How do you enable REST api without browser?
Added by Tomoya Goto about 10 years ago
Hello, folks.
I've been touching Redmine this week, and I have a question regarding settings.
How do you enable REST api WITHOUT accessing browser?
The reason I want to change settings without browser is that I'm heavily relying on ansible and want to automate installation/updating/scaling.
I tried following ruby/runner script, but failed.
ruby script/rails runner \ 'setting = Setting.find_by_name("rest_api_enabled"); setting.value = "1"; setting.save!' \ -e production
Are there any other suitable method I missed for such purpose?
Thank you in advance.
Replies (1)
RE: How do you enable REST api without browser?
-
Added by Tomoya Goto about 10 years ago
Alright, I got the answer!
The reason former script failed was that there is no "rest_api_enabled" record in sql table(redmine.settings) until this setting was commited (via browser or rails runner).
So when you have to change settings just after the installation, you have to use Setting.create() to populate sql table.
Following script successfully change settings before/after the sql table population.
settings = [ {:name => "rest_api_enabled", :value => 1}, {:name => "repositories_encodings", :value => "utf-8,cp932,euc-jp"}, {:name => "ui_theme", :value => "alternate"}, {:name => "default_language", :value => "ja"}, {:name => "user_format", :value => "firstname_lastname"}, {:name => "login_required", :value => 1}, {:name => "autologin", :value => 0}, {:name => "self_registration", :value => 0}, {:name => "unsubscribe", :value => 1}, {:name => "password_min_length", :value => 8}, {:name => "lost_password", :value => 1}, {:name => "default_projects_public", :value => 0} ] for each in settings do if !Setting.find_by_name( each[:name] ) Setting.create( :name => each[:name], :value => each[:value] ) else set = Setting.find_by_name( each[:name] ) set.value = each[:value] set.save! end end
thank you for reading.