如何脚本化设置向导?

看起来我应该使用 rake:admin 来创建管理员用户。不过,我认为管理员用户可能已经创建,只是尚未激活,因此我需要将其状态改为已激活。

或者,我是否可以创建一个 API 密钥,使用 api_key:create_master,然后利用它来创建管理员用户?

root@forum:/var/www/discourse# RAILS_DB=secondsite rake 'api_key:create_master[MASTERKEY]'
ad676e7413778aaaaa5d315c35f188591ef0edb4a4d4b2d644b9247a88421cfa

但看起来我还没有完全理解这个主密钥的使用方式,因为以下操作并未生效:

# curl -X GET "https://forum2/categories" -H "Accept: application/json" -H "Api-Key: ad676e7413778aa3a5d315c35f91ef0edb4a4d4b2d644b924b7a88421cfa"
{"errors":["You are not permitted to view the requested resource. The API username or key is invalid."],"error_type":"invalid_access"}

然而,如果我创建一个管理员用户:

root@forum:/var/www/discourse# RAILS_DB=secondsite rake 'admin:create' 
Email:  loic@dachary.org
Password:  
Repeat password:  

Ensuring account is active!

Account created successfully with username loic
Do you want to grant Admin privileges to this account? (Y/n)  Y

Your account now has Admin privileges!

然后使用相同的主密钥并指定新创建的用户,操作就成功了:

curl -X GET "https://forum2/categories" -H "Accept: application/json" -H "Api-Key: ad676e7413778aa3a5d315c358591ef0edb4a4d4b2d644b924b7a88421cfa" -H "Api-Username: loic"
{"category_list":{"can...

并且该账户确实拥有管理员权限,因为它也可以访问 /admin/site_settings/category/branding