在Rails中生成环境密钥的方式是不运行编辑凭据文件命令吗?

huangapple go评论49阅读模式
英文:

Is there a way to generate an environment key for Rails without running the edit credential file command?

问题

我知道你可以运行 EDITOR=nano rails credentials:edit --environment production 同时创建 production.keyproduction.yml.enc 文件。我的问题是,是否可以在不调用 :edit 部分的情况下执行类似的操作?

我尝试过的

我尝试过 rails credentials:show --environment production,但如果尚未创建文件,你会收到以下错误消息:

Missing 'config/credentials/production.key' to decrypt credentials. See bin/rails credentials:help

为什么我提问

实际上,我一直只是运行编辑命令来创建文件,然后关闭文件。非常简单快捷。但是,现在在工作中,我遇到了一个问题。

我正在创建一个模板,我们可以使用它快速轻松地从头开始创建一个具有我们所有标准代码的RoR应用程序。也就是说,它具有基本样式表、JS文件、登录功能等。我希望这个模板还可以自动创建production.keyproduction.yml.enc文件。实际凭据文件可以是空的,那也没关系。

如果我让模板运行带有edit的命令,那么它将等待用户关闭凭据文件。我更希望它只是创建文件,然后继续而不需要用户输入。

如果能提供任何帮助,将不胜感激。谢谢。

愉快编码!

英文:

I am aware that you can run EDITOR=nano rails credentials:edit --environment production to create a production.key and a production.yml.enc file at the same time. My question is, can you do the something without invoking the :edit part?

What I tried

I tried rails credentials:show --environment production but, if there are no files created yet you get the error:

Missing 'config/credentials/production.key' to decrypt credentials. See bin/rails credentials:help

Why I ask

Truly I have always just ran the edit code to create the files and then closed out of the file. Easy and fast. But, I am running into a problem now at work with this.

I am creating a template that we can use to quickly and easily make a RoR app from scratch that has all of our standard code. IE, it has the base Stylesheets, JS files, login abilities, etc. I would like the template to also auto-create the production.key and production.yml.enc files. The actual credentials file can be blank. That's fine.

If I have the template run the command with edit then it will wait there until the user closes the credentials file. I would prefer that it just create the files and continue on without needing user input.

Any help that can be given would be most welcome. Thank you.

Happy Coding!

答案1

得分: 3

TL;DR; 使用 sed 编辑器,像这样: run "EDITOR=sed rails credentials:edit --environment production"

CONTEXT:

根据 @max 的评论,我能够通过使用我不熟悉的非交互式编辑器 sed 来获得我所需的内容。

因此,我能够将 run "EDITOR=sed rails credentials:edit --environment production" 放入我的模板创建器中,它创建了我想要的 production.keyproduction.yml.enc 文件,而无需等待用户输入以继续。

感谢 @max!

祝大家编程愉快!

英文:

TL;DR; Use sed editor like so: run "EDITOR=sed rails credentials:edit --environment production"

CONTEXT:

Per the comment from @max, I was able to get what I needed by using the sed editor, a non-interactivce editor I was unfamiliar with.

So, I was able to put run "EDITOR=sed rails credentials:edit --environment production" in my template creator, and it created the production.key and production.yml.enc files I was wanting, without needing to wait for user input to continue.

Thank you @max!

Happy Coding everyone!

huangapple
  • 本文由 发表于 2023年4月11日 13:10:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75982575.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定