apmate 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/apmate/cli.rb +37 -144
- data/lib/apmate/commands/apply.rb +32 -0
- data/lib/apmate/commands/base.rb +18 -0
- data/lib/apmate/commands/get/artifact.rb +21 -0
- data/lib/apmate/commands/get/artifact_environment.rb +21 -0
- data/lib/apmate/commands/get/artifact_name.rb +21 -0
- data/lib/apmate/commands/get.rb +8 -0
- data/lib/apmate/commands/help.rb +17 -0
- data/lib/apmate/commands/promote.rb +23 -0
- data/lib/apmate/logger/logger.rb +31 -0
- data/lib/apmate/version.rb +1 -1
- data/lib/apmate.rb +10 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f679bfcd9b4a5ba1a3e2e77233579372ccb920cc
|
4
|
+
data.tar.gz: dcce6f5b24192a76fabada8295d88bf0a0a0ac87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 861aabdb368c4bc510c65257672bb2bd8aaf37590f2f226259c200e2ca75bd20202fb692cde0fc22bef38b36abfa9b1092f2fba229203689bde11298d8dcf59f
|
7
|
+
data.tar.gz: 3c26ca10bece7363629d29fee9e40b69698816e895df5e87e6f5834f30a21392d5a97647d3de2ba2324eaf2ca492e33fa1be19b97dc54e813cd0e0a6ca450afb
|
data/lib/apmate/cli.rb
CHANGED
@@ -9,42 +9,16 @@ require 'pp'
|
|
9
9
|
require 'uri'
|
10
10
|
require 'yaml'
|
11
11
|
|
12
|
-
|
13
|
-
class Apmate::Logger
|
14
|
-
@@logger = nil
|
15
|
-
|
16
|
-
def self.logger
|
17
|
-
@@logger
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.logger=(logger)
|
21
|
-
@@logger = logger
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.log_level(opts)
|
25
|
-
if opts[:log]
|
26
|
-
if opts[:log] == true
|
27
|
-
@@logger = ::Logger.new(File.join Dir.pwd, 'apmate-cli.log')
|
28
|
-
else
|
29
|
-
@@logger = ::Logger.new(File.join Dir.pwd, opts[:log])
|
30
|
-
end
|
31
|
-
else
|
32
|
-
@@logger = ::Logger.new('/dev/null')
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.verbosity(opts)
|
37
|
-
if opts[:verbose]
|
38
|
-
@@logger.level = ::Logger::DEBUG
|
39
|
-
else
|
40
|
-
@@logger.level = ::Logger::INFO
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
12
|
class Apmate::CLI
|
46
13
|
APMATE_BASE_URL = ENV['APMATE_BASE_URL'] || 'http://localhost'
|
47
14
|
APMATE_PORT = ENV['APMATE_PORT'] || '3000'
|
15
|
+
APMATE_URL = "#{APMATE_BASE_URL}:#{APMATE_PORT}"
|
16
|
+
ENDPOINTS = {
|
17
|
+
get_artifact_environment: '/api/artifacts/environment',
|
18
|
+
get_artifact: '/api/artifacts',
|
19
|
+
get_artifact_name: '/api/artifacts/name',
|
20
|
+
promote_environment: '/api/environments/promote'
|
21
|
+
}
|
48
22
|
|
49
23
|
def self.apply_file(file, opts)
|
50
24
|
Apmate::Logger.logger.info "applying file #{file}"
|
@@ -69,11 +43,25 @@ class Apmate::CLI
|
|
69
43
|
end
|
70
44
|
end
|
71
45
|
|
72
|
-
def self.
|
46
|
+
def self.apmate_get_artifact_environment(artifact_name, environment_name, opts)
|
47
|
+
params = { :name => artifact_name, :environment_name => environment_name }
|
48
|
+
apmate_get(ENDPOINTS[:get_artifact_environment], opts, params)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.apmate_get_artifact_name(artifact_id, group_id, filename_extension, opts)
|
52
|
+
params = { artifact_id: artifact_id, group_id: group_id, filename_extension: filename_extension }
|
53
|
+
apmate_get(ENDPOINTS[:get_artifact_name], opts, params)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.apmate_get_artifact(artifact_name, opts)
|
57
|
+
params = {name: artifact_name}
|
58
|
+
apmate_get(ENDPOINTS[:get_artifact], opts, params)
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.apmate_get(endpoint, opts, params=nil)
|
73
62
|
Apmate::Logger.logger.debug "Beginning get request."
|
74
|
-
uri = URI("#{Apmate::CLI::
|
63
|
+
uri = URI("#{Apmate::CLI::APMATE_URL}#{endpoint}")
|
75
64
|
Apmate::Logger.logger.debug "uri: #{uri}"
|
76
|
-
params = { :name => artifact_name, :environment_name => environment_name }
|
77
65
|
uri.query = URI.encode_www_form(params)
|
78
66
|
response = Net::HTTP.get_response(uri)
|
79
67
|
output = JSON.pretty_generate(JSON.parse(response.body))
|
@@ -105,7 +93,7 @@ class Apmate::CLI
|
|
105
93
|
def self.apmate_promote(env_from, env_to, opts)
|
106
94
|
Apmate::Logger.logger.debug "Beginning post request."
|
107
95
|
|
108
|
-
uri = URI("#{Apmate::CLI::
|
96
|
+
uri = URI("#{Apmate::CLI::APMATE_URL}#{ENDPOINTS[:promote_environment]}")
|
109
97
|
Apmate::Logger.logger.debug "uri: #{uri}"
|
110
98
|
|
111
99
|
payload = { environment_from: env_from, environment_to: env_to }
|
@@ -133,117 +121,22 @@ class Apmate::CLI
|
|
133
121
|
end
|
134
122
|
|
135
123
|
def run
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
exit 0
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
help_command = Cri::Command.define do
|
149
|
-
name 'help'
|
150
|
-
usage 'help'
|
151
|
-
summary 'Prints help screen.'
|
152
|
-
description 'This command prints the help screen.'
|
153
|
-
|
154
|
-
flag :h, :help, 'show help for this command' do |value, cmd|
|
155
|
-
puts cmd.help
|
156
|
-
exit 0
|
157
|
-
end
|
158
|
-
|
159
|
-
run do |opts, args, cmd|
|
160
|
-
command.run ['-h']
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
get_command = Cri::Command.define do
|
165
|
-
name 'get'
|
166
|
-
usage 'get <artifact_name> <environment_name>'
|
167
|
-
summary 'Returns the requested object from the datastore.'
|
168
|
-
description 'Returns the requested object from the datastore.'
|
169
|
-
|
170
|
-
flag :h, :help, 'show help for this command' do |value, cmd|
|
171
|
-
puts cmd.help
|
172
|
-
exit 0
|
173
|
-
end
|
174
|
-
|
175
|
-
run do |opts, args, cmd|
|
176
|
-
Apmate::Logger.log_level(opts)
|
177
|
-
Apmate::Logger.verbosity(opts)
|
178
|
-
Apmate::Logger.logger.debug "opts: #{opts}"
|
179
|
-
Apmate::Logger.logger.debug "args: #{args}"
|
180
|
-
Apmate::Logger.logger.debug "cmd: #{cmd.to_s}"
|
181
|
-
cmd.run(['-h']) unless args.count == 2
|
182
|
-
Apmate::CLI.apmate_get(args[0], args[1], opts)
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
promote_command = Cri::Command.define do
|
187
|
-
name 'promote'
|
188
|
-
usage 'promote <environment_from_name> <environment_to_name>'
|
189
|
-
summary 'Promotes values from one environment to another environment.'
|
190
|
-
description 'Promotes values from one environment to another environment.'
|
191
|
-
|
192
|
-
flag :h, :help, 'show help for this command' do |value, cmd|
|
193
|
-
puts cmd.help
|
194
|
-
exit 0
|
195
|
-
end
|
196
|
-
|
197
|
-
run do |opts, args, cmd|
|
198
|
-
Apmate::Logger.log_level(opts)
|
199
|
-
Apmate::Logger.verbosity(opts)
|
200
|
-
Apmate::Logger.logger.debug "opts: #{opts}"
|
201
|
-
Apmate::Logger.logger.debug "args: #{args}"
|
202
|
-
Apmate::Logger.logger.debug "cmd: #{cmd.to_s}"
|
203
|
-
cmd.run(['-h']) unless args.count == 2
|
204
|
-
Apmate::CLI.apmate_promote(args[0], args[1], opts)
|
205
|
-
end
|
124
|
+
get_command = Command::GET
|
125
|
+
|
126
|
+
[
|
127
|
+
Command::Get::ARTIFACT,
|
128
|
+
Command::Get::ARTIFACT_ENVIRONMENT,
|
129
|
+
Command::Get::ARTIFACT_NAME
|
130
|
+
].each do |cmd|
|
131
|
+
get_command.add_command cmd
|
206
132
|
end
|
207
133
|
|
208
|
-
|
209
|
-
name 'apply'
|
210
|
-
usage 'apply [options] <arg>'
|
211
|
-
summary 'Creates or updates objects in the Apmate environment datastore.'
|
212
|
-
description 'Creates or updates objects in the Apmate environment datastore.'
|
213
|
-
|
214
|
-
flag :h, :help, 'show help for this command' do |value, cmd|
|
215
|
-
puts cmd.help
|
216
|
-
exit 0
|
217
|
-
end
|
218
|
-
flag :v, :verbose, 'be verbose'
|
219
|
-
flag :q, :quiet, 'Do not output Apmate reponse.'
|
220
|
-
required :o, :output, 'Name of file to write operation output.'
|
221
|
-
optional :l, :log, 'Write to log file if passed. Set a value for a custom location.'
|
222
|
-
|
223
|
-
run do |opts, args, cmd|
|
224
|
-
Apmate::Logger.log_level(opts)
|
225
|
-
Apmate::Logger.verbosity(opts)
|
226
|
-
Apmate::Logger.logger.debug "opts: #{opts}"
|
227
|
-
Apmate::Logger.logger.debug "args: #{args}"
|
228
|
-
Apmate::Logger.logger.debug "cmd: #{cmd.to_s}"
|
229
|
-
cmd.run(['-h']) unless args[0]
|
230
|
-
if args[0]
|
231
|
-
if File.directory? args[0]
|
232
|
-
Apmate::CLI.apply_dir args[0], opts
|
233
|
-
else
|
234
|
-
Apmate::CLI.apply_file args[0], opts
|
235
|
-
end
|
236
|
-
else
|
237
|
-
puts cmd.help
|
238
|
-
exit 0
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
134
|
+
command = Command::BASE
|
242
135
|
[
|
243
|
-
|
244
|
-
|
136
|
+
Command::HELP,
|
137
|
+
Command::APPLY,
|
245
138
|
get_command,
|
246
|
-
|
139
|
+
Command::PROMOTE
|
247
140
|
].each do |cmd|
|
248
141
|
command.add_command cmd
|
249
142
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Apmate::CLI::Command
|
2
|
+
APPLY = Cri::Command.define do
|
3
|
+
name 'apply'
|
4
|
+
usage 'apply [options] <path>'
|
5
|
+
summary 'Creates or updates objects in the Apmate environment datastore.'
|
6
|
+
description 'Creates or updates objects in the Apmate environment datastore.'
|
7
|
+
|
8
|
+
flag :h, :help, 'show help for this command' do |value, cmd|
|
9
|
+
puts cmd.help
|
10
|
+
exit 0
|
11
|
+
end
|
12
|
+
|
13
|
+
run do |opts, args, cmd|
|
14
|
+
Apmate::Logger.log_level(opts)
|
15
|
+
Apmate::Logger.verbosity(opts)
|
16
|
+
Apmate::Logger.logger.debug "opts: #{opts}"
|
17
|
+
Apmate::Logger.logger.debug "args: #{args}"
|
18
|
+
Apmate::Logger.logger.debug "cmd: #{cmd.to_s}"
|
19
|
+
cmd.run(['-h']) unless args[0]
|
20
|
+
if args[0]
|
21
|
+
if File.directory? args[0]
|
22
|
+
Apmate::CLI.apply_dir args[0], opts
|
23
|
+
else
|
24
|
+
Apmate::CLI.apply_file args[0], opts
|
25
|
+
end
|
26
|
+
else
|
27
|
+
puts cmd.help
|
28
|
+
exit 0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Apmate::CLI::Command
|
2
|
+
BASE = Cri::Command.define do
|
3
|
+
name 'apmate'
|
4
|
+
usage 'apmate <command> [<args>]'
|
5
|
+
summary 'Environment datastore CLI'
|
6
|
+
description 'Apmate is responsible for managing data in the Apmate environment datastore.'
|
7
|
+
|
8
|
+
flag :h, :help, 'show help for this command' do |value, cmd|
|
9
|
+
puts cmd.help
|
10
|
+
exit 0
|
11
|
+
end
|
12
|
+
|
13
|
+
flag :v, :verbose, 'be verbose'
|
14
|
+
flag :q, :quiet, 'Do not output Apmate reponse.'
|
15
|
+
required :o, :output, 'Name of file to write operation output.'
|
16
|
+
optional :l, :log, 'Write to log file if passed. Set a value for a custom location.'
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Apmate::CLI::Command::Get
|
2
|
+
ARTIFACT = Cri::Command.define do
|
3
|
+
name 'artifact'
|
4
|
+
usage 'artifact <artifact_name>'
|
5
|
+
summary 'Returns the requested artifact object from the datastore.'
|
6
|
+
description 'Returns the requested artifact object from the datastore.'
|
7
|
+
|
8
|
+
run do |opts, args, cmd|
|
9
|
+
Apmate::Logger.log_level(opts)
|
10
|
+
Apmate::Logger.verbosity(opts)
|
11
|
+
Apmate::Logger.logger.debug "opts: #{opts}"
|
12
|
+
Apmate::Logger.logger.debug "args: #{args}"
|
13
|
+
Apmate::Logger.logger.debug "cmd: #{cmd.to_s}"
|
14
|
+
if args.count == 1
|
15
|
+
Apmate::CLI.apmate_get_artifact(args[0], opts)
|
16
|
+
else
|
17
|
+
cmd.run(['-h'])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Apmate::CLI::Command::Get
|
2
|
+
ARTIFACT_ENVIRONMENT = Cri::Command.define do
|
3
|
+
name 'artifact_environment'
|
4
|
+
usage 'artifact_environment <artifact_name> <environment_name>'
|
5
|
+
summary 'Returns the requested artifact with it\'s environment data from the datastore.'
|
6
|
+
description 'Returns the requested artifact with it\'s environment data from the datastore.'
|
7
|
+
|
8
|
+
run do |opts, args, cmd|
|
9
|
+
Apmate::Logger.log_level(opts)
|
10
|
+
Apmate::Logger.verbosity(opts)
|
11
|
+
Apmate::Logger.logger.debug "opts: #{opts}"
|
12
|
+
Apmate::Logger.logger.debug "args: #{args}"
|
13
|
+
Apmate::Logger.logger.debug "cmd: #{cmd.to_s}"
|
14
|
+
if args.count == 2
|
15
|
+
Apmate::CLI.apmate_get_artifact_environment(args[0], args[1], opts)
|
16
|
+
else
|
17
|
+
cmd.run(['-h'])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Apmate::CLI::Command::Get
|
2
|
+
ARTIFACT_NAME = Cri::Command.define do
|
3
|
+
name 'artifact_name'
|
4
|
+
usage 'artifact_name <artifact_id> <group_id> <filename_extension>'
|
5
|
+
summary 'Returns the requested artifact object name from the datastore.'
|
6
|
+
description 'Returns the requested artifact object name from the datastore.'
|
7
|
+
|
8
|
+
run do |opts, args, cmd|
|
9
|
+
Apmate::Logger.log_level(opts)
|
10
|
+
Apmate::Logger.verbosity(opts)
|
11
|
+
Apmate::Logger.logger.debug "opts: #{opts}"
|
12
|
+
Apmate::Logger.logger.debug "args: #{args}"
|
13
|
+
Apmate::Logger.logger.debug "cmd: #{cmd.to_s}"
|
14
|
+
if args.count == 3
|
15
|
+
Apmate::CLI.apmate_get_artifact_name(args[0], args[1], args[2], opts)
|
16
|
+
else
|
17
|
+
cmd.run(['-h'])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module Apmate::CLI::Command
|
2
|
+
GET = Cri::Command.define do
|
3
|
+
name 'get'
|
4
|
+
usage "get <command> [<args>]\n\nCommands: artifact, artifact_environment, artifact_name"
|
5
|
+
summary 'Returns the requested object or data from the datastore.'
|
6
|
+
description 'Returns the requested object or data from the datastore.'
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Apmate::CLI::Command
|
2
|
+
HELP = Cri::Command.define do
|
3
|
+
name 'help'
|
4
|
+
usage 'help'
|
5
|
+
summary 'Prints help screen.'
|
6
|
+
description 'This command prints the help screen.'
|
7
|
+
|
8
|
+
flag :h, :help, 'show help for this command' do |value, cmd|
|
9
|
+
puts cmd.help
|
10
|
+
exit 0
|
11
|
+
end
|
12
|
+
|
13
|
+
run do |opts, args, cmd|
|
14
|
+
command.run ['-h']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Apmate::CLI::Command
|
2
|
+
PROMOTE = Cri::Command.define do
|
3
|
+
name 'promote'
|
4
|
+
usage 'promote <environment_from> <environment_to>'
|
5
|
+
summary 'Promotes values from one environment to another environment.'
|
6
|
+
description 'Promotes values from one environment to another environment.'
|
7
|
+
|
8
|
+
flag :h, :help, 'show help for this command' do |value, cmd|
|
9
|
+
puts cmd.help
|
10
|
+
exit 0
|
11
|
+
end
|
12
|
+
|
13
|
+
run do |opts, args, cmd|
|
14
|
+
Apmate::Logger.log_level(opts)
|
15
|
+
Apmate::Logger.verbosity(opts)
|
16
|
+
Apmate::Logger.logger.debug "opts: #{opts}"
|
17
|
+
Apmate::Logger.logger.debug "args: #{args}"
|
18
|
+
Apmate::Logger.logger.debug "cmd: #{cmd.to_s}"
|
19
|
+
cmd.run(['-h']) unless args.count == 2
|
20
|
+
Apmate::CLI.apmate_promote(args[0], args[1], opts)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Apmate::Logger
|
2
|
+
@@logger = nil
|
3
|
+
|
4
|
+
def self.logger
|
5
|
+
@@logger
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.logger=(logger)
|
9
|
+
@@logger = logger
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.log_level(opts)
|
13
|
+
if opts[:log]
|
14
|
+
if opts[:log] == true
|
15
|
+
@@logger = ::Logger.new(File.join Dir.pwd, 'apmate-cli.log')
|
16
|
+
else
|
17
|
+
@@logger = ::Logger.new(File.join Dir.pwd, opts[:log])
|
18
|
+
end
|
19
|
+
else
|
20
|
+
@@logger = ::Logger.new('/dev/null')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.verbosity(opts)
|
25
|
+
if opts[:verbose]
|
26
|
+
@@logger.level = ::Logger::DEBUG
|
27
|
+
else
|
28
|
+
@@logger.level = ::Logger::INFO
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/apmate/version.rb
CHANGED
data/lib/apmate.rb
CHANGED
@@ -1,2 +1,12 @@
|
|
1
1
|
require "apmate/version"
|
2
|
+
require 'apmate/logger/logger'
|
2
3
|
require "apmate/cli"
|
4
|
+
|
5
|
+
require 'apmate/commands/base'
|
6
|
+
require 'apmate/commands/help'
|
7
|
+
require 'apmate/commands/get'
|
8
|
+
require 'apmate/commands/get/artifact'
|
9
|
+
require 'apmate/commands/get/artifact_environment'
|
10
|
+
require 'apmate/commands/get/artifact_name'
|
11
|
+
require 'apmate/commands/apply'
|
12
|
+
require 'apmate/commands/promote'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apmate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Baldridge
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cri
|
@@ -77,6 +77,15 @@ files:
|
|
77
77
|
- exe/apmate
|
78
78
|
- lib/apmate.rb
|
79
79
|
- lib/apmate/cli.rb
|
80
|
+
- lib/apmate/commands/apply.rb
|
81
|
+
- lib/apmate/commands/base.rb
|
82
|
+
- lib/apmate/commands/get.rb
|
83
|
+
- lib/apmate/commands/get/artifact.rb
|
84
|
+
- lib/apmate/commands/get/artifact_environment.rb
|
85
|
+
- lib/apmate/commands/get/artifact_name.rb
|
86
|
+
- lib/apmate/commands/help.rb
|
87
|
+
- lib/apmate/commands/promote.rb
|
88
|
+
- lib/apmate/logger/logger.rb
|
80
89
|
- lib/apmate/version.rb
|
81
90
|
homepage:
|
82
91
|
licenses: []
|