bld 0.1.4 → 0.1.6

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bld +2 -1
  3. data/bin/build +2 -1
  4. data/lib/commands.rb +231 -70
  5. metadata +22 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e58ad6d7f83190c1e03e61c08d300cf30d34ca0a565935c902739712968999b4
4
- data.tar.gz: e9836c61883993fac85828620cf0129ea2b6fe5e3b2939742189bdd833389c88
3
+ metadata.gz: 23ca92095150f9e2e36d9a2b64946ab21047349387aa7a6eebefc10e7f8227d3
4
+ data.tar.gz: f46aba8b557a61ee3ac3b41c366a1be1ea3c608e82e8cbf5ef8d1851fca7022d
5
5
  SHA512:
6
- metadata.gz: 2d103b0fad23903d458d79a6b6b6d5a23ab72ea117ef248511bb7e733d4b9622f91fd11c77b845ec4096ee5024b87f63e45d393ea58762165b6e3976aeb614c7
7
- data.tar.gz: 9f6a7f68f081c9e66667cf3cb345727e528df706040d6006cdd6e5fc2bffa2dab7bb7bda05e4611d4659fb0780ccfb696e1830770b18b027401d691df011c72a
6
+ metadata.gz: 5ca6e41446dbceea06b380d9e47b57e5b5b585f3b6a238c8c50d8a24c4bd6b613619771aa13d538cc7fe5c9f0c2cf63024a78a88a5d46f61048b05969fd089b7
7
+ data.tar.gz: d5a535ce8825b02b2d91f4df6fea86f71ccd3f58b285708cd3b21ecff065d8f58be849d973838f208a6cba5f7c79756f3227cfce9cae885acdeb06aad0206856
data/bin/bld CHANGED
@@ -5,6 +5,7 @@ require 'cli/ui'
5
5
  require 'launchy'
6
6
  require 'netrc'
7
7
  require 'httparty'
8
+ require 'net/ssh'
8
9
  require_relative '../lib/commands'
9
10
 
10
11
  ANTIMONY_HOST = "https://app.build.io"
@@ -19,7 +20,7 @@ class BuildCLI
19
20
 
20
21
  def run
21
22
  program :name, 'Build CLI'
22
- program :version, '0.1.4'
23
+ program :version, '0.1.6'
23
24
  program :description, "Build's Command Line Interface"
24
25
  program :int_block, -> { exit }
25
26
  default_command :help
data/bin/build CHANGED
@@ -5,6 +5,7 @@ require 'cli/ui'
5
5
  require 'launchy'
6
6
  require 'netrc'
7
7
  require 'httparty'
8
+ require 'net/ssh'
8
9
  require_relative '../lib/commands'
9
10
 
10
11
  ANTIMONY_HOST = "https://app.build.io"
@@ -19,7 +20,7 @@ class BuildCLI
19
20
 
20
21
  def run
21
22
  program :name, 'Build CLI'
22
- program :version, '0.1.4'
23
+ program :version, '0.1.6'
23
24
  program :description, "Build's Command Line Interface"
24
25
  program :int_block, -> { exit }
25
26
  default_command :help
data/lib/commands.rb CHANGED
@@ -2,43 +2,208 @@
2
2
  class BuildCLICommands
3
3
  def self.index
4
4
  return {
5
- "apps:create": {
6
- cli_details: { :syntax => "apps:create [options] -a <app>", :description => "Create a new app",
7
- :options => [["-t", "--team=<value>", String, "team to use"], ["-r", "--region=<value>", String, "specify region for the app to run in"], ["-s", "--stack=<value>", String, "the stack to create the app on"], ["-a", "--app=<value>", String, "(required) the name of the app to create"]] },
5
+ "config": {
6
+ cli_details: { :syntax => "build config -a <app>", :description => "Get the config variables for an app",
7
+ :options => [["-a", "--app=<value>", String, "(required) app to run command against"]] },
8
8
  cli_perform: Proc.new { |args, options|
9
- begin
10
- user_netrc = Netrc.read
11
- user_token = user_netrc.[]("build.io").[](1)
12
- auth = "Bearer #{user_token}"
13
- app_name = options.app
14
- if app_name.nil?
15
- puts(CLI::UI.fmt("{{red:›}} Error: no app name specified"))
9
+ app_name = options.app
10
+ if app_name.nil? || app_name.strip == ""
11
+ puts(CLI::UI.fmt("{{red:›}} Error: The following error occurred:"))
12
+ puts(CLI::UI.fmt("{{red:›}} {{gray:Missing required flag app}}"))
13
+ puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
14
+ exit(1)
15
+ end
16
+ user_netrc = Netrc.read
17
+ user_token = user_netrc.[]("build.io")&.password
18
+ if user_token.nil?
19
+ puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
20
+ exit(1)
21
+ end
22
+ auth = "Bearer #{user_token}"
23
+ query_params = {}
24
+ query_params.[]=(:app, app_name)
25
+ query_string = URI.encode_www_form(query_params)
26
+ res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config?#{query_string}",
27
+ { headers: { "Authorization" => auth } })
28
+ if res.code != 200
29
+ if res.body.[]("error")
30
+ puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
31
+ exit(1)
32
+ else
33
+ puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
16
34
  exit(1)
17
35
  end
18
- query_params = {}
19
- query_params.[]=(:app, app_name)
20
- if options.team
21
- query_params.[]=(:team, options.team)
22
- end
23
- if options.region
24
- query_params.[]=(:region, options.region)
36
+ end
37
+ JSON.parse(res.body).each { |key, value|
38
+ puts("#{key}=#{value}")
39
+ }
40
+ },
41
+ },
42
+ "config:get": {
43
+ cli_details: { :syntax => "build config:get VARIABLE -a <app>", :description => "Get a config variable for an app",
44
+ :options => [["-a", "--app=<value>", String, "(required) app to run command against"]] },
45
+ cli_perform: Proc.new { |args, options|
46
+ app_name = options.app
47
+ if app_name.nil? || app_name.strip == ""
48
+ puts(CLI::UI.fmt("{{red:›}} Error: The following error occurred:"))
49
+ puts(CLI::UI.fmt("{{red:›}} {{gray:Missing required flag app}}"))
50
+ puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
51
+ exit(1)
52
+ end
53
+ config_variable = args.[](0)
54
+ if config_variable.nil? || config_variable.strip == ""
55
+ puts(CLI::UI.fmt("{{red:›}} Error: The following error occurred:"))
56
+ puts(CLI::UI.fmt("{{red:›}} {{gray:Missing required argument VARIABLE}}"))
57
+ puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
58
+ exit(1)
59
+ end
60
+ user_netrc = Netrc.read
61
+ user_token = user_netrc.[]("build.io")&.password
62
+ if user_token.nil?
63
+ puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
64
+ exit(1)
65
+ end
66
+ auth = "Bearer #{user_token}"
67
+ query_params = {}
68
+ query_params.[]=(:app, app_name)
69
+ query_params.[]=(:key, config_variable)
70
+ query_string = URI.encode_www_form(query_params)
71
+ res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config/get?#{query_string}",
72
+ { headers: { "Authorization" => auth } })
73
+ if res.code != 200
74
+ if res.body.[]("error")
75
+ puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
76
+ exit(1)
77
+ else
78
+ puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
79
+ exit(1)
25
80
  end
26
- if options.stack
27
- query_params.[]=(:stack, options.stack)
81
+ end
82
+ puts(res.body)
83
+ },
84
+ },
85
+ "config:set": {
86
+ cli_details: { :syntax => "build config:set VARIABLE=VALUE -a <app>", :description => "Set config variables for an app",
87
+ :options => [["-a", "--app=<value>", String, "(required) app to run command against"]] },
88
+ cli_perform: Proc.new { |args, options|
89
+ app_name = options.app
90
+ if app_name.nil? || app_name.strip == ""
91
+ puts(CLI::UI.fmt("{{red:›}} Error: The following error occurred:"))
92
+ puts(CLI::UI.fmt("{{red:›}} {{gray:Missing required flag app}}"))
93
+ puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
94
+ exit(1)
95
+ end
96
+ config_variables = args.map { |arg,|
97
+ arg.split("=")
98
+ }.to_h
99
+ if config_variables.empty?
100
+ puts(CLI::UI.fmt("{{red:›}} Error: The following error occurred:"))
101
+ puts(CLI::UI.fmt("{{red:›}} {{gray:No config variables provided}}"))
102
+ puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
103
+ exit(1)
104
+ end
105
+ user_netrc = Netrc.read
106
+ user_token = user_netrc.[]("build.io")&.password
107
+ if user_token.nil?
108
+ puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
109
+ exit(1)
110
+ end
111
+ auth = "Bearer #{user_token}"
112
+ query_params = {}
113
+ query_params.[]=(:app, app_name)
114
+ query_params.[]=(:config, config_variables.to_json)
115
+ query_string = URI.encode_www_form(query_params)
116
+ res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config/set?#{query_string}",
117
+ { headers: { "Authorization" => auth } })
118
+ if res.code != 200
119
+ if res.body && res.body.[]("error")
120
+ puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
121
+ else
122
+ puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
28
123
  end
29
- query_string = URI.encode_www_form(query_params)
30
- res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/apps/create?#{query_string}",
31
- { headers: { "Authorization" => auth } })
32
- if res.code != 200
33
- puts(CLI::UI.fmt("{{red:›}} Error: not authorized to create app (#{app_name})"))
34
- exit(1)
124
+ exit(1)
125
+ end
126
+ puts(CLI::UI.fmt("{{green:›}} Config variable(s) set successfully"))
127
+ },
128
+ },
129
+ "config:unset": {
130
+ cli_details: { :syntax => "build config:unset VARIABLE -a <app>", :description => "Un-Set config variables for an app",
131
+ :options => [["-a", "--app=<value>", String, "(required) app to run command against"]] },
132
+ cli_perform: Proc.new { |args, options|
133
+ app_name = options.app
134
+ if app_name.nil? || app_name.strip == ""
135
+ puts(CLI::UI.fmt("{{red:›}} Error: The following error occurred:"))
136
+ puts(CLI::UI.fmt("{{red:›}} {{gray:Missing required flag app}}"))
137
+ puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
138
+ exit(1)
139
+ end
140
+ config_variables = args.compact
141
+ if config_variables.empty?
142
+ puts(CLI::UI.fmt("{{red:›}} Error: The following error occurred:"))
143
+ puts(CLI::UI.fmt("{{red:›}} {{gray:No config variables provided}}"))
144
+ puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
145
+ exit(1)
146
+ end
147
+ user_netrc = Netrc.read
148
+ user_token = user_netrc.[]("build.io")&.password
149
+ if user_token.nil?
150
+ puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
151
+ exit(1)
152
+ end
153
+ auth = "Bearer #{user_token}"
154
+ query_params = {}
155
+ query_params.[]=(:app, app_name)
156
+ query_params.[]=(:config, config_variables)
157
+ query_string = URI.encode_www_form(query_params)
158
+ res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/config/unset?#{query_string}",
159
+ { headers: { "Authorization" => auth } })
160
+ if res.code != 200
161
+ if res.body && res.body.[]("error")
162
+ puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
163
+ else
164
+ puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
35
165
  end
36
- app_name = JSON.parse(res.body).[]("name")
37
- puts("https://#{app_name}.#{region}.antimony.io | #{app_name}")
38
- rescue
166
+ exit(1)
167
+ end
168
+ puts(CLI::UI.fmt("{{green:›}} Config variable(s) unset successfully"))
169
+ },
170
+ },
171
+ "apps:create": {
172
+ cli_details: { :syntax => "apps:create [options] -a <app>", :description => "Create a new app",
173
+ :options => [["-t", "--team=<value>", String, "team to use"], ["-r", "--region=<value>", String, "specify region for the app to run in"], ["-s", "--stack=<value>", String, "the stack to create the app on"], ["-a", "--app=<value>", String, "(required) the name of the app to create"]] },
174
+ cli_perform: Proc.new { |args, options|
175
+ user_netrc = Netrc.read
176
+ user_token = user_netrc.[]("build.io")&.password
177
+ if user_token.nil?
39
178
  puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
40
179
  exit(1)
41
180
  end
181
+ auth = "Bearer #{user_token}"
182
+ app_name = options.app
183
+ if app_name.nil?
184
+ puts(CLI::UI.fmt("{{red:›}} Error: no app name specified"))
185
+ exit(1)
186
+ end
187
+ query_params = {}
188
+ query_params.[]=(:app, app_name)
189
+ if options.team
190
+ query_params.[]=(:team, options.team)
191
+ end
192
+ if options.region
193
+ query_params.[]=(:region, options.region)
194
+ end
195
+ if options.stack
196
+ query_params.[]=(:stack, options.stack)
197
+ end
198
+ query_string = URI.encode_www_form(query_params)
199
+ res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/apps/create?#{query_string}",
200
+ { headers: { "Authorization" => auth } })
201
+ if res.code != 200
202
+ puts(CLI::UI.fmt("{{red:›}} Error: not authorized to create app (#{app_name})"))
203
+ exit(1)
204
+ end
205
+ app_name = JSON.parse(res.body).[]("name")
206
+ puts("https://#{app_name}.#{region}.antimony.io | #{app_name}")
42
207
  },
43
208
  },
44
209
  "login": {
@@ -91,15 +256,13 @@ class BuildCLICommands
91
256
  puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
92
257
  exit(1)
93
258
  end
94
-
95
- begin
96
- user_netrc = Netrc.read
97
- user_token = user_netrc.[]("build.io").[](1)
98
- auth = "Bearer #{user_token}"
99
- rescue
259
+ user_netrc = Netrc.read
260
+ user_token = user_netrc.[]("build.io")&.password
261
+ if user_token.nil?
100
262
  puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
101
263
  exit(1)
102
264
  end
265
+ auth = "Bearer #{user_token}"
103
266
  query_params = {}
104
267
  if options.num
105
268
  query_params.[]=(:num, options.num)
@@ -143,54 +306,52 @@ class BuildCLICommands
143
306
  cli_details: { :syntax => "build whoami", :description => "Display the current logged in user",
144
307
  :options => [] },
145
308
  cli_perform: Proc.new { |args, options|
146
- begin
147
- user_netrc = Netrc.read
148
- user_token = user_netrc.[]("build.io").[](1)
149
- auth = "Bearer #{user_token}"
150
- res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/whoami",
151
- { headers: { "Authorization" => auth } })
152
- if res.code != 200
153
- puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
154
- exit(1)
155
- end
156
- puts(JSON.parse(res.body).[]("email"))
157
- rescue
309
+ user_netrc = Netrc.read
310
+ user_token = user_netrc.[]("build.io")&.password
311
+ if user_token.nil?
312
+ puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
313
+ exit(1)
314
+ end
315
+ auth = "Bearer #{user_token}"
316
+ res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/whoami",
317
+ { headers: { "Authorization" => auth } })
318
+ if res.code != 200
158
319
  puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
159
320
  exit(1)
160
321
  end
322
+ puts(JSON.parse(res.body).[]("email"))
161
323
  },
162
324
  },
163
325
  "run": {
164
326
  cli_details: { :syntax => "build run COMMAND -a <app>", :description => "Run a once-off process in an app",
165
327
  :options => [["-a", "--app=<value>", String, "(required) app to run command against"]] },
166
328
  cli_perform: Proc.new { |args, options|
167
- begin
168
- if args.empty?
169
- puts(CLI::UI.fmt("{{red:›}} Error: no command provided"))
170
- exit(1)
171
- end
172
- user_netrc = Netrc.read
173
- user_token = user_netrc.[]("build.io").[](1)
174
- auth = "Bearer #{user_token}"
175
- query_params = {}
176
- if options.app
177
- query_params.[]=(:app, options.app)
178
- end
179
- query_string = URI.encode_www_form(query_params)
180
- res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/run?#{query_string}",
181
- { headers: { "Authorization" => auth } })
182
- if res.code != 200
183
- puts(CLI::UI.fmt("{{red:›}} Error: app not found"))
184
- exit(1)
329
+ if args.empty?
330
+ puts(CLI::UI.fmt("{{red:›}} Error: no command provided"))
331
+ exit(1)
332
+ end
333
+ user_netrc = Netrc.read
334
+ user_token = user_netrc.[]("build.io").[](1)
335
+ auth = "Bearer #{user_token}"
336
+ query_params = {}
337
+ if options.app
338
+ query_params.[]=(:app, options.app)
339
+ end
340
+ query_string = URI.encode_www_form(query_params)
341
+ res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/run?#{query_string}",
342
+ { headers: { "Authorization" => auth } })
343
+ if res.code != 200
344
+ if res.body.[]("error")
345
+ puts(CLI::UI.fmt("{{red:›}} Error: #{res.body.[]("error")}"))
346
+ else
347
+ puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
185
348
  end
186
- ruby = JSON.parse(res.body).[]("ruby")
187
- require("shellwords")
188
- command = "/cnb/lifecycle/launcher #{Shellwords.join(args)}"
189
- eval(ruby)
190
- rescue
191
- puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
192
349
  exit(1)
193
350
  end
351
+ ruby = JSON.parse(res.body).[]("ruby")
352
+ require("shellwords")
353
+ command = "/cnb/lifecycle/launcher #{Shellwords.join(args)}"
354
+ eval(ruby)
194
355
  },
195
356
  }
196
357
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bld
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - usiegl00
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-30 00:00:00.000000000 Z
11
+ date: 2024-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: public_suffix
@@ -120,6 +120,26 @@ dependencies:
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
122
  version: 2.5.2
123
+ - !ruby/object:Gem::Dependency
124
+ name: net-ssh
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '6.1'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 6.1.0
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '6.1'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 6.1.0
123
143
  description: CLI for build.io
124
144
  email: 50933431+usiegl00@users.noreply.github.com
125
145
  executables: