secrets_cli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +81 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/exe/secrets +72 -0
- data/lib/secrets_cli/check/secrets.rb +34 -0
- data/lib/secrets_cli/check/vault.rb +30 -0
- data/lib/secrets_cli/configuration.rb +30 -0
- data/lib/secrets_cli/helpers.rb +24 -0
- data/lib/secrets_cli/init.rb +41 -0
- data/lib/secrets_cli/prompts/secrets_field.rb +11 -0
- data/lib/secrets_cli/prompts/secrets_file.rb +25 -0
- data/lib/secrets_cli/prompts/secrets_repo.rb +17 -0
- data/lib/secrets_cli/vault/auth.rb +28 -0
- data/lib/secrets_cli/vault/base.rb +34 -0
- data/lib/secrets_cli/vault/pull.rb +18 -0
- data/lib/secrets_cli/vault/push.rb +30 -0
- data/lib/secrets_cli/vault/read.rb +19 -0
- data/lib/secrets_cli/version.rb +3 -0
- data/lib/secrets_cli.rb +25 -0
- data/secrets_cli.gemspec +36 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3e4d9b93dbc96538f3109e94daf38a70b2d6897d
|
4
|
+
data.tar.gz: 5334f16c6e175afda6431d011f2186803ad1ecdd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e61d4648e790863435dc63cc3b1f0ee93a15733c65b449d72191809cef6f728ec5d104376e604e2aa8353f004a87442db6d649ec89219a8d37f9ec829e4cfbcb
|
7
|
+
data.tar.gz: fe2de40530362d484d554ebc3bfc548a2b867e6b60825ce70def65a91b98265be722a005ae2a608d89a402baef35997b95fffb366e8885a086e5ffe99eda09d1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Stjepan Hadjic
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# SecretsCli
|
2
|
+
|
3
|
+
This is a CLI for easier use of (vault)[https://www.vaultproject.io/]
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'secrets_cli'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install secrets_cli
|
20
|
+
|
21
|
+
## Prerequisites
|
22
|
+
|
23
|
+
`vault` must be installed on system. This gem adds a dependancy to `vault-binaries` which will install `vault` for you.
|
24
|
+
|
25
|
+
Following environemt variables need to be set:
|
26
|
+
VAULT_ADDR - this is an address to vault server
|
27
|
+
SECRETS_VAULT_AUTH_METHOD - this is auth method ('github' or 'token' supported for now)
|
28
|
+
SECRETS_VAULT_AUTH_TOKEN - this is vault auth token
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
All commands have --help with detailed descriptions of options.
|
33
|
+
Some of the commands have --verbose switch which will print out the commands it run.
|
34
|
+
|
35
|
+
### Init
|
36
|
+
|
37
|
+
$ secrets init
|
38
|
+
|
39
|
+
This will create `.secrets` file with project configuration. The command will ask you all it needs to know if you do not
|
40
|
+
supply the config through options.
|
41
|
+
|
42
|
+
### Auth
|
43
|
+
|
44
|
+
$ secrets auth
|
45
|
+
|
46
|
+
You need to first authenticate yourself on vault server to be able to read and write.
|
47
|
+
Needs to be done only once for token.
|
48
|
+
|
49
|
+
### Read
|
50
|
+
|
51
|
+
$ secrets read
|
52
|
+
|
53
|
+
This will only read from vault.
|
54
|
+
|
55
|
+
### Pull
|
56
|
+
|
57
|
+
$ secrets pull
|
58
|
+
|
59
|
+
This will pull from vault and write to your secrets file.
|
60
|
+
|
61
|
+
### Push
|
62
|
+
|
63
|
+
$ secrets push
|
64
|
+
|
65
|
+
This will push from your secrets file to vault.
|
66
|
+
|
67
|
+
## Development
|
68
|
+
|
69
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
70
|
+
|
71
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/infinum/secrets_cli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
76
|
+
|
77
|
+
|
78
|
+
## License
|
79
|
+
|
80
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
81
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'secrets_cli'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require 'pry'
|
11
|
+
Pry.start
|
12
|
+
|
13
|
+
# require "irb"
|
14
|
+
# IRB.start
|
data/exe/secrets
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# $LOAD_PATH << 'lib'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'commander/import'
|
6
|
+
require 'secrets_cli'
|
7
|
+
|
8
|
+
program :version, SecretsCli::VERSION
|
9
|
+
program :description, 'CLI for vault'
|
10
|
+
|
11
|
+
global_option '-V', '--verbose', 'Verbose'
|
12
|
+
|
13
|
+
command :init do |c|
|
14
|
+
c.syntax = 'secrets init [options]'
|
15
|
+
c.summary = 'Use to initialize project, create .secrets file'
|
16
|
+
c.option '-f', '--secrets_file STRING', String, 'Define secrets file'
|
17
|
+
c.option '-r', '--secrets_repo STRING', String, 'Define secrets repo'
|
18
|
+
c.option '-F', '--secrets_field STRING', String, 'Define secrets field'
|
19
|
+
c.action do |_args, options|
|
20
|
+
SecretsCli::Init.new(options).call
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
command :auth do |c|
|
25
|
+
c.syntax = 'secrets auth [options]'
|
26
|
+
c.summary = 'Use to authenticate with vault server'
|
27
|
+
c.option '-T', '--auth_token STRING', String, 'Auth token or $SECRETS_VAULT_AUTH_TOKEN'
|
28
|
+
c.option '-m', '--auth_method STRING', String, 'github or token'
|
29
|
+
c.action do |_args, options|
|
30
|
+
SecretsCli::Check::Vault.new(options).call
|
31
|
+
SecretsCli::Vault::Auth.new(options).call
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
command :pull do |c|
|
36
|
+
c.syntax = 'secrets pull [options]'
|
37
|
+
c.summary = 'Use to read from vault server to secrets file'
|
38
|
+
c.option '-e', '--environment STRING', String, 'Set environment, default: development'
|
39
|
+
c.option '-f', '--secrets_file STRING', String, 'Override secrets_file'
|
40
|
+
c.option '-r', '--secrets_repo STRING', String, 'Override secrets_repo'
|
41
|
+
c.option '-F', '--secrets_field STRING', String, 'Override secrets_field'
|
42
|
+
c.action do |_args, options|
|
43
|
+
SecretsCli::Check::Secrets.new(options).call
|
44
|
+
SecretsCli::Vault::Pull.new(options).call
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
command :push do |c|
|
49
|
+
c.syntax = 'secrets push [options]'
|
50
|
+
c.summary = 'Use to write to vault server from secrets file'
|
51
|
+
c.option '-y', '--without_prompt', 'Push without prompt'
|
52
|
+
c.option '-e', '--environment STRING', String, 'Set environment, default: development'
|
53
|
+
c.option '-f', '--secrets_file STRING', String, 'Override secrets_file'
|
54
|
+
c.option '-r', '--secrets_repo STRING', String, 'Override secrets_repo'
|
55
|
+
c.option '-F', '--secrets_field STRING', String, 'Override secrets_field'
|
56
|
+
c.action do |_args, options|
|
57
|
+
SecretsCli::Check::Secrets.new(options).call
|
58
|
+
SecretsCli::Vault::Push.new(options).call
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
command :read do |c|
|
63
|
+
c.syntax = 'secrets read [options]'
|
64
|
+
c.summary = 'Use to only read from vault server without writing to secrets file'
|
65
|
+
c.option '-e', '--environment STRING', String, 'Set environment, default: development'
|
66
|
+
c.option '-r', '--secrets_repo STRING', String, 'Override secrets_repo'
|
67
|
+
c.option '-F', '--secrets_field STRING', String, 'Override secrets_field'
|
68
|
+
c.action do |_args, options|
|
69
|
+
SecretsCli::Check::Secrets.new(options).call
|
70
|
+
SecretsCli::Vault::Read.new(options).call
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SecretsCli
|
2
|
+
module Check
|
3
|
+
class Secrets
|
4
|
+
include SecretsCli::Helpers
|
5
|
+
|
6
|
+
attr_reader :options
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
error! 'Missing .secrets' unless File.exist?('.secrets')
|
14
|
+
error! 'Missing secrets_file' if missing_secret_file?
|
15
|
+
error! 'Missing secrets_repo' if missing_secret_repo?
|
16
|
+
error! 'Missing secrets_field' if missing_secret_field?
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def missing_secret_file?
|
22
|
+
options.secrets_file.nil? && config.secrets_file.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def missing_secret_repo?
|
26
|
+
options.secrets_repo && config.secrets_repo.nil?
|
27
|
+
end
|
28
|
+
|
29
|
+
def missing_secret_field?
|
30
|
+
options.secrets_field && config.secrets_field.nil?
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SecretsCli
|
2
|
+
module Check
|
3
|
+
class Vault
|
4
|
+
include SecretsCli::Helpers
|
5
|
+
|
6
|
+
attr_reader :options
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
error! 'Missing vault' if TTY::Which.which('vault').nil?
|
14
|
+
error! 'Missing VAULT_ADDR env' if ENV['VAULT_ADDR'].nil?
|
15
|
+
error! 'Missing SECRETS_VAULT_AUTH_TOKEN env' if missing_auth_token?
|
16
|
+
error! 'Missing SECRETS_VAULT_AUTH_METHOD env' if missing_auth_method?
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def missing_auth_token?
|
22
|
+
options.auth_token.nil? && ENV['SECRETS_VAULT_AUTH_TOKEN'].nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def missing_auth_method?
|
26
|
+
options.auth_method.nil? && ENV['SECRETS_VAULT_AUTH_METHOD'].nil?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SecretsCli
|
2
|
+
class Configuration
|
3
|
+
attr_reader :environment, :verbose
|
4
|
+
|
5
|
+
def initialize(options)
|
6
|
+
@environment = options.environment || ENV['RAILS_ENV'] || 'development'
|
7
|
+
@verbose = options.verbose
|
8
|
+
end
|
9
|
+
|
10
|
+
def config
|
11
|
+
@config ||= YAML.load_file(SECRETS_CONFIG_FILE)
|
12
|
+
end
|
13
|
+
|
14
|
+
def secrets_file
|
15
|
+
config[:secrets_file]
|
16
|
+
end
|
17
|
+
|
18
|
+
def secrets_repo
|
19
|
+
config[:secrets_repo]
|
20
|
+
end
|
21
|
+
|
22
|
+
def secrets_field
|
23
|
+
config[:secrets_field]
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.write(config)
|
27
|
+
File.open(SECRETS_CONFIG_FILE, 'w') { |f| f.write(config.to_yaml) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SecretsCli
|
2
|
+
module Helpers
|
3
|
+
def prompt
|
4
|
+
@prompt ||= TTY::Prompt.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def pastel
|
8
|
+
@pastel ||= Pastel.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def config
|
12
|
+
@config ||= SecretsCli::Configuration.new(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def error!(message)
|
16
|
+
prompt.error(message)
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
|
20
|
+
def print_verbose(message)
|
21
|
+
puts pastel.cyan(message)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module SecretsCli
|
2
|
+
class Init
|
3
|
+
include SecretsCli::Helpers
|
4
|
+
|
5
|
+
attr_reader :options
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
SecretsCli::Configuration.write(config)
|
13
|
+
prompt.ok "Written in #{SECRETS_CONFIG_FILE}:"
|
14
|
+
prompt.ok File.read(SECRETS_CONFIG_FILE)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def config
|
20
|
+
{
|
21
|
+
secrets_file: secrets_file,
|
22
|
+
secrets_repo: secrets_repo,
|
23
|
+
secrets_field: secrets_field
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def secrets_file
|
28
|
+
@secrets_file ||= options.secrets_file || SecretsCli::Prompts::SecretsFile.new.call
|
29
|
+
end
|
30
|
+
|
31
|
+
def secrets_repo
|
32
|
+
repo = options.secrets_repo || SecretsCli::Prompts::SecretsRepo.new.call
|
33
|
+
repo << '/' unless repo.end_with?('/')
|
34
|
+
repo
|
35
|
+
end
|
36
|
+
|
37
|
+
def secrets_field
|
38
|
+
options.secrets_field || SecretsCli::Prompts::SecretsField.new.call
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SecretsCli
|
2
|
+
module Prompts
|
3
|
+
class SecretsFile
|
4
|
+
include SecretsCli::Helpers
|
5
|
+
|
6
|
+
def call
|
7
|
+
case choice
|
8
|
+
when 1 then 'config/application.yml'
|
9
|
+
when 2 then '.env'
|
10
|
+
when 3 then prompt.ask('What secrets file are you using?', required: true)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def choice
|
17
|
+
prompt.select('Which secrets gem are you using?') do |menu|
|
18
|
+
menu.choice 'Figaro (config/application.yml)', 1
|
19
|
+
menu.choice 'dotenv (.env)', 2
|
20
|
+
menu.choice 'other', 3
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SecretsCli
|
2
|
+
module Prompts
|
3
|
+
class SecretsRepo
|
4
|
+
include SecretsCli::Helpers
|
5
|
+
|
6
|
+
def call
|
7
|
+
prompt.ask('What will the secrets repo be?', default: default)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def default
|
13
|
+
"rails/#{Dir.pwd.split('/').last}/"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SecretsCli
|
2
|
+
module Vault
|
3
|
+
class Auth < SecretsCli::Vault::Base
|
4
|
+
include SecretsCli::Helpers
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
super
|
8
|
+
@auth_token = options.auth_token || ENV['SECRETS_VAULT_AUTH_TOKEN']
|
9
|
+
@auth_method = options.auth_method || ENV['SECRETS_VAULT_AUTH_METHOD']
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
attr_reader :auth_token, :auth_method
|
15
|
+
|
16
|
+
def command
|
17
|
+
case auth_method
|
18
|
+
when 'github'
|
19
|
+
"vault auth -method=github token=#{auth_token}"
|
20
|
+
when 'token'
|
21
|
+
"vault auth #{auth_token}"
|
22
|
+
else
|
23
|
+
error! "Unknown auth method #{auth_method}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SecretsCli
|
2
|
+
module Vault
|
3
|
+
class Base
|
4
|
+
include SecretsCli::Helpers
|
5
|
+
|
6
|
+
attr_reader :options
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
print_verbose(command) if config.verbose
|
14
|
+
Open3.popen2e(command) do |_stdin, stdout_and_stderr, wait_thr|
|
15
|
+
if wait_thr.value.success?
|
16
|
+
prompt.ok(stdout_and_stderr.read)
|
17
|
+
else
|
18
|
+
error!(stdout_and_stderr.read)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def command
|
26
|
+
fail NotImplementedError
|
27
|
+
end
|
28
|
+
|
29
|
+
def secrets_full_repo
|
30
|
+
File.join(secrets_repo, config.environment)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SecretsCli
|
2
|
+
module Vault
|
3
|
+
class Pull < SecretsCli::Vault::Read
|
4
|
+
attr_reader :secrets_file
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
super
|
8
|
+
@secrets_file = options.secrets_file || config.secrets_file
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
secrets = super.first
|
13
|
+
print_verbose("Writing to #{secrets_file}")
|
14
|
+
File.open(secrets_file, 'w') { |f| f.write(secrets) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SecretsCli
|
2
|
+
module Vault
|
3
|
+
class Push < SecretsCli::Vault::Base
|
4
|
+
attr_reader :secrets_repo, :secrets_field, :secrets, :secrets_file
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
super
|
8
|
+
@secrets_repo = options.secrets_repo || config.secrets_repo
|
9
|
+
@secrets_field = options.secrets_field || config.secrets_field
|
10
|
+
@secrets_file = options.secrets_file || config.secrets_file
|
11
|
+
@secrets = File.read(secrets_file)
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
return if !options.without_prompt && !are_you_sure?
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def command
|
22
|
+
"vault write #{secrets_full_repo} #{secrets_field}=\"#{secrets}\""
|
23
|
+
end
|
24
|
+
|
25
|
+
def are_you_sure?
|
26
|
+
prompt.yes?("Are you sure you want to write #{secrets_file} to #{secrets_full_repo}", default: 'Y')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SecretsCli
|
2
|
+
module Vault
|
3
|
+
class Read < SecretsCli::Vault::Base
|
4
|
+
def initialize(options)
|
5
|
+
super
|
6
|
+
@secrets_repo = options.secrets_repo || config.secrets_repo
|
7
|
+
@secrets_field = options.secrets_field || config.secrets_field
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
attr_reader :secrets_repo, :secrets_field
|
13
|
+
|
14
|
+
def command
|
15
|
+
"vault read --field=#{secrets_field} #{secrets_full_repo}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/secrets_cli.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'tty-prompt'
|
3
|
+
require 'tty-which'
|
4
|
+
require 'open3'
|
5
|
+
require 'singleton'
|
6
|
+
require 'secrets_cli/helpers'
|
7
|
+
require 'secrets_cli/configuration'
|
8
|
+
require 'secrets_cli/init'
|
9
|
+
require 'secrets_cli/check/secrets'
|
10
|
+
require 'secrets_cli/check/vault'
|
11
|
+
require 'secrets_cli/prompts/secrets_file'
|
12
|
+
require 'secrets_cli/prompts/secrets_repo'
|
13
|
+
require 'secrets_cli/prompts/secrets_field'
|
14
|
+
require 'secrets_cli/vault/base'
|
15
|
+
require 'secrets_cli/vault/auth'
|
16
|
+
require 'secrets_cli/vault/read'
|
17
|
+
require 'secrets_cli/vault/pull'
|
18
|
+
require 'secrets_cli/vault/push'
|
19
|
+
require 'secrets_cli/version'
|
20
|
+
|
21
|
+
# require 'pry'
|
22
|
+
|
23
|
+
module SecretsCli
|
24
|
+
SECRETS_CONFIG_FILE = '.secrets'
|
25
|
+
end
|
data/secrets_cli.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'secrets_cli/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'secrets_cli'
|
8
|
+
spec.version = SecretsCli::VERSION
|
9
|
+
spec.authors = ['Stjepan Hadjic']
|
10
|
+
spec.email = ['d4be4st@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'This is a CLI for easier use of https://www.vaultproject.io/'
|
13
|
+
spec.homepage = 'http://github.com/infinum.secrets_cli'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
20
|
+
else
|
21
|
+
fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
30
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
31
|
+
spec.add_development_dependency 'rspec'
|
32
|
+
spec.add_development_dependency 'pry'
|
33
|
+
|
34
|
+
spec.add_runtime_dependency 'tty', '~> 0.4.0'
|
35
|
+
spec.add_runtime_dependency 'vault-binaries'
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: secrets_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stjepan Hadjic
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: tty
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.4.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.4.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vault-binaries
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- d4be4st@gmail.com
|
100
|
+
executables:
|
101
|
+
- secrets
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- CODE_OF_CONDUCT.md
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- exe/secrets
|
115
|
+
- lib/secrets_cli.rb
|
116
|
+
- lib/secrets_cli/check/secrets.rb
|
117
|
+
- lib/secrets_cli/check/vault.rb
|
118
|
+
- lib/secrets_cli/configuration.rb
|
119
|
+
- lib/secrets_cli/helpers.rb
|
120
|
+
- lib/secrets_cli/init.rb
|
121
|
+
- lib/secrets_cli/prompts/secrets_field.rb
|
122
|
+
- lib/secrets_cli/prompts/secrets_file.rb
|
123
|
+
- lib/secrets_cli/prompts/secrets_repo.rb
|
124
|
+
- lib/secrets_cli/vault/auth.rb
|
125
|
+
- lib/secrets_cli/vault/base.rb
|
126
|
+
- lib/secrets_cli/vault/pull.rb
|
127
|
+
- lib/secrets_cli/vault/push.rb
|
128
|
+
- lib/secrets_cli/vault/read.rb
|
129
|
+
- lib/secrets_cli/version.rb
|
130
|
+
- secrets_cli.gemspec
|
131
|
+
homepage: http://github.com/infinum.secrets_cli
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata:
|
135
|
+
allowed_push_host: https://rubygems.org
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 2.4.5
|
153
|
+
signing_key:
|
154
|
+
specification_version: 4
|
155
|
+
summary: This is a CLI for easier use of https://www.vaultproject.io/
|
156
|
+
test_files: []
|
157
|
+
has_rdoc:
|