bld 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bld +1 -1
  3. data/bin/build +1 -1
  4. data/lib/commands.rb +50 -24
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95db01fc1f8b814390cb002e44ac52022eb1473396b4872d38919ddbcbda0275
4
- data.tar.gz: 34c4968f97710e37f51ab1d01936c571c16e5b2033840e6c1d380d7eaa07dd25
3
+ metadata.gz: 0c960f6dd300e86772b724b30cc9c871e463e2a90126f81c11002be45a267551
4
+ data.tar.gz: ed13da023c4c920edbb9ea4df7ecab26d1fac2fb12f9483d1b1b3262666f9807
5
5
  SHA512:
6
- metadata.gz: c379f62a27575b6ca56a51c529cdf8df066588eecae843628c4bd929f550e24b44b28f0dbaf04adadda140a9610f12d307b249c4d94b3cf844f8ff4b3775507d
7
- data.tar.gz: e1d3d504f2af8525a8bb2a0d1b983211fe2d0abba7f55d64b58596c4e55833bd96afb005aa4dc741ee8c404c413848de2c9a5bb5918676f7d957a3b185a6a212
6
+ metadata.gz: 1d7ec6e425b8851d51ecff706277d47892d2df5188411e7920e75cbe2ad3dfbe4cdd4907578302835e45c82f11c72b1da5f854fb68ea65a09413d1205d3a2e24
7
+ data.tar.gz: 7f47e83c9a815ceb768e1178045ef9fe07168dfa3ba917f47292054dfc03909846e8e9377f570ce7a3ed63575d5a2604837eba64bed00ab4fa69ecaf22f7908a
data/bin/bld CHANGED
@@ -20,7 +20,7 @@ class BuildCLI
20
20
 
21
21
  def run
22
22
  program :name, 'Build CLI'
23
- program :version, '0.1.11'
23
+ program :version, '0.1.12'
24
24
  program :description, "Build's Command Line Interface"
25
25
  program :int_block, -> { exit }
26
26
  default_command :help
data/bin/build CHANGED
@@ -20,7 +20,7 @@ class BuildCLI
20
20
 
21
21
  def run
22
22
  program :name, 'Build CLI'
23
- program :version, '0.1.11'
23
+ program :version, '0.1.12'
24
24
  program :description, "Build's Command Line Interface"
25
25
  program :int_block, -> { exit }
26
26
  default_command :help
data/lib/commands.rb CHANGED
@@ -13,8 +13,7 @@ class BuildCLICommands
13
13
  puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
14
14
  exit(1)
15
15
  end
16
- user_netrc = Netrc.read
17
- user_token = user_netrc.[]("build.io")&.password
16
+ user_token = ENV.[]("BUILD_API_KEY") || Netrc.read.[]("build.io")&.password
18
17
  if user_token.nil?
19
18
  puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
20
19
  exit(1)
@@ -91,8 +90,7 @@ class BuildCLICommands
91
90
  exit(1)
92
91
  end
93
92
  process = args.first
94
- user_netrc = Netrc.read
95
- user_token = user_netrc.[]("build.io")&.password
93
+ user_token = ENV.[]("BUILD_API_KEY") || Netrc.read.[]("build.io")&.password
96
94
  if user_token.nil?
97
95
  puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
98
96
  exit(1)
@@ -132,8 +130,7 @@ class BuildCLICommands
132
130
  puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
133
131
  exit(1)
134
132
  end
135
- user_netrc = Netrc.read
136
- user_token = user_netrc.[]("build.io")&.password
133
+ user_token = ENV.[]("BUILD_API_KEY") || Netrc.read.[]("build.io")&.password
137
134
  if user_token.nil?
138
135
  puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
139
136
  exit(1)
@@ -175,8 +172,7 @@ class BuildCLICommands
175
172
  puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
176
173
  exit(1)
177
174
  end
178
- user_netrc = Netrc.read
179
- user_token = user_netrc.[]("build.io")&.password
175
+ user_token = ENV.[]("BUILD_API_KEY") || Netrc.read.[]("build.io")&.password
180
176
  if user_token.nil?
181
177
  puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
182
178
  exit(1)
@@ -219,8 +215,7 @@ class BuildCLICommands
219
215
  puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
220
216
  exit(1)
221
217
  end
222
- user_netrc = Netrc.read
223
- user_token = user_netrc.[]("build.io")&.password
218
+ user_token = ENV.[]("BUILD_API_KEY") || Netrc.read.[]("build.io")&.password
224
219
  if user_token.nil?
225
220
  puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
226
221
  exit(1)
@@ -261,8 +256,7 @@ class BuildCLICommands
261
256
  puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
262
257
  exit(1)
263
258
  end
264
- user_netrc = Netrc.read
265
- user_token = user_netrc.[]("build.io")&.password
259
+ user_token = ENV.[]("BUILD_API_KEY") || Netrc.read.[]("build.io")&.password
266
260
  if user_token.nil?
267
261
  puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
268
262
  exit(1)
@@ -289,8 +283,7 @@ class BuildCLICommands
289
283
  cli_details: { :syntax => "apps:create [options] -a <app>", :description => "Create a new app",
290
284
  :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"]] },
291
285
  cli_perform: Proc.new { |args, options|
292
- user_netrc = Netrc.read
293
- user_token = user_netrc.[]("build.io")&.password
286
+ user_token = ENV.[]("BUILD_API_KEY") || Netrc.read.[]("build.io")&.password
294
287
  if user_token.nil?
295
288
  puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
296
289
  exit(1)
@@ -315,11 +308,12 @@ class BuildCLICommands
315
308
  query_string = URI.encode_www_form(query_params)
316
309
  res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/apps/create?#{query_string}",
317
310
  { headers: { "Authorization" => auth } })
318
- if res.code != 200
319
- puts(CLI::UI.fmt("{{red:›}} Error: not authorized to create app (#{app_name})"))
311
+ if !res.success?
312
+ puts(CLI::UI.fmt("{{red:›}} Error: #{res.body}"))
320
313
  exit(1)
321
314
  end
322
315
  app_name = JSON.parse(res.body).[]("name")
316
+ region = options.region || "us-east-1"
323
317
  puts("https://#{app_name}.#{region}.antimony.io | #{app_name}")
324
318
  },
325
319
  },
@@ -378,8 +372,7 @@ class BuildCLICommands
378
372
  puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
379
373
  exit(1)
380
374
  end
381
- user_netrc = Netrc.read
382
- user_token = user_netrc.[]("build.io")&.password
375
+ user_token = ENV.[]("BUILD_API_KEY") || Netrc.read.[]("build.io")&.password
383
376
  if user_token.nil?
384
377
  puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
385
378
  exit(1)
@@ -430,8 +423,7 @@ class BuildCLICommands
430
423
  cli_details: { :syntax => "build whoami", :description => "Display the current logged in user",
431
424
  :options => [] },
432
425
  cli_perform: Proc.new { |args, options|
433
- user_netrc = Netrc.read
434
- user_token = user_netrc.[]("build.io")&.password
426
+ user_token = ENV.[]("BUILD_API_KEY") || Netrc.read.[]("build.io")&.password
435
427
  if user_token.nil?
436
428
  puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
437
429
  exit(1)
@@ -454,8 +446,7 @@ class BuildCLICommands
454
446
  puts(CLI::UI.fmt("{{red:›}} Error: no command provided"))
455
447
  exit(1)
456
448
  end
457
- user_netrc = Netrc.read
458
- user_token = user_netrc.[]("build.io")&.password
449
+ user_token = ENV.[]("BUILD_API_KEY") || Netrc.read.[]("build.io")&.password
459
450
  if user_token.nil?
460
451
  puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
461
452
  exit(1)
@@ -477,10 +468,45 @@ class BuildCLICommands
477
468
  exit(1)
478
469
  end
479
470
  ruby = JSON.parse(res.body).[]("ruby")
480
- require("shellwords")
481
- command = "/cnb/lifecycle/launcher #{Shellwords.join(args)}"
482
471
  eval(ruby)
483
472
  },
473
+ },
474
+ "oidc-login": {
475
+ cli_details: { :syntax => "build oidc-login", :description => "Login to your Build cluster",
476
+ :options => [["-r", "--region REGION", String, "(required) The region of the cluster to access"]] },
477
+ cli_perform: Proc.new { |args, options|
478
+ region = options.region
479
+ if region.nil? || region.strip == ""
480
+ puts(CLI::UI.fmt("{{red:›}} Error: The following error occurred:"))
481
+ puts(CLI::UI.fmt("{{red:›}} {{gray:Missing required flag region}}"))
482
+ puts(CLI::UI.fmt("{{red:›}} See more help with --help"))
483
+ exit(1)
484
+ end
485
+ user_token = ENV.[]("BUILD_API_KEY")
486
+ if user_token.nil?
487
+ user_netrc = Netrc.read
488
+ user_token = user_netrc.[]("build.io")&.password
489
+ end
490
+ if user_token.nil?
491
+ puts(CLI::UI.fmt("{{red:›}} Error: not logged in"))
492
+ exit(1)
493
+ end
494
+ auth = "Bearer #{user_token}"
495
+ query_params = {}
496
+ query_params.[]=(:region, region)
497
+ query_string = URI.encode_www_form(query_params)
498
+ res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/oidc-login?#{query_string}",
499
+ { headers: { "Authorization" => auth } })
500
+ if res.code != 200
501
+ if res.body && res.body != "" && JSON.parse(res.body)&.key?("error")
502
+ puts(CLI::UI.fmt("{{red:›}} Error: #{JSON.parse(res.body).[]("error")}"))
503
+ else
504
+ puts(CLI::UI.fmt("{{red:›}} Error: An unknown error occurred"))
505
+ end
506
+ exit(1)
507
+ end
508
+ puts(res.body)
509
+ },
484
510
  }
485
511
  }
486
512
  end
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.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - usiegl00
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-14 00:00:00.000000000 Z
11
+ date: 2024-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: abbrev