ccli 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b808de24e75aa7de88a4fa899401f33b0c07a8bfc056371b6b4dba3037ac4c1c
4
- data.tar.gz: 8d6aed4c6a3ddd82c0a9d5d2eaa26d5668b5da7d8ae6b3a1d7bfac473c724158
3
+ metadata.gz: d2f2f0b3d9151f52f911b794e164119054e2d281d3291f06a8e04b3ada1382d0
4
+ data.tar.gz: 5fef82bab17bf44d9b922c8ef543c89405e8aee145cf98c138c932d42c37bb4a
5
5
  SHA512:
6
- metadata.gz: 23cdaf53c3e84c90ea7bd8caac55c1c0dc5479e70dbd7d893d31e4c9ef7830cda495f90d5d075c0cce93d242abad23b639c69f337df557b060219d633d8c373a
7
- data.tar.gz: eb84e14c287080cecf3b91e08ef7837c1a7e64e923f9e505974f9fc28f5c95fbf0fcc14777663967f8f553cf9c5f39db52fb8094ca5b20207a4d2db105199e2a
6
+ metadata.gz: 10b197547309059384bb1fdd65135f5950cbf33cbbb9aed7fb5e871cb436cb493ef8524902e31318dbabd4fd1a98d26a4f769937845e97eb72e5a6c65ad43093
7
+ data.tar.gz: 6ef9539d2512c4ec66ae63d5eb400bc06fd1d8c33147304dffb2f2527ed3f74ba9e7e64b7b85f2da88806bef4f9be18c41ffd73ebe6cfb3ab04a92be4902fbfa
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0
4
+
5
+ - Rename Account to Encryptable to support Cryptopus > 4.2
6
+
3
7
  ## 1.0.1
4
8
 
5
9
  - Reset api user token after login
data/Gemfile CHANGED
@@ -5,9 +5,9 @@ source 'https://rubygems.org'
5
5
  gem 'commander', '~> 4.5', '>= 4.5.2'
6
6
  gem 'rspec', '~> 3.9'
7
7
  gem 'rubocop', '~> 0.89.0'
8
- gem 'tty-command'
9
- gem 'tty-exit'
10
- gem 'tty-logger'
8
+ gem 'tty-command', '~> 0.10'
9
+ gem 'tty-exit', '~> 0.1'
10
+ gem 'tty-logger', '~> 0.6'
11
11
 
12
12
  gem 'pry'
13
13
  gem 'pry-byebug'
data/Gemfile.lock CHANGED
@@ -7,14 +7,12 @@ GEM
7
7
  commander (4.5.2)
8
8
  highline (~> 2.0.0)
9
9
  diff-lcs (1.4.4)
10
- equatable (0.6.1)
11
10
  highline (2.0.3)
12
11
  method_source (1.0.0)
13
12
  parallel (1.19.2)
14
13
  parser (2.7.1.4)
15
14
  ast (~> 2.4.1)
16
- pastel (0.7.4)
17
- equatable (~> 0.6)
15
+ pastel (0.8.0)
18
16
  tty-color (~> 0.5)
19
17
  pry (0.13.1)
20
18
  coderay (~> 1.1)
@@ -24,7 +22,7 @@ GEM
24
22
  pry (~> 0.13.0)
25
23
  rainbow (3.0.0)
26
24
  regexp_parser (1.7.1)
27
- rexml (3.2.4)
25
+ rexml (3.2.5)
28
26
  rspec (3.9.0)
29
27
  rspec-core (~> 3.9.0)
30
28
  rspec-expectations (~> 3.9.0)
@@ -50,12 +48,12 @@ GEM
50
48
  rubocop-ast (0.3.0)
51
49
  parser (>= 2.7.1.4)
52
50
  ruby-progressbar (1.10.1)
53
- tty-color (0.5.2)
54
- tty-command (0.9.0)
55
- pastel (~> 0.7.0)
51
+ tty-color (0.6.0)
52
+ tty-command (0.10.1)
53
+ pastel (~> 0.8)
56
54
  tty-exit (0.1.0)
57
- tty-logger (0.3.0)
58
- pastel (~> 0.7.0)
55
+ tty-logger (0.6.0)
56
+ pastel (~> 0.8)
59
57
  unicode-display_width (1.7.0)
60
58
 
61
59
  PLATFORMS
@@ -67,9 +65,9 @@ DEPENDENCIES
67
65
  pry-byebug
68
66
  rspec (~> 3.9)
69
67
  rubocop (~> 0.89.0)
70
- tty-command
71
- tty-exit
72
- tty-logger
68
+ tty-command (~> 0.10)
69
+ tty-exit (~> 0.1)
70
+ tty-logger (~> 0.6)
73
71
 
74
72
  BUNDLED WITH
75
73
  2.1.4
data/README.md CHANGED
@@ -10,7 +10,7 @@ This will install the `cry` command including its dependencies
10
10
 
11
11
  ## Features
12
12
 
13
- - Fetch account data from Cryptopus
13
+ - Fetch encryptable data from Cryptopus
14
14
  - List accessable teams in Cryptopus
15
15
  - Sync Openshift/Kubernetes Secrets to Cryptopus
16
16
  - Sync Secrets from Cryptopus to Openshift/Kubernetes
@@ -24,7 +24,7 @@ This will install the `cry` command including its dependencies
24
24
  ```
25
25
  Command: Summary:
26
26
 
27
- account Fetches an account by the given id
27
+ encryptable Fetches an encryptable by the given id
28
28
  folder Selects the Cryptopus folder by id
29
29
  help Display global or [command] help documentation
30
30
  k8s-secret-pull Pulls secret from Kubectl to Cryptopus
@@ -53,15 +53,15 @@ Use the ccli login copy button from the UI or do it manually:
53
53
 
54
54
  #### Retrieving
55
55
 
56
- To retreive account data as yaml:
56
+ To retreive encryptable data as yaml:
57
57
 
58
58
  ```
59
- cry account 42 > account.yaml
59
+ cry encryptable 42 > encryptable.yaml
60
60
  ```
61
- Retreiving account's password and assign it to a variable:
61
+ Retreiving encryptable's password and assign it to a variable:
62
62
 
63
63
  ```
64
- PASSWORD=$(cry account 42 --password)
64
+ PASSWORD=$(cry encryptable 42 --password)
65
65
  ```
66
66
 
67
67
  #### Updating
data/ccli.gemspec CHANGED
@@ -6,11 +6,11 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'ccli'
8
8
  s.description = <<-EOF
9
- CCLI is the Cryptopus Command Line Interface. It allows to fetch account data and list teams from Cryptopus.
9
+ CCLI is the Cryptopus Command Line Interface. It allows to fetch encryptable data and list teams from Cryptopus.
10
10
  One of the main functionality is backing up secrets from cluster services (currently: openshift, kubernetes)
11
11
  to Cryptopus and restoring them as well.
12
12
  EOF
13
- s.version = '1.0.1'
13
+ s.version = '1.1.0'
14
14
  s.summary = 'Command line client for the opensource password manager Cryptopus'
15
15
  s.license = 'MIT'
16
16
  s.homepage = 'https://github.com/puzzle/ccli'
@@ -30,8 +30,8 @@ Gem::Specification.new do |s|
30
30
  }
31
31
 
32
32
  s.add_runtime_dependency 'commander', '~> 4.5', '>= 4.5.2'
33
- s.add_runtime_dependency 'tty-command'
34
- s.add_runtime_dependency 'tty-exit'
35
- s.add_runtime_dependency 'tty-logger'
33
+ s.add_runtime_dependency 'tty-command', '~> 0.10'
34
+ s.add_runtime_dependency 'tty-exit', '~> 0.1'
35
+ s.add_runtime_dependency 'tty-logger', '~> 0.6'
36
36
 
37
37
  end
@@ -34,24 +34,23 @@ class CryptopusAdapter
34
34
  end
35
35
 
36
36
  def save_secret(secret)
37
- secret_account = secret.to_account
38
- secret_account.folder = session_adapter.selected_folder.id
39
-
40
- persisted_secret = Account.find_by_name_and_folder_id(secret.name,
41
- session_adapter.selected_folder.id)
37
+ secret_encryptable = secret.to_encryptable
38
+ secret_encryptable.folder = session_adapter.selected_folder.id
39
+ persisted_secret = Encryptable.find_by_name_and_folder_id(secret.name,
40
+ session_adapter.selected_folder.id)
42
41
  if persisted_secret
43
- patch("accounts/#{persisted_secret.id}", secret_account.to_json)
42
+ patch("encryptables/#{persisted_secret.id}", secret_encryptable.to_json)
44
43
  else
45
- post('accounts', secret_account.to_json)
44
+ post('encryptables', secret_encryptable.to_json)
46
45
  end
47
46
  end
48
47
 
49
- def find_account_by_name(name)
50
- secret_account = Account.find_by_name_and_folder_id(name, session_adapter.selected_folder.id)
48
+ def find_encryptable_by_name(name)
49
+ secret_encryptable = Encryptable.find_by_name_and_folder_id(name, session_adapter.selected_folder.id)
51
50
 
52
- raise CryptopusAccountNotFoundError unless secret_account
51
+ raise CryptopusEncryptableNotFoundError unless secret_encryptable
53
52
 
54
- secret_account
53
+ secret_encryptable
55
54
  end
56
55
 
57
56
  def renewed_auth_token
data/lib/cli.rb CHANGED
@@ -14,7 +14,7 @@ class CLI
14
14
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metric/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/BlockLength
15
15
  def run
16
16
  program :name, 'cry - cryptopus cli'
17
- program :version, '1.0.1'
17
+ program :version, '1.1.0'
18
18
  program :description, 'CLI tool to manage Openshift Secrets via Cryptopus'
19
19
  program :help, 'Source Code', 'https://www.github.com/puzzle/ccli'
20
20
  program :help, 'Usage', 'cry [flags]'
@@ -49,20 +49,20 @@ class CLI
49
49
  end
50
50
  end
51
51
 
52
- command :account do |c|
53
- c.syntax = 'cry account <id> [options]'
54
- c.description = 'Fetches an account by the given id'
52
+ command :encryptable do |c|
53
+ c.syntax = 'cry encryptable <id> [options]'
54
+ c.description = 'Fetches an encryptable by the given id'
55
55
  c.option '--username', String, 'Only show the username of the user'
56
56
  c.option '--password', String, 'Only show the password of the user'
57
57
 
58
58
  c.action do |args, options|
59
59
  exit_with_error(:usage_error, 'id missing') if args.empty?
60
60
  execute_action do
61
- logger.info 'Fetching account...'
62
- account = Account.find(args.first)
63
- out = account.username if options.username
64
- out = account.password if options.password
65
- puts out || account.to_yaml
61
+ logger.info 'Fetching encryptable...'
62
+ encryptable = Encryptable.find(args.first)
63
+ out = encryptable.username if options.username
64
+ out = encryptable.password if options.password
65
+ puts out || encryptable.to_yaml
66
66
  end
67
67
  end
68
68
  end
@@ -120,25 +120,25 @@ class CLI
120
120
  c.summary = 'Pushes secret from Cryptopus to Openshift'
121
121
  c.description = 'Pushes the Secret to Openshift by retrieving it from Cryptopus first. ' \
122
122
  'If a Secret in the selected Openshift project using the name ' \
123
- 'of the given accountname is already present, it will be updated accordingly.'
123
+ 'of the given name is already present, it will be updated accordingly.'
124
124
 
125
125
  c.action do |args|
126
126
  secret_name = args.first
127
127
  exit_with_error(:usage_error, 'Only one secret can be pushed') if args.length > 1
128
128
  execute_action({ secret_name: secret_name }) do
129
- secret_accounts = if secret_name.nil?
130
- logger.info 'Fetching all accounts in folder...'
131
- session_adapter.selected_folder.accounts
129
+ secret_encryptables = if secret_name.nil?
130
+ logger.info 'Fetching all encryptables in folder...'
131
+ session_adapter.selected_folder.encryptables
132
132
  else
133
- logger.info "Fetching account #{secret_name}..."
134
- [cryptopus_adapter.find_account_by_name(secret_name)]
133
+ logger.info "Fetching encryptable #{secret_name}..."
134
+ [cryptopus_adapter.find_encryptable_by_name(secret_name)]
135
135
  end
136
- secret_accounts.each do |account|
137
- logger.info "Fetching secret #{account.accountname}..."
138
- secret_account = Account.find(account.id)
139
- logger.info "Inserting secret #{account.accountname}..."
140
- ose_adapter.insert_secret(secret_account.to_osesecret)
141
- log_success "Secret #{secret_account.accountname} was successfully applied"
136
+ secret_encryptables.each do |encryptable|
137
+ logger.info "Fetching secret #{encryptable.name}..."
138
+ secret_encryptable = Encryptable.find(encryptable.id)
139
+ logger.info "Inserting secret #{encryptable.name}..."
140
+ ose_adapter.insert_secret(secret_encryptable.to_osesecret)
141
+ log_success "Secret #{secret_encryptable.name} was successfully applied"
142
142
  end
143
143
  end
144
144
  end
@@ -148,7 +148,7 @@ class CLI
148
148
  c.syntax = 'cry k8s-secret-pull <secret-name>'
149
149
  c.summary = 'Pulls secret from Kubectl to Cryptopus'
150
150
  c.description = "Pulls the Secret from Kubectl and pushes them to Cryptopus.\n" \
151
- 'If a Cryptopus Account in the selected folder using the name ' \
151
+ 'If a Cryptopus Encryptable in the selected folder using the name ' \
152
152
  "of the given secret is already present, it will be updated accordingly.\n" \
153
153
  'If no name is given, it will pull all secrets inside the selected project.'
154
154
 
@@ -180,25 +180,24 @@ class CLI
180
180
  c.summary = 'Pushes secret from Cryptopus to Kubectl'
181
181
  c.description = 'Pushes the Secret to Kubectl by retrieving it from Cryptopus first. ' \
182
182
  'If a Secret in the selected Kubectl project using the name ' \
183
- 'of the given accountname is already present, it will be updated accordingly.'
183
+ 'of the given name is already present, it will be updated accordingly.'
184
184
 
185
185
  c.action do |args|
186
186
  secret_name = args.first
187
187
  exit_with_error(:usage_error, 'Only one secret can be pushed') if args.length > 1
188
188
  execute_action({ secret_name: secret_name }) do
189
- secret_accounts = if secret_name.nil?
190
- logger.info 'Fetching all accounts in folder...'
191
- session_adapter.selected_folder.accounts
189
+ secret_encryptables = if secret_name.nil?
190
+ logger.info 'Fetching all encryptables in folder...'
191
+ session_adapter.selected_folder.encryptables
192
192
  else
193
- logger.info "Fetching account #{secret_name}..."
194
- [cryptopus_adapter.find_account_by_name(secret_name)]
193
+ logger.info "Fetching encryptable #{secret_name}..."
194
+ [cryptopus_adapter.find_encryptable_by_name(secret_name)]
195
195
  end
196
- secret_accounts.each do |account|
197
- logger.info "Fetching secret #{account.accountname}..."
198
- secret_account = Account.find(account.id)
199
- logger.info "Inserting secret #{account.accountname}..."
200
- k8s_adapter.insert_secret(secret_account.to_osesecret)
201
- log_success "Secret #{secret_account.accountname} was successfully applied"
196
+ secret_encryptables.each do |encryptable|
197
+ secret_encryptable = Encryptable.find(encryptable.id)
198
+ logger.info "Inserting secret #{encryptable.name}..."
199
+ k8s_adapter.insert_secret(secret_encryptable.to_osesecret)
200
+ log_success "Secret #{secret_encryptable.name} was successfully applied"
202
201
  end
203
202
  end
204
203
  end
@@ -264,7 +263,7 @@ class CLI
264
263
  exit_with_error(:usage_error, 'kubectl is not installed')
265
264
  rescue KubernetesClientNotLoggedInError
266
265
  exit_with_error(:usage_error, 'kubectl is not logged in')
267
- rescue CryptopusAccountNotFoundError
266
+ rescue CryptopusEncryptableNotFoundError
268
267
  exit_with_error(:usage_error, 'Secret with the given name ' \
269
268
  "#{options[:secret_name]} was not found")
270
269
  rescue OpenshiftSecretNotFoundError
data/lib/errors.rb CHANGED
@@ -30,7 +30,7 @@ end
30
30
  class NoFolderSelectedError < Error
31
31
  end
32
32
 
33
- class CryptopusAccountNotFoundError < Error
33
+ class CryptopusEncryptableNotFoundError < Error
34
34
  end
35
35
 
36
36
  class TeamNotFoundError < Error
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Encryptable
4
+ attr_reader :id, :name, :username, :password, :type, :ose_secret
5
+ attr_accessor :folder
6
+
7
+ def initialize(name: nil, username: nil, password: nil,
8
+ ose_secret: nil, type: nil, id: nil)
9
+ @id = id
10
+ @name = name
11
+ @username = username
12
+ @password = password
13
+ @ose_secret = ose_secret
14
+ @type = type || 'credentials'
15
+ end
16
+
17
+ def to_json(*_args)
18
+ EncryptableSerializer.to_json(self)
19
+ end
20
+
21
+ def to_yaml
22
+ EncryptableSerializer.to_yaml(self)
23
+ end
24
+
25
+ def to_osesecret
26
+ EncryptableSerializer.to_osesecret(self)
27
+ end
28
+
29
+ class << self
30
+ def find(id)
31
+ EncryptableSerializer.from_json(CryptopusAdapter.new.get("encryptables/#{id}"))
32
+ end
33
+
34
+ def find_by_name_and_folder_id(name, id)
35
+ Folder.find(id).encryptables.find do |encryptable|
36
+ encryptable.name.downcase == name.downcase
37
+ end
38
+ end
39
+
40
+ def from_json(json)
41
+ EncryptableSerializer.from_json(json)
42
+ end
43
+ end
44
+ end
data/lib/models/folder.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Folder
4
- attr_reader :name, :id, :accounts
4
+ attr_reader :name, :id, :encryptables
5
5
 
6
- def initialize(name: nil, id: nil, accounts: [])
6
+ def initialize(name: nil, id: nil, encryptables: [])
7
7
  @name = name
8
8
  @id = id
9
- @accounts = accounts
9
+ @encryptables = encryptables
10
10
  end
11
11
 
12
12
  class << self
@@ -15,11 +15,11 @@ class Folder
15
15
  symbolize_names: true)
16
16
  included = json[:included] || []
17
17
  name = json[:data][:attributes][:name]
18
- accounts = included.map do |record|
19
- Account.from_json(record.to_json) if %w[account_ose_secrets
20
- account_credentials].include? record[:type]
18
+ encryptables = included.map do |record|
19
+ Encryptable.from_json(record.to_json) if %w[encryptable_ose_secrets
20
+ encryptable_credentials].include? record[:type]
21
21
  end.compact
22
- Folder.new(id: id, name: name, accounts: accounts)
22
+ Folder.new(id: id, name: name, encryptables: encryptables)
23
23
  end
24
24
  end
25
25
  end
@@ -8,8 +8,8 @@ class OSESecret
8
8
  @ose_secret = ose_secret
9
9
  end
10
10
 
11
- def to_account
12
- OSESecretSerializer.to_account(self)
11
+ def to_encryptable
12
+ OSESecretSerializer.to_encryptable(self)
13
13
  end
14
14
 
15
15
  def to_yaml
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ class EncryptableSerializer
6
+ class << self
7
+ # rubocop:disable Metrics/MethodLength
8
+ def to_json(encryptable)
9
+ {
10
+ data: {
11
+ type: 'encryptables',
12
+ id: encryptable.id,
13
+ attributes: {
14
+ name: encryptable.name,
15
+ type: encryptable.type,
16
+ cleartext_username: encryptable.username,
17
+ cleartext_password: encryptable.password,
18
+ cleartext_ose_secret: encryptable.ose_secret
19
+ },
20
+ relationships: {
21
+ folder: {
22
+ data: {
23
+ id: encryptable.folder,
24
+ type: 'folders'
25
+ }
26
+ }
27
+ }
28
+ }
29
+ }.compact.to_json
30
+ end
31
+ # rubocop:enable Metrics/MethodLength
32
+
33
+ def to_yaml(encryptable)
34
+ { 'id' => encryptable.id,
35
+ 'name' => encryptable.name,
36
+ 'username' => encryptable.username,
37
+ 'password' => encryptable.password,
38
+ 'type' => encryptable.type }.to_yaml
39
+ end
40
+
41
+ def from_json(json)
42
+ json = JSON.parse(json, symbolize_names: true)
43
+ data = json[:data] || json
44
+ attributes = data[:attributes]
45
+ Encryptable.new(name: attributes[:name],
46
+ username: attributes[:cleartext_username],
47
+ password: attributes[:cleartext_password],
48
+ ose_secret: attributes[:ose_secret],
49
+ type: attributes[:type],
50
+ id: data[:id])
51
+ end
52
+
53
+ def to_osesecret(account)
54
+ OSESecret.from_yaml(account.ose_secret)
55
+ end
56
+ end
57
+ end
@@ -21,8 +21,8 @@ class OSESecretSerializer
21
21
  end
22
22
  # rubocop:enable Metrics/MethodLength
23
23
 
24
- def to_account(secret)
25
- Account.new(accountname: secret.name, ose_secret: secret.ose_secret, type: 'ose_secret')
24
+ def to_encryptable(secret)
25
+ Encryptable.new(name: secret.name, ose_secret: secret.ose_secret, type: 'ose_secret')
26
26
  end
27
27
 
28
28
  def to_yaml(secret)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ccli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nils Rauch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-05 00:00:00.000000000 Z
11
+ date: 2022-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -34,46 +34,46 @@ dependencies:
34
34
  name: tty-command
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
39
+ version: '0.10'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ">="
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0'
46
+ version: '0.10'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: tty-exit
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ">="
51
+ - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: '0.1'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ">="
58
+ - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0'
60
+ version: '0.1'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: tty-logger
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ">="
65
+ - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0'
67
+ version: '0.6'
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - ">="
72
+ - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '0'
74
+ version: '0.6'
75
75
  description: |2
76
- CCLI is the Cryptopus Command Line Interface. It allows to fetch account data and list teams from Cryptopus.
76
+ CCLI is the Cryptopus Command Line Interface. It allows to fetch encryptable data and list teams from Cryptopus.
77
77
  One of the main functionality is backing up secrets from cluster services (currently: openshift, kubernetes)
78
78
  to Cryptopus and restoring them as well.
79
79
  email: rauch@puzzle.ch
@@ -101,13 +101,13 @@ files:
101
101
  - lib/adapters/session_adapter.rb
102
102
  - lib/cli.rb
103
103
  - lib/errors.rb
104
- - lib/models/account.rb
104
+ - lib/models/encryptable.rb
105
105
  - lib/models/folder.rb
106
106
  - lib/models/k8s_secret.rb
107
107
  - lib/models/ose_secret.rb
108
108
  - lib/models/team.rb
109
109
  - lib/presenters/team_presenter.rb
110
- - lib/serializers/account_serializer.rb
110
+ - lib/serializers/encryptable_serializer.rb
111
111
  - lib/serializers/folder_serializer.rb
112
112
  - lib/serializers/ose_secret_serializer.rb
113
113
  - lib/serializers/team_serializer.rb
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Account
4
- attr_reader :id, :accountname, :username, :password, :type, :ose_secret
5
- attr_accessor :folder
6
-
7
- def initialize(accountname: nil, username: nil, password: nil,
8
- ose_secret: nil, type: nil, id: nil)
9
- @id = id
10
- @accountname = accountname
11
- @username = username
12
- @password = password
13
- @ose_secret = ose_secret
14
- @type = type || 'credentials'
15
- end
16
-
17
- def to_json(*_args)
18
- AccountSerializer.to_json(self)
19
- end
20
-
21
- def to_yaml
22
- AccountSerializer.to_yaml(self)
23
- end
24
-
25
- def to_osesecret
26
- AccountSerializer.to_osesecret(self)
27
- end
28
-
29
- class << self
30
- def find(id)
31
- AccountSerializer.from_json(CryptopusAdapter.new.get("accounts/#{id}"))
32
- end
33
-
34
- def find_by_name_and_folder_id(name, id)
35
- Folder.find(id).accounts.find do |account|
36
- account.accountname.downcase == name.downcase
37
- end
38
- end
39
-
40
- def from_json(json)
41
- AccountSerializer.from_json(json)
42
- end
43
- end
44
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'yaml'
4
-
5
- class AccountSerializer
6
- class << self
7
- # rubocop:disable Metrics/MethodLength
8
- def to_json(account)
9
- {
10
- data: {
11
- type: 'accounts',
12
- id: account.id,
13
- attributes: {
14
- accountname: account.accountname,
15
- type: account.type,
16
- cleartext_username: account.username,
17
- cleartext_password: account.password,
18
- ose_secret: account.ose_secret
19
- },
20
- relationships: {
21
- folder: {
22
- data: {
23
- id: account.folder,
24
- type: 'folders'
25
- }
26
- }
27
- }
28
- }
29
- }.compact.to_json
30
- end
31
- # rubocop:enable Metrics/MethodLength
32
-
33
- def to_yaml(account)
34
- { 'id' => account.id,
35
- 'accountname' => account.accountname,
36
- 'username' => account.username,
37
- 'password' => account.password,
38
- 'type' => account.type }.to_yaml
39
- end
40
-
41
- def from_json(json)
42
- json = JSON.parse(json, symbolize_names: true)
43
- data = json[:data] || json
44
- attributes = data[:attributes]
45
- Account.new(accountname: attributes[:accountname],
46
- username: attributes[:cleartext_username],
47
- password: attributes[:cleartext_password],
48
- ose_secret: attributes[:ose_secret],
49
- type: attributes[:type],
50
- id: data[:id])
51
- end
52
-
53
- def to_osesecret(account)
54
- OSESecret.from_yaml(account.ose_secret)
55
- end
56
- end
57
- end