bld 0.1.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 +7 -0
- data/bin/build +43 -0
- data/lib/commands.rb +155 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a5aff9af9ec4135ac11d00db562bfb3e0920828bd17c6b9352d6d6b9ec04d3b3
|
4
|
+
data.tar.gz: 280aa6249349b18a15749203437209b79fda9ec1020e76aaa7a11f3cde68be4a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d9de55950bafa3263f32ba601b6afbd29f170c44e68fbae81482ce22a45f77a5a3210419461faf53f40d29ec8b80ed219361ab06bd65fda886021a2f432ddc4e
|
7
|
+
data.tar.gz: a41dd5686bab750a094c724d4495bff1091cb515e3453374dcaf982be91b4641b0d8ac5e44425ea5929c28a397a4a47878ad5dc7d965de712df3f9c89a8082a3
|
data/bin/build
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'commander'
|
4
|
+
require 'cli/ui'
|
5
|
+
require 'launchy'
|
6
|
+
require 'netrc'
|
7
|
+
require 'httparty'
|
8
|
+
require_relative '../lib/commands'
|
9
|
+
|
10
|
+
ANTIMONY_HOST = "https://app.build.io"
|
11
|
+
|
12
|
+
CLI::UI::StdoutRouter.enable
|
13
|
+
Netrc.configure do |config|
|
14
|
+
config[:allow_permissive_netrc_file] = true
|
15
|
+
end
|
16
|
+
|
17
|
+
class BuildCLI
|
18
|
+
include Commander::Methods
|
19
|
+
|
20
|
+
def run
|
21
|
+
program :name, 'Build CLI'
|
22
|
+
program :version, '1.0.0'
|
23
|
+
program :description, "Build's Command Line Interface"
|
24
|
+
program :int_block, -> { exit }
|
25
|
+
|
26
|
+
BuildCLICommands.index.each do |name, entry|
|
27
|
+
command name.to_sym do |c|
|
28
|
+
c.syntax = entry[:cli_details][:syntax]
|
29
|
+
c.description = entry[:cli_details][:description]
|
30
|
+
entry[:cli_details][:options].each do |values|
|
31
|
+
c.option *values
|
32
|
+
end
|
33
|
+
c.action do |args, options|
|
34
|
+
entry[:cli_perform].call(args, options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
run!
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
BuildCLI.new.run
|
data/lib/commands.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
# NOTE: This file is generated
|
2
|
+
class BuildCLICommands
|
3
|
+
def self.index
|
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"]] },
|
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
|
+
|
14
|
+
app_name = options.app
|
15
|
+
if app_name.nil?
|
16
|
+
puts CLI::UI.fmt "{{red:›}} Error: no app name specified"
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
|
20
|
+
query_params = {}
|
21
|
+
query_params[:app] = app_name
|
22
|
+
query_params[:team] = options.team if options.team
|
23
|
+
query_params[:region] = options.region if options.region
|
24
|
+
query_params[:stack] = options.stack if options.stack
|
25
|
+
|
26
|
+
query_string = URI.encode_www_form(query_params)
|
27
|
+
|
28
|
+
res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/apps/create?#{query_string}",
|
29
|
+
headers: { "Authorization" => auth })
|
30
|
+
if res.code != 200
|
31
|
+
puts CLI::UI.fmt "{{red:›}} Error: not authorized to create app (#{app_name})"
|
32
|
+
exit 1
|
33
|
+
end
|
34
|
+
app_name = JSON.parse(res.body)["name"]
|
35
|
+
puts "https://#{app_name}.#{region}.antimony.io | #{app_name}"
|
36
|
+
rescue
|
37
|
+
puts CLI::UI.fmt "{{red:›}} Error: not logged in"
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
},
|
41
|
+
},
|
42
|
+
"login": {
|
43
|
+
cli_details: { :syntax => "build login", :description => "Login to your Build account", :options => [] },
|
44
|
+
cli_perform: Proc.new { |args, options|
|
45
|
+
input = CLI::UI.any_key('Press any key to open up the browser to login or q to exit')
|
46
|
+
exit if input.downcase == "q"
|
47
|
+
|
48
|
+
user_token, user_email = nil
|
49
|
+
CLI::UI::Spinner.spin("Waiting for login") do |spinner|
|
50
|
+
client_secret = SecureRandom.uuid
|
51
|
+
|
52
|
+
oauth_url = "#{ANTIMONY_HOST}/cli_auth/authorize/#{client_secret}"
|
53
|
+
Launchy.open(oauth_url)
|
54
|
+
|
55
|
+
poll_interval = 1
|
56
|
+
timeout = (5 * 60)
|
57
|
+
start_time = Time.now
|
58
|
+
loop do
|
59
|
+
response = HTTParty.get("#{ANTIMONY_HOST}/api/cli_auth/resolve/#{client_secret}")
|
60
|
+
if response.code == 200 && response['code'] == 'unresolved'
|
61
|
+
sleep(poll_interval)
|
62
|
+
elsif response.code == 200 && response['code'] == 'resolved'
|
63
|
+
user_token = response["token"]
|
64
|
+
user_email = response["email"]
|
65
|
+
break
|
66
|
+
else
|
67
|
+
raise "Error: #{response.code}"
|
68
|
+
end
|
69
|
+
break if Time.now - start_time > timeout
|
70
|
+
end
|
71
|
+
|
72
|
+
user_netrc = Netrc.read
|
73
|
+
user_netrc["build.io"] = "#{user_email}", "#{user_token}"
|
74
|
+
user_netrc.save
|
75
|
+
end
|
76
|
+
|
77
|
+
puts CLI::UI.fmt "Logged in as {{green:#{user_email}}}"
|
78
|
+
},
|
79
|
+
},
|
80
|
+
"logs": {
|
81
|
+
cli_details: { :syntax => "build logs -t -a <app>", :description => "Display recent log output",
|
82
|
+
:options => [["-a", "--app=<value>", String, "(required) app to run command against"], ["-t", "--tail", TrueClass, "continually stream logs"], ["-n", "--num=<value>", String, "number of lines to show"], ["-p", "--process=<value>", String, "show only logs for a specific Procfile process"], ["-s", "--source=<value>", String, "show only logs from a specific source (such as app or build)"]] },
|
83
|
+
cli_perform: Proc.new { |args, options|
|
84
|
+
app_name = options.app
|
85
|
+
if app_name.nil? || app_name.strip == ""
|
86
|
+
puts CLI::UI.fmt "{{red:›}} Error: The following error occurred:"
|
87
|
+
puts CLI::UI.fmt "{{red:›}} {{gray:Missing required flag app}}"
|
88
|
+
puts CLI::UI.fmt "{{red:›}} See more help with --help"
|
89
|
+
exit 1
|
90
|
+
end
|
91
|
+
|
92
|
+
begin
|
93
|
+
user_netrc = Netrc.read
|
94
|
+
user_token = user_netrc["build.io"][1]
|
95
|
+
auth = "Bearer #{user_token}"
|
96
|
+
rescue
|
97
|
+
puts CLI::UI.fmt "{{red:›}} Error: not logged in"
|
98
|
+
exit 1
|
99
|
+
end
|
100
|
+
|
101
|
+
query_params = {}
|
102
|
+
query_params[:num] = options.num if options.num
|
103
|
+
query_params[:process] = options.process if options.process
|
104
|
+
query_params[:source] = options.source if options.source
|
105
|
+
query_params[:tail] = options.trace if options.trace
|
106
|
+
query_params[:tail] = options.tail if options.tail
|
107
|
+
|
108
|
+
query_string = URI.encode_www_form(query_params)
|
109
|
+
|
110
|
+
res = HTTParty.get("#{ANTIMONY_HOST}/api/apps/#{app_name}/logs/log_url?#{query_string}",
|
111
|
+
headers: { "Authorization" => auth })
|
112
|
+
if res.code != 200
|
113
|
+
puts CLI::UI.fmt "{{red:›}} Error: Couldn't find that app."
|
114
|
+
puts CLI::UI.fmt "{{red:›}}"
|
115
|
+
puts CLI::UI.fmt "{{red:›}} Error ID: not_found"
|
116
|
+
exit 1
|
117
|
+
end
|
118
|
+
log_url = res["url"]
|
119
|
+
|
120
|
+
res = HTTParty.get(log_url, timeout: 1_000_000) do |fragment|
|
121
|
+
puts fragment unless fragment.empty?
|
122
|
+
end
|
123
|
+
if res.code != 200
|
124
|
+
puts CLI::UI.fmt "{{red:›}} Error: Connection to logs failed."
|
125
|
+
puts CLI::UI.fmt "{{red:›}}"
|
126
|
+
puts CLI::UI.fmt "{{red:›}} Error ID: connection_failed"
|
127
|
+
exit 1
|
128
|
+
end
|
129
|
+
},
|
130
|
+
},
|
131
|
+
"whoami": {
|
132
|
+
cli_details: { :syntax => "build whoami", :description => "Display the current logged in user",
|
133
|
+
:options => [] },
|
134
|
+
cli_perform: Proc.new { |args, options|
|
135
|
+
begin
|
136
|
+
user_netrc = Netrc.read
|
137
|
+
user_token = user_netrc["build.io"][1]
|
138
|
+
auth = "Bearer #{user_token}"
|
139
|
+
|
140
|
+
res = HTTParty.get("#{ANTIMONY_HOST}/api/cli/command/whoami",
|
141
|
+
headers: { "Authorization" => auth })
|
142
|
+
if res.code != 200
|
143
|
+
puts CLI::UI.fmt "{{red:›}} Error: not logged in"
|
144
|
+
exit 1
|
145
|
+
end
|
146
|
+
puts JSON.parse(res.body)["email"]
|
147
|
+
rescue
|
148
|
+
puts CLI::UI.fmt "{{red:›}} Error: not logged in"
|
149
|
+
exit 1
|
150
|
+
end
|
151
|
+
},
|
152
|
+
}
|
153
|
+
}
|
154
|
+
end
|
155
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bld
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- usiegl00
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-01-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.21.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.21.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: netrc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.11.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.11.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: commander
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cli-ui
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.2'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 2.2.3
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '2.2'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 2.2.3
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: launchy
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '2.5'
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 2.5.2
|
85
|
+
type: :runtime
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '2.5'
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 2.5.2
|
95
|
+
description: Build.io cli
|
96
|
+
email: 50933431+usiegl00@users.noreply.github.com
|
97
|
+
executables:
|
98
|
+
- build
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- bin/build
|
103
|
+
- lib/commands.rb
|
104
|
+
homepage: https://build.io
|
105
|
+
licenses:
|
106
|
+
- ''
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 3.0.0
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubygems_version: 3.4.6
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Build.io cli
|
127
|
+
test_files: []
|