rockette 0.0.5 → 0.0.6

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: ee0d2270c8442e3e6b696cce15e9ac765a5d2c42e6a7ab84dc2c2a9b057d90e8
4
- data.tar.gz: 70d91cff0436629fe0cdcf50f7f5201047daee8a6504ef87a3ffc009c0143035
3
+ metadata.gz: 26e8d73d2c9b1c9a543b41dfd95dda73efea46e5bb14d444a5f50ada2af968ce
4
+ data.tar.gz: 44b7d193c2ad1ff6dcb9efad3ab7b5a70c87ba8942fb919aec5fa2302c4282b4
5
5
  SHA512:
6
- metadata.gz: 9c7afa7c6b7c0a4f39a4ebfa16ae70fa9b15e4a83e32930e30f2dbbae1aafa04850061de0b63e44f5023eb346e3ac42eaa68e56bd8d0a7db2b1b1cf3efc6b32f
7
- data.tar.gz: 0ac4932e7d0302bcdf9e3df9b9c8d6c4ce12a16e0831b8de9fe947a3850ca45633fa79cbdf1409ecd833bd76a42172beb6b681128d72177421eea068d4b8c418
6
+ metadata.gz: 0124ec971be8e538d810582967a512dc26efbaa2ed9e6e9f61fd9f1a954b40b2d3e6625e0b91aa813eac9902350cb3df2ce9f8c1f018edcc9aabdfaa87c73e43
7
+ data.tar.gz: aabc39c4210d4ec7dc7ca56cede861c433349fe395088657eba03744c3ced88ca91d7227ddba1488a48d238e87d1d92c05bda232a0d0907a057e7b90d61a193e
@@ -18,15 +18,15 @@ module Rockette
18
18
  identity_client = OCI::Identity::IdentityClient.new(config: OCI::Config.new, signer: signer)
19
19
  secret_client = OCI::Secrets::SecretsClient.new(config: OCI::Config.new, signer: signer)
20
20
  secret_response = secret_client.get_secret_bundle(secret_id).data.secret_bundle_content.content
21
- @conf = JSON.parse(Base64.decode64(secret_response))
21
+ @conf = Psych.load(Base64.decode64(secret_response))
22
22
  else
23
23
  @conf = Psych.load(File.read(CONF))
24
24
  end
25
25
  @body = @conf["token_body"]
26
26
  @hdrs = @conf["token_hdrs"]
27
+ @hdrs["Authorization"] = @conf["web_creds"][@options[:cred]] if @options[:cred]
27
28
  @token = get_token
28
29
  @hdrs["Authorization"] = "Bearer " + @token
29
- @hdrs["Content-Type"] = "application/sql"
30
30
  end
31
31
 
32
32
  def check_version(filey)
@@ -65,6 +65,7 @@ module Rockette
65
65
  if @options[:app_id] != '0' then
66
66
  abort padder("Error. Versions are identical, unable to deploy export") if check_version(filey)
67
67
  end
68
+ @hdrs["Content-Type"] = "application/sql"
68
69
  response = Rester.new(headers: @hdrs, meth: "Post", params: File.open(filey), url: push_url).rest_try
69
70
  bail unless response
70
71
  abort padder("Error. Got back response code: #{response.code}") unless (200..201).include? response.code
@@ -14,6 +14,7 @@ module Rockette
14
14
  @conf = Psych.load(File.read(CONF))
15
15
  @body = @conf["token_body"]
16
16
  @hdrs = @conf["token_hdrs"]
17
+ @hdrs["Authorization"] = @conf["web_creds"][@options[:cred]] if @options[:cred]
17
18
  @filey = "f#{@options[:app_id]}.sql"
18
19
  @token = get_token
19
20
  @hdrs["Authorization"] = "Bearer " + @token
@@ -47,6 +47,18 @@ module Rockette
47
47
  end
48
48
  end
49
49
 
50
+ def add_controller_cred
51
+ puts "Now that you have entered a controller url, please enter the OAuth client credentials for the controller."
52
+ user = @prompt.ask("User:")
53
+ pass = @prompt.ask("Pass:")
54
+ basey = 'Basic ' + Base64.encode64(user + ":" + pass).tr("\n", "")
55
+ @config.set(:rockette, :controller_cred, value: basey)
56
+ @config.write(force: true)
57
+ refresh_conf
58
+ puts "Choose View Resources and then All Applications to automate adding client credentials for each environment."
59
+ puts "You will need these credentials to use Rockette to deploy, export, and update applications."
60
+ end
61
+
50
62
  def add_url
51
63
  uri = @prompt.ask("Please enter APEX deployment URI (base path):") do |u|
52
64
  u.validate(%r{^https://\w+.\w+})
@@ -70,6 +82,7 @@ module Rockette
70
82
  response = @prompt.yes?("Would you like to enter a URI?")
71
83
  if response == true
72
84
  add_url
85
+ add_controller_cred
73
86
  else
74
87
  response = @prompt.yes?("Would you like to disable these checks in the future?")
75
88
  @config.set(:rockette, :check_for_url, value: false) if response == true
@@ -45,19 +45,20 @@ module Rockette
45
45
  def add_app
46
46
  puts padder("Let's choose an export to add")
47
47
  file = choose_file
48
- url = choose_env
48
+ env = choose_env
49
+ url = env[0]
49
50
  puts padder("You chose to add #{file} to the environment at #{url}")
50
51
  puts
51
52
  return unless @prompt.yes?("Proceed with the deployment?")
52
53
 
53
54
  options = Thor::CoreExt::HashWithIndifferentAccess.new "app_id" => "0", "url" => url, "file" => file,
54
- "force" => true
55
+ "cred" => env[1], "force" => true
55
56
  Rockette::Commands::Deploy.new(options).execute
56
57
  puts
57
58
  end
58
59
 
59
- def choose_app(apps_url)
60
- apps = Rockette::Viewer.new.applications(apps_url)
60
+ def choose_app(apps_url, cred)
61
+ apps = Rockette::Viewer.new.applications(apps_url, cred)
61
62
  list = list_builder(apps)
62
63
  action = @prompt.slider("Application to update => ", list, default: 1)
63
64
 
@@ -68,7 +69,7 @@ module Rockette
68
69
  enviros = Rockette::Viewer.new.environments
69
70
  list = list_builder(enviros)
70
71
  action = @prompt.select("Which environment?", list)
71
- enviros[action - 1]["deployment_api"]
72
+ [enviros[action - 1]["deployment_api"], enviros[action - 1]["web_cred"]]
72
73
  end
73
74
 
74
75
  def choose_file
@@ -90,15 +91,16 @@ module Rockette
90
91
  def updater
91
92
  puts padder("Please choose the export with your updated application code")
92
93
  file = choose_file
93
- url = choose_env
94
- app = choose_app(url)
94
+ env = choose_env
95
+ url = env[0]
96
+ app = choose_app(url, env[1])
95
97
  puts "Application: #{app["application_name"]} | App ID: #{app["application_id"]} | Env URI: #{url}"
96
98
  puts "will be updated with the code from export: #{file}"
97
99
  puts
98
100
  return unless @prompt.yes?("Proceed with the deployment?")
99
101
 
100
102
  options = Thor::CoreExt::HashWithIndifferentAccess.new "app_id" => app["application_id"], "url" => url,
101
- "file" => file, "force" => true
103
+ "cred" => env[1], "file" => file, "force" => true
102
104
  Rockette::Commands::Deploy.new(options).execute
103
105
  puts
104
106
  end
@@ -27,19 +27,20 @@ module Rockette
27
27
  break if action == list.length
28
28
 
29
29
  apps_url = enviros[action - 1]["deployment_api"]
30
- choose_app(apps_url)
30
+ cred = enviros[action - 1]["web_cred"]
31
+ choose_app(apps_url, cred)
31
32
  end
32
33
  end
33
34
 
34
- def do_export(app_id, apps_url)
35
+ def do_export(app_id, apps_url, cred)
35
36
  response = @prompt.yes?("Would you like to enter a filename for the export?")
36
37
  if response == true
37
38
  file = @prompt.ask("Please enter your desired filename:")
38
- options = Thor::CoreExt::HashWithIndifferentAccess.new "app_id" => app_id, "url" => apps_url, "file" => file,
39
- "force" => true
39
+ options = Thor::CoreExt::HashWithIndifferentAccess.new "app_id" => app_id, "url" => apps_url, "cred" => cred,
40
+ "file" => file, "force" => true
40
41
  else
41
42
  puts padder("Saving under default file name: f#{app_id}.sql")
42
- options = Thor::CoreExt::HashWithIndifferentAccess.new "app_id" => app_id, "url" => apps_url, "force" => true
43
+ options = Thor::CoreExt::HashWithIndifferentAccess.new "app_id" => app_id, "url" => apps_url, "cred" => cred, "force" => true
43
44
  end
44
45
  Rockette::Commands::Export.new(options).execute
45
46
  puts
@@ -47,15 +48,15 @@ module Rockette
47
48
 
48
49
  protected
49
50
 
50
- def choose_app(apps_url)
51
+ def choose_app(apps_url, cred)
51
52
  loop do
52
- apps = Rockette::Viewer.new.applications(apps_url)
53
+ apps = Rockette::Viewer.new.applications(apps_url, cred)
53
54
  list = list_builder(apps)
54
55
  action = @prompt.slider("Download application => ", list, default: 1)
55
56
  break if action == list.length
56
57
 
57
58
  app_id = apps[action - 1]["application_id"]
58
- do_export(app_id, apps_url)
59
+ do_export(app_id, apps_url, cred)
59
60
  end
60
61
  end
61
62
 
@@ -8,7 +8,16 @@ module Rockette
8
8
  include TextHelper
9
9
 
10
10
  def initialize
11
+ @config = TTY::Config.new
12
+ @config.append_path APP_PATH
13
+ @config.read
11
14
  @conf = Psych.load(File.read(CONF))
15
+ @body = @conf["token_body"]
16
+ @hdrs = @conf["token_hdrs"]
17
+ #@hdrs["Authorization"] = @conf["web_creds"]["controller_cred"]
18
+ token_url = @conf["rockette"]["controller_url"].sub!('deploy/', '')
19
+ @token = get_token(token_url, "controller_cred")
20
+ @hdrs["Authorization"] = "Bearer " + @token
12
21
  @pastel = Pastel.new
13
22
  @prompt = TTY::Prompt.new
14
23
  @spinner = TTY::Spinner.new # ("[:spinner] Loading APEX environments ...", format: pulse_2)
@@ -16,6 +25,10 @@ module Rockette
16
25
  "🌎 Applications by Environment" => 3, "⬅️ Go Back" => 4 }
17
26
  end
18
27
 
28
+ def self.config
29
+ @config ||= self.class.new.config
30
+ end
31
+
19
32
  def launch!
20
33
  puts padder("You can view environments or registered applications")
21
34
  puts
@@ -54,25 +67,49 @@ module Rockette
54
67
  end
55
68
  end
56
69
 
57
- def ape_e_i(uri)
58
- response = Rester.new(url: uri).rest_try
70
+ def add_web_cred(env_cred, env_name)
71
+ puts "You are attempting to access a resource that requires authentication."
72
+ puts "Please enter the OAuth client credentials for the #{env_name} environment."
73
+ user = @prompt.ask("User:")
74
+ pass = @prompt.ask("Pass:")
75
+ basey = 'Basic ' + Base64.encode64(user + ":" + pass).tr("\n", "")
76
+ @config.set(:web_creds, env_cred.to_sym, value: basey)
77
+ @config.write(force: true)
78
+ refresh_conf
79
+ end
80
+
81
+ def ape_e_i(uri, headers = @hdrs)
82
+ response = Rester.new(url: uri, headers: headers).rest_try
59
83
  bail unless response
60
84
  abort padder("#{uri} didn't work. Received: #{response.code}") unless response.code == 200
61
85
  response
62
86
  end
63
87
 
64
- def applications(url)
65
- uri = "#{url}deploy/apps"
66
- response = ape_e_i(uri)
88
+ def applications(url, cred)
89
+ headers = @hdrs
90
+ #@hdrs["Authorization"] = @conf["web_creds"][cred]
91
+ @token = get_token(url, cred)
92
+ @hdrs["Authorization"] = "Bearer " + @token
93
+ uri = "#{url}deploy/apps/"
94
+
95
+ response = ape_e_i(uri, @hdrs)
96
+ @hdrs = headers
67
97
  JSON.parse(response.body)["items"]
68
98
  end
69
99
 
70
100
  def environments
71
101
  uri = "#{@conf["rockette"]["controller_url"]}deploy/environments/"
72
102
  response = ape_e_i(uri)
73
- @table_env = TTY::Table.new(header: ["Environment Name", "API", "Domain", "Owner", "Workspace"])
103
+ @table_env = TTY::Table.new(header: ["Environment Name", "API", "Domain", "Owner", "Workspace", "Web Cred"])
74
104
  items = JSON.parse(response.body)["items"]
75
- items.each { |h| @table_env << [h["name"], h["deployment_api"], h["domain"], h["owner"], h["workspace"]] }
105
+ items.each { |h| @table_env << [h["name"], h["deployment_api"], h["domain"], h["owner"], h["workspace"], h["web_cred"]] }
106
+ end
107
+
108
+ def get_token(url, cred)
109
+ @hdrs["Authorization"] = @conf["web_creds"][cred]
110
+ token_url = url + "oauth/token"
111
+ response = Rester.new(headers: @hdrs, meth: "Post", params: @body, url: token_url).rest_try
112
+ return JSON.parse(response.body)["access_token"]
76
113
  end
77
114
 
78
115
  def registered
@@ -91,13 +128,22 @@ module Rockette
91
128
  @table_env.each do |env|
92
129
  next if env[0] == "Environment Name"
93
130
 
94
- apps = applications(env[1])
131
+ creds = Hash.new
132
+ creds = @conf["web_creds"]
133
+ add_web_cred(env[5], env[0]) unless creds.has_key?(env[5])
134
+
135
+ apps = applications(env[1], env[5])
95
136
  apps.each do |app|
96
137
  @table_all_apps << [env[0], app["application_name"], app["application_id"]]
97
138
  end
98
139
  end
99
140
  end
100
141
 
142
+ def refresh_conf
143
+ @config.read
144
+ @conf = Psych.load(File.read(CONF))
145
+ end
146
+
101
147
  def spinner(dur=1)
102
148
  @spinner.auto_spin
103
149
  sleep(dur)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rockette
4
- VERSION = "0.0.5"
4
+ VERSION = "0.0.6"
5
5
  end
@@ -5,4 +5,5 @@ token_hdrs:
5
5
  Content-Type: application/x-www-form-urlencoded
6
6
  rockette:
7
7
  check_for_url: true
8
+ controller_cred: ''
8
9
  controller_url: ''
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rockette
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kody Wilson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-29 00:00:00.000000000 Z
11
+ date: 2021-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry