uffizzi-cli 0.5.0 → 0.6.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/README.md +61 -115
- data/config/uffizzi.rb +2 -1
- data/lib/uffizzi/auth_helper.rb +5 -6
- data/lib/uffizzi/cli/common.rb +1 -1
- data/lib/uffizzi/cli/config.rb +40 -8
- data/lib/uffizzi/cli/connect.rb +8 -8
- data/lib/uffizzi/cli/disconnect.rb +1 -1
- data/lib/uffizzi/cli/login.rb +29 -10
- data/lib/uffizzi/cli/logout.rb +2 -2
- data/lib/uffizzi/cli/preview/service.rb +6 -6
- data/lib/uffizzi/cli/preview.rb +11 -11
- data/lib/uffizzi/cli/project/compose.rb +12 -14
- data/lib/uffizzi/cli/project/secret.rb +6 -6
- data/lib/uffizzi/cli/project.rb +2 -2
- data/lib/uffizzi/cli.rb +8 -3
- data/lib/uffizzi/clients/api/api_client.rb +44 -42
- data/lib/uffizzi/clients/api/api_routes.rb +30 -30
- data/lib/uffizzi/clients/api/http_client.rb +2 -4
- data/lib/uffizzi/config_file.rb +36 -20
- data/lib/uffizzi/shell.rb +13 -4
- data/lib/uffizzi/version.rb +1 -1
- data/lib/uffizzi.rb +4 -0
- data/man/uffizzi-config +65 -0
- data/man/uffizzi-config.html +144 -0
- data/man/uffizzi-config.ronn +55 -0
- data/man/uffizzi-login +1 -1
- data/man/uffizzi-login.ronn +1 -1
- metadata +19 -2
data/lib/uffizzi/cli/preview.rb
CHANGED
@@ -48,7 +48,7 @@ module Uffizzi
|
|
48
48
|
Uffizzi.ui.disable_stdout
|
49
49
|
end
|
50
50
|
raise Uffizzi::Error.new('You are not logged in.') unless Uffizzi::AuthHelper.signed_in?
|
51
|
-
raise Uffizzi::Error.new('This command needs project to be set in config file') unless Uffizzi::AuthHelper.project_set?
|
51
|
+
raise Uffizzi::Error.new('This command needs project to be set in config file') unless Uffizzi::AuthHelper.project_set?(options)
|
52
52
|
|
53
53
|
project_slug = options[:project].nil? ? ConfigFile.read_option(:project) : options[:project]
|
54
54
|
|
@@ -67,7 +67,7 @@ module Uffizzi
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def handle_list_command(project_slug)
|
70
|
-
response = fetch_deployments(ConfigFile.read_option(:
|
70
|
+
response = fetch_deployments(ConfigFile.read_option(:server), project_slug)
|
71
71
|
|
72
72
|
if ResponseHelper.ok?(response)
|
73
73
|
handle_succeed_list_response(response)
|
@@ -78,7 +78,7 @@ module Uffizzi
|
|
78
78
|
|
79
79
|
def handle_create_command(file_path, project_slug)
|
80
80
|
params = file_path.nil? ? {} : prepare_params(file_path)
|
81
|
-
response = create_deployment(ConfigFile.read_option(:
|
81
|
+
response = create_deployment(ConfigFile.read_option(:server), project_slug, params)
|
82
82
|
|
83
83
|
if ResponseHelper.created?(response)
|
84
84
|
handle_succeed_create_response(project_slug, response)
|
@@ -92,7 +92,7 @@ module Uffizzi
|
|
92
92
|
|
93
93
|
return Uffizzi.ui.say("Preview should be specified in 'deployment-PREVIEW_ID' format") if deployment_id.nil?
|
94
94
|
|
95
|
-
response = fetch_events(ConfigFile.read_option(:
|
95
|
+
response = fetch_events(ConfigFile.read_option(:server), project_slug, deployment_id)
|
96
96
|
|
97
97
|
if ResponseHelper.ok?(response)
|
98
98
|
handle_succeed_events_response(response)
|
@@ -102,7 +102,7 @@ module Uffizzi
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def handle_succeed_events_response(response)
|
105
|
-
Uffizzi.ui.
|
105
|
+
Uffizzi.ui.pretty_say(response[:body][:events])
|
106
106
|
end
|
107
107
|
|
108
108
|
def handle_succeed_create_response(project_slug, response)
|
@@ -110,7 +110,7 @@ module Uffizzi
|
|
110
110
|
deployment_id = deployment[:id]
|
111
111
|
params = { id: deployment_id }
|
112
112
|
|
113
|
-
response = deploy_containers(ConfigFile.read_option(:
|
113
|
+
response = deploy_containers(ConfigFile.read_option(:server), project_slug, deployment_id, params)
|
114
114
|
|
115
115
|
if ResponseHelper.no_content?(response)
|
116
116
|
Uffizzi.ui.say("Preview created with name deployment-#{deployment_id}")
|
@@ -129,12 +129,12 @@ module Uffizzi
|
|
129
129
|
activity_items = []
|
130
130
|
|
131
131
|
loop do
|
132
|
-
response = get_activity_items(ConfigFile.read_option(:
|
132
|
+
response = get_activity_items(ConfigFile.read_option(:server), project_slug, deployment_id)
|
133
133
|
handle_activity_items_response(response)
|
134
134
|
return unless @spinner.spinning?
|
135
135
|
|
136
136
|
activity_items = response[:body][:activity_items]
|
137
|
-
break
|
137
|
+
break if !activity_items.empty? && activity_items.count == deployment[:containers].count
|
138
138
|
|
139
139
|
sleep(5)
|
140
140
|
end
|
@@ -164,7 +164,7 @@ module Uffizzi
|
|
164
164
|
|
165
165
|
def wait_containers_deploying(project_slug, deployment_id, containers_spinners)
|
166
166
|
loop do
|
167
|
-
response = get_activity_items(ConfigFile.read_option(:
|
167
|
+
response = get_activity_items(ConfigFile.read_option(:server), project_slug, deployment_id)
|
168
168
|
handle_activity_items_response(response)
|
169
169
|
return if @spinner.done?
|
170
170
|
|
@@ -208,7 +208,7 @@ module Uffizzi
|
|
208
208
|
|
209
209
|
return Uffizzi.ui.say("Preview should be specified in 'deployment-PREVIEW_ID' format") if deployment_id.nil?
|
210
210
|
|
211
|
-
response = delete_deployment(ConfigFile.read_option(:
|
211
|
+
response = delete_deployment(ConfigFile.read_option(:server), project_slug, deployment_id)
|
212
212
|
|
213
213
|
if ResponseHelper.no_content?(response)
|
214
214
|
handle_succeed_delete_response(deployment_id)
|
@@ -222,7 +222,7 @@ module Uffizzi
|
|
222
222
|
|
223
223
|
return Uffizzi.ui.say("Preview should be specified in 'deployment-PREVIEW_ID' format") if deployment_id.nil?
|
224
224
|
|
225
|
-
response = describe_deployment(ConfigFile.read_option(:
|
225
|
+
response = describe_deployment(ConfigFile.read_option(:server), project_slug, deployment_id)
|
226
226
|
|
227
227
|
if ResponseHelper.ok?(response)
|
228
228
|
handle_succeed_describe_response(response)
|
@@ -12,25 +12,27 @@ module Uffizzi
|
|
12
12
|
|
13
13
|
desc 'set [OPTIONS]', 'set'
|
14
14
|
def set
|
15
|
-
run(
|
15
|
+
run('set')
|
16
16
|
end
|
17
17
|
|
18
18
|
desc 'unset', 'unset'
|
19
19
|
def unset
|
20
|
-
run(
|
20
|
+
run('unset')
|
21
21
|
end
|
22
22
|
|
23
23
|
desc 'describe', 'describe'
|
24
24
|
def describe
|
25
|
-
run(
|
25
|
+
run('describe')
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
def run(
|
30
|
+
def run(command)
|
31
31
|
return Uffizzi.ui.say('You are not logged in.') unless Uffizzi::AuthHelper.signed_in?
|
32
|
-
return Uffizzi.ui.say('This command needs project to be set in config file') unless Uffizzi::AuthHelper.project_set?
|
32
|
+
return Uffizzi.ui.say('This command needs project to be set in config file') unless Uffizzi::AuthHelper.project_set?(options)
|
33
33
|
|
34
|
+
@project_slug = options[:project].nil? ? ConfigFile.read_option(:project) : options[:project]
|
35
|
+
@server = ConfigFile.read_option(:server)
|
34
36
|
file_path = options[:file]
|
35
37
|
case command
|
36
38
|
when 'set'
|
@@ -39,18 +41,14 @@ module Uffizzi
|
|
39
41
|
handle_unset_command
|
40
42
|
when 'describe'
|
41
43
|
handle_describe_command
|
42
|
-
when 'validate'
|
43
|
-
handle_validate_command(file_path)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
def handle_set_command(file_path)
|
48
48
|
return Uffizzi.ui.say('No file provided') if file_path.nil?
|
49
49
|
|
50
|
-
hostname = ConfigFile.read_option(:hostname)
|
51
|
-
project_slug = ConfigFile.read_option(:project)
|
52
50
|
params = prepare_params(file_path)
|
53
|
-
response = set_compose_file(
|
51
|
+
response = set_compose_file(@server, params, @project_slug)
|
54
52
|
|
55
53
|
if ResponseHelper.created?(response)
|
56
54
|
Uffizzi.ui.say('compose file created')
|
@@ -60,9 +58,9 @@ module Uffizzi
|
|
60
58
|
end
|
61
59
|
|
62
60
|
def handle_unset_command
|
63
|
-
|
61
|
+
server = ConfigFile.read_option(:server)
|
64
62
|
project_slug = ConfigFile.read_option(:project)
|
65
|
-
response = unset_compose_file(
|
63
|
+
response = unset_compose_file(server, project_slug)
|
66
64
|
|
67
65
|
if ResponseHelper.no_content?(response)
|
68
66
|
Uffizzi.ui.say('compose file deleted')
|
@@ -72,9 +70,9 @@ module Uffizzi
|
|
72
70
|
end
|
73
71
|
|
74
72
|
def handle_describe_command
|
75
|
-
|
73
|
+
server = ConfigFile.read_option(:server)
|
76
74
|
project_slug = ConfigFile.read_option(:project)
|
77
|
-
response = describe_compose_file(
|
75
|
+
response = describe_compose_file(server, project_slug)
|
78
76
|
compose_file = response[:body][:compose_file]
|
79
77
|
|
80
78
|
if ResponseHelper.ok?(response)
|
@@ -48,8 +48,8 @@ module Uffizzi
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def handle_list_command(project_slug)
|
51
|
-
|
52
|
-
response = fetch_secrets(
|
51
|
+
server = ConfigFile.read_option(:server)
|
52
|
+
response = fetch_secrets(server, project_slug)
|
53
53
|
secrets = response[:body][:secrets].map { |secret| [secret[:name]] }
|
54
54
|
return Uffizzi.ui.say('There are no secrets for the project') if secrets.empty?
|
55
55
|
|
@@ -61,20 +61,20 @@ module Uffizzi
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def handle_create_command(project_slug, id)
|
64
|
-
|
64
|
+
server = ConfigFile.read_option(:server)
|
65
65
|
secret_value = $stdin.read
|
66
66
|
return Uffizzi.ui.say('Please provide the secret value') if secret_value.nil?
|
67
67
|
|
68
68
|
params = { secrets: [{ name: id, value: secret_value }] }
|
69
|
-
response = bulk_create_secrets(
|
69
|
+
response = bulk_create_secrets(server, project_slug, params)
|
70
70
|
return Uffizzi.ui.say('The secret was successfully created') if ResponseHelper.created?(response)
|
71
71
|
|
72
72
|
ResponseHelper.handle_failed_response(response)
|
73
73
|
end
|
74
74
|
|
75
75
|
def handle_delete_command(project_slug, id)
|
76
|
-
|
77
|
-
response = delete_secret(
|
76
|
+
server = ConfigFile.read_option(:server)
|
77
|
+
response = delete_secret(server, project_slug, id)
|
78
78
|
|
79
79
|
if ResponseHelper.no_content?(response)
|
80
80
|
Uffizzi.ui.say('The secret was successfully deleted')
|
data/lib/uffizzi/cli/project.rb
CHANGED
@@ -34,8 +34,8 @@ module Uffizzi
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def handle_list_command
|
37
|
-
|
38
|
-
response = fetch_projects(
|
37
|
+
server = ConfigFile.read_option(:server)
|
38
|
+
response = fetch_projects(server)
|
39
39
|
|
40
40
|
if ResponseHelper.ok?(response)
|
41
41
|
handle_succeed_response(response)
|
data/lib/uffizzi/cli.rb
CHANGED
@@ -4,19 +4,24 @@ require 'uffizzi'
|
|
4
4
|
|
5
5
|
module Uffizzi
|
6
6
|
class CLI < Thor
|
7
|
+
require_relative 'cli/common'
|
8
|
+
|
9
|
+
class_option :help, type: :boolean, aliases: HELP_MAPPINGS
|
10
|
+
class_option :project, type: :string
|
11
|
+
|
7
12
|
def self.exit_on_failure?
|
8
13
|
true
|
9
14
|
end
|
10
15
|
|
11
|
-
desc 'version', '
|
16
|
+
desc 'version', 'Show Version'
|
12
17
|
def version
|
13
18
|
require_relative 'version'
|
14
19
|
Uffizzi.ui.say(Uffizzi::VERSION)
|
15
20
|
end
|
16
21
|
|
17
22
|
desc 'login [OPTIONS]', 'Login into Uffizzi'
|
18
|
-
method_option :
|
19
|
-
method_option :
|
23
|
+
method_option :server, required: false, aliases: '-s'
|
24
|
+
method_option :username, required: false, aliases: '-u'
|
20
25
|
def login
|
21
26
|
require_relative 'cli/login'
|
22
27
|
Login.new(options).run
|
@@ -6,148 +6,148 @@ require_relative 'http_client'
|
|
6
6
|
module ApiClient
|
7
7
|
include ApiRoutes
|
8
8
|
|
9
|
-
def create_session(
|
10
|
-
uri = session_uri(
|
9
|
+
def create_session(server, params = {})
|
10
|
+
uri = session_uri(server)
|
11
11
|
response = Uffizzi::HttpClient.make_post_request(uri, params, false)
|
12
12
|
|
13
13
|
build_response(response)
|
14
14
|
end
|
15
15
|
|
16
|
-
def destroy_session(
|
17
|
-
uri = session_uri(
|
16
|
+
def destroy_session(server)
|
17
|
+
uri = session_uri(server)
|
18
18
|
response = Uffizzi::HttpClient.make_delete_request(uri)
|
19
19
|
|
20
20
|
build_response(response)
|
21
21
|
end
|
22
22
|
|
23
|
-
def fetch_projects(
|
24
|
-
uri = projects_uri(
|
23
|
+
def fetch_projects(server)
|
24
|
+
uri = projects_uri(server)
|
25
25
|
response = Uffizzi::HttpClient.make_get_request(uri)
|
26
26
|
|
27
27
|
build_response(response)
|
28
28
|
end
|
29
29
|
|
30
|
-
def create_credential(
|
31
|
-
uri = credentials_uri(
|
30
|
+
def create_credential(server, params)
|
31
|
+
uri = credentials_uri(server)
|
32
32
|
response = Uffizzi::HttpClient.make_post_request(uri, params)
|
33
33
|
|
34
34
|
build_response(response)
|
35
35
|
end
|
36
36
|
|
37
|
-
def fetch_deployment_services(
|
38
|
-
uri = preview_services_uri(
|
37
|
+
def fetch_deployment_services(server, project_slug, deployment_id)
|
38
|
+
uri = preview_services_uri(server, project_slug, deployment_id)
|
39
39
|
response = Uffizzi::HttpClient.make_get_request(uri)
|
40
40
|
|
41
41
|
build_response(response)
|
42
42
|
end
|
43
43
|
|
44
|
-
def delete_credential(
|
45
|
-
uri = delete_credential_uri(
|
44
|
+
def delete_credential(server, credential_type)
|
45
|
+
uri = delete_credential_uri(server, credential_type)
|
46
46
|
response = Uffizzi::HttpClient.make_delete_request(uri)
|
47
47
|
|
48
48
|
build_response(response)
|
49
49
|
end
|
50
50
|
|
51
|
-
def fetch_deployment_service_logs(
|
52
|
-
uri = preview_service_logs_uri(
|
51
|
+
def fetch_deployment_service_logs(server, project_slug, deployment_id, container_name)
|
52
|
+
uri = preview_service_logs_uri(server, project_slug, deployment_id, container_name)
|
53
53
|
response = Uffizzi::HttpClient.make_get_request(uri)
|
54
54
|
|
55
55
|
build_response(response)
|
56
56
|
end
|
57
57
|
|
58
|
-
def set_compose_file(
|
59
|
-
uri = compose_file_uri(
|
58
|
+
def set_compose_file(server, params, project_slug)
|
59
|
+
uri = compose_file_uri(server, project_slug)
|
60
60
|
response = Uffizzi::HttpClient.make_post_request(uri, params)
|
61
61
|
|
62
62
|
build_response(response)
|
63
63
|
end
|
64
64
|
|
65
|
-
def unset_compose_file(
|
66
|
-
uri = compose_file_uri(
|
65
|
+
def unset_compose_file(server, project_slug)
|
66
|
+
uri = compose_file_uri(server, project_slug)
|
67
67
|
response = Uffizzi::HttpClient.make_delete_request(uri)
|
68
68
|
|
69
69
|
build_response(response)
|
70
70
|
end
|
71
71
|
|
72
|
-
def fetch_secrets(
|
73
|
-
uri = secrets_uri(
|
72
|
+
def fetch_secrets(server, project_slug)
|
73
|
+
uri = secrets_uri(server, project_slug)
|
74
74
|
response = Uffizzi::HttpClient.make_get_request(uri)
|
75
75
|
|
76
76
|
build_response(response)
|
77
77
|
end
|
78
78
|
|
79
|
-
def bulk_create_secrets(
|
80
|
-
uri = "#{secrets_uri(
|
79
|
+
def bulk_create_secrets(server, project_slug, params)
|
80
|
+
uri = "#{secrets_uri(server, project_slug)}/bulk_create"
|
81
81
|
response = Uffizzi::HttpClient.make_post_request(uri, params)
|
82
82
|
|
83
83
|
build_response(response)
|
84
84
|
end
|
85
85
|
|
86
|
-
def delete_secret(
|
87
|
-
uri = secret_uri(
|
86
|
+
def delete_secret(server, project_slug, id)
|
87
|
+
uri = secret_uri(server, project_slug, id)
|
88
88
|
response = Uffizzi::HttpClient.make_delete_request(uri)
|
89
89
|
|
90
90
|
build_response(response)
|
91
91
|
end
|
92
92
|
|
93
|
-
def describe_compose_file(
|
94
|
-
uri = compose_file_uri(
|
93
|
+
def describe_compose_file(server, project_slug)
|
94
|
+
uri = compose_file_uri(server, project_slug)
|
95
95
|
response = Uffizzi::HttpClient.make_get_request(uri)
|
96
96
|
|
97
97
|
build_response(response)
|
98
98
|
end
|
99
99
|
|
100
|
-
def validate_compose_file(
|
101
|
-
uri = validate_compose_file_uri(
|
100
|
+
def validate_compose_file(server, project_slug)
|
101
|
+
uri = validate_compose_file_uri(server, project_slug)
|
102
102
|
response = Uffizzi::HttpClient.make_get_request(uri)
|
103
103
|
|
104
104
|
build_response(response)
|
105
105
|
end
|
106
106
|
|
107
|
-
def fetch_deployments(
|
108
|
-
uri = deployments_uri(
|
107
|
+
def fetch_deployments(server, project_slug)
|
108
|
+
uri = deployments_uri(server, project_slug)
|
109
109
|
response = Uffizzi::HttpClient.make_get_request(uri)
|
110
110
|
|
111
111
|
build_response(response)
|
112
112
|
end
|
113
113
|
|
114
|
-
def create_deployment(
|
115
|
-
uri = deployments_uri(
|
114
|
+
def create_deployment(server, project_slug, params)
|
115
|
+
uri = deployments_uri(server, project_slug)
|
116
116
|
response = Uffizzi::HttpClient.make_post_request(uri, params)
|
117
117
|
|
118
118
|
build_response(response)
|
119
119
|
end
|
120
120
|
|
121
|
-
def delete_deployment(
|
122
|
-
uri = deployment_uri(
|
121
|
+
def delete_deployment(server, project_slug, deployment_id)
|
122
|
+
uri = deployment_uri(server, project_slug, deployment_id)
|
123
123
|
response = Uffizzi::HttpClient.make_delete_request(uri)
|
124
124
|
|
125
125
|
build_response(response)
|
126
126
|
end
|
127
127
|
|
128
|
-
def describe_deployment(
|
129
|
-
uri = deployment_uri(
|
128
|
+
def describe_deployment(server, project_slug, deployment_id)
|
129
|
+
uri = deployment_uri(server, project_slug, deployment_id)
|
130
130
|
response = Uffizzi::HttpClient.make_get_request(uri)
|
131
131
|
|
132
132
|
build_response(response)
|
133
133
|
end
|
134
134
|
|
135
|
-
def fetch_events(
|
136
|
-
uri = events_uri(
|
135
|
+
def fetch_events(server, project_slug, deployment_id)
|
136
|
+
uri = events_uri(server, project_slug, deployment_id)
|
137
137
|
response = Uffizzi::HttpClient.make_get_request(uri)
|
138
138
|
|
139
139
|
build_response(response)
|
140
140
|
end
|
141
141
|
|
142
|
-
def get_activity_items(
|
143
|
-
uri = activity_items_uri(
|
142
|
+
def get_activity_items(server, project_slug, deployment_id)
|
143
|
+
uri = activity_items_uri(server, project_slug, deployment_id)
|
144
144
|
response = Uffizzi::HttpClient.make_get_request(uri)
|
145
145
|
|
146
146
|
build_response(response)
|
147
147
|
end
|
148
148
|
|
149
|
-
def deploy_containers(
|
150
|
-
uri = deploy_containers_uri(
|
149
|
+
def deploy_containers(server, project_slug, deployment_id, params)
|
150
|
+
uri = deploy_containers_uri(server, project_slug, deployment_id)
|
151
151
|
response = Uffizzi::HttpClient.make_post_request(uri, params)
|
152
152
|
|
153
153
|
build_response(response)
|
@@ -167,6 +167,8 @@ module ApiClient
|
|
167
167
|
return nil if response.body.nil?
|
168
168
|
|
169
169
|
JSON.parse(response.body, symbolize_names: true)
|
170
|
+
rescue JSON::ParserError
|
171
|
+
raise Uffizzi::Error.new(response.message)
|
170
172
|
end
|
171
173
|
|
172
174
|
def response_cookie(response)
|
@@ -3,64 +3,64 @@
|
|
3
3
|
require 'cgi'
|
4
4
|
|
5
5
|
module ApiRoutes
|
6
|
-
def compose_file_uri(
|
7
|
-
"#{
|
6
|
+
def compose_file_uri(server, project_slug)
|
7
|
+
"#{server}/api/cli/v1/projects/#{project_slug}/compose_file"
|
8
8
|
end
|
9
9
|
|
10
|
-
def projects_uri(
|
11
|
-
"#{
|
10
|
+
def projects_uri(server)
|
11
|
+
"#{server}/api/cli/v1/projects"
|
12
12
|
end
|
13
13
|
|
14
|
-
def secret_uri(
|
14
|
+
def secret_uri(server, project_slug, id)
|
15
15
|
path_id = CGI.escape(id)
|
16
|
-
"#{
|
16
|
+
"#{server}/api/cli/v1/projects/#{project_slug}/secrets/#{path_id}"
|
17
17
|
end
|
18
18
|
|
19
|
-
def secrets_uri(
|
20
|
-
"#{
|
19
|
+
def secrets_uri(server, project_slug)
|
20
|
+
"#{server}/api/cli/v1/projects/#{project_slug}/secrets"
|
21
21
|
end
|
22
22
|
|
23
|
-
def session_uri(
|
24
|
-
"#{
|
23
|
+
def session_uri(server)
|
24
|
+
"#{server}/api/cli/v1/session"
|
25
25
|
end
|
26
26
|
|
27
|
-
def validate_compose_file_uri(
|
28
|
-
"#{compose_files_uri(
|
27
|
+
def validate_compose_file_uri(server, project_slug)
|
28
|
+
"#{compose_files_uri(server, project_slug)}/validate"
|
29
29
|
end
|
30
30
|
|
31
|
-
def deployments_uri(
|
32
|
-
"#{
|
31
|
+
def deployments_uri(server, project_slug)
|
32
|
+
"#{server}/api/cli/v1/projects/#{project_slug}/deployments"
|
33
33
|
end
|
34
34
|
|
35
|
-
def deployment_uri(
|
36
|
-
"#{
|
35
|
+
def deployment_uri(server, project_slug, deployment_id)
|
36
|
+
"#{server}/api/cli/v1/projects/#{project_slug}/deployments/#{deployment_id}"
|
37
37
|
end
|
38
38
|
|
39
|
-
def activity_items_uri(
|
40
|
-
"#{
|
39
|
+
def activity_items_uri(server, project_slug, deployment_id)
|
40
|
+
"#{server}/api/cli/v1/projects/#{project_slug}/deployments/#{deployment_id}/activity_items"
|
41
41
|
end
|
42
42
|
|
43
|
-
def deploy_containers_uri(
|
44
|
-
"#{
|
43
|
+
def deploy_containers_uri(server, project_slug, deployment_id)
|
44
|
+
"#{server}/api/cli/v1/projects/#{project_slug}/deployments/#{deployment_id}/deploy_containers"
|
45
45
|
end
|
46
46
|
|
47
|
-
def events_uri(
|
48
|
-
"#{
|
47
|
+
def events_uri(server, project_slug, deployment_id)
|
48
|
+
"#{server}/api/cli/v1/projects/#{project_slug}/deployments/#{deployment_id}/events"
|
49
49
|
end
|
50
50
|
|
51
|
-
def credentials_uri(
|
52
|
-
"#{
|
51
|
+
def credentials_uri(server)
|
52
|
+
"#{server}/api/cli/v1/account/credentials"
|
53
53
|
end
|
54
54
|
|
55
|
-
def preview_services_uri(
|
56
|
-
"#{
|
55
|
+
def preview_services_uri(server, project_slug, deployment_id)
|
56
|
+
"#{server}/api/cli/v1/projects/#{project_slug}/deployments/#{deployment_id}/containers"
|
57
57
|
end
|
58
58
|
|
59
|
-
def delete_credential_uri(
|
60
|
-
"#{
|
59
|
+
def delete_credential_uri(server, credential_type)
|
60
|
+
"#{server}/api/cli/v1/account/credentials/#{credential_type}"
|
61
61
|
end
|
62
62
|
|
63
|
-
def preview_service_logs_uri(
|
64
|
-
"#{
|
63
|
+
def preview_service_logs_uri(server, project_slug, deployment_id, container_name)
|
64
|
+
"#{server}/api/cli/v1/projects/#{project_slug}/deployments/#{deployment_id}/containers/#{container_name}/logs"
|
65
65
|
end
|
66
66
|
end
|
@@ -36,9 +36,7 @@ module Uffizzi
|
|
36
36
|
http.request(request)
|
37
37
|
end
|
38
38
|
|
39
|
-
if response.
|
40
|
-
raise StandardError.new('Not authorized')
|
41
|
-
end
|
39
|
+
raise Uffizzi::Error.new('Not authorized') if response.is_a?(Net::HTTPUnauthorized)
|
42
40
|
|
43
41
|
response
|
44
42
|
end
|
@@ -59,7 +57,7 @@ module Uffizzi
|
|
59
57
|
request.body = params.to_json
|
60
58
|
end
|
61
59
|
request['Cookie'] = ConfigFile.read_option(:cookie) if require_cookies
|
62
|
-
if ConfigFile.exists? && ConfigFile.
|
60
|
+
if ConfigFile.exists? && ConfigFile.option_has_value?(:basic_auth_user) && ConfigFile.option_has_value?(:basic_auth_password)
|
63
61
|
request.basic_auth(ConfigFile.read_option(:basic_auth_user), ConfigFile.read_option(:basic_auth_password))
|
64
62
|
end
|
65
63
|
|
data/lib/uffizzi/config_file.rb
CHANGED
@@ -5,11 +5,11 @@ require 'fileutils'
|
|
5
5
|
|
6
6
|
module Uffizzi
|
7
7
|
class ConfigFile
|
8
|
-
CONFIG_PATH = "#{Dir.home}/.uffizzi/
|
8
|
+
CONFIG_PATH = "#{Dir.home}/.config/uffizzi/config_default.json"
|
9
9
|
|
10
10
|
class << self
|
11
|
-
def create(account_id, cookie,
|
12
|
-
data = prepare_config_data(account_id, cookie,
|
11
|
+
def create(account_id, cookie, server)
|
12
|
+
data = prepare_config_data(account_id, cookie, server)
|
13
13
|
data.each_pair { |key, value| write_option(key, value) }
|
14
14
|
end
|
15
15
|
|
@@ -28,11 +28,11 @@ module Uffizzi
|
|
28
28
|
data[option]
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
31
|
+
def option_has_value?(option)
|
32
32
|
data = read
|
33
|
-
return false
|
33
|
+
return false if !data.is_a?(Hash) || !option_exists?(option)
|
34
34
|
|
35
|
-
data.
|
35
|
+
!data[option].empty?
|
36
36
|
end
|
37
37
|
|
38
38
|
def write_option(key, value)
|
@@ -40,15 +40,15 @@ module Uffizzi
|
|
40
40
|
return nil unless data.is_a?(Hash)
|
41
41
|
|
42
42
|
data[key] = value
|
43
|
-
write(data
|
43
|
+
write(data)
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
46
|
+
def unset_option(key)
|
47
47
|
data = read
|
48
|
-
return nil unless data.is_a?(Hash)
|
48
|
+
return nil unless data.is_a?(Hash) || !option_exists?(key)
|
49
49
|
|
50
|
-
|
51
|
-
write(
|
50
|
+
data[key] = ''
|
51
|
+
write(data)
|
52
52
|
end
|
53
53
|
|
54
54
|
def rewrite_cookie(cookie)
|
@@ -61,7 +61,7 @@ module Uffizzi
|
|
61
61
|
|
62
62
|
content = data.reduce('') do |acc, pair|
|
63
63
|
property, value = pair
|
64
|
-
"#{acc}#{property}
|
64
|
+
"#{acc}#{property} = #{value}\n"
|
65
65
|
end
|
66
66
|
|
67
67
|
Uffizzi.ui.say(content)
|
@@ -71,26 +71,42 @@ module Uffizzi
|
|
71
71
|
|
72
72
|
private
|
73
73
|
|
74
|
+
def option_exists?(option)
|
75
|
+
data = read
|
76
|
+
return false unless data.is_a?(Hash)
|
77
|
+
|
78
|
+
data.key?(option)
|
79
|
+
end
|
80
|
+
|
74
81
|
def read
|
75
|
-
|
82
|
+
data = File.read(CONFIG_PATH)
|
83
|
+
options = data.split("\n")
|
84
|
+
options.reduce({}) do |acc, option|
|
85
|
+
key, value = option.split('=', 2)
|
86
|
+
acc.merge({ key.strip.to_sym => value.strip })
|
87
|
+
end
|
76
88
|
rescue Errno::ENOENT => e
|
77
89
|
Uffizzi.ui.say(e)
|
78
|
-
nil
|
79
|
-
rescue JSON::ParserError
|
80
|
-
Uffizzi.ui.say('Config file is in incorrect format')
|
81
|
-
nil
|
82
90
|
end
|
83
91
|
|
84
92
|
def write(data)
|
85
93
|
file = create_file
|
86
|
-
|
94
|
+
prepared_data = prepare_data(data)
|
95
|
+
file.write(prepared_data)
|
87
96
|
file.close
|
88
97
|
end
|
89
98
|
|
90
|
-
def
|
99
|
+
def prepare_data(data)
|
100
|
+
data.reduce('') do |acc, option|
|
101
|
+
key, value = option
|
102
|
+
"#{acc}#{key} = #{value}\n"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def prepare_config_data(account_id, cookie, server)
|
91
107
|
{
|
92
108
|
account_id: account_id,
|
93
|
-
|
109
|
+
server: server,
|
94
110
|
cookie: cookie,
|
95
111
|
}
|
96
112
|
end
|