Skip to content

Commit c74a266

Browse files
[#1307] added check for account plan
1 parent bca51b5 commit c74a266

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

lib/uffizzi/cli/install.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ class Cli::Install < Thor
2020
method_option :'node-selector-template', required: false, type: :string
2121
def controller(hostname)
2222
Uffizzi::AuthHelper.check_login
23+
check_account_can_install
2324

24-
# InstallService.kubectl_exists?
25-
# InstallService.helm_exists?
25+
InstallService.kubectl_exists?
26+
InstallService.helm_exists?
2627

2728
if options[:context].present? && options[:context] != InstallService.kubeconfig_current_context
2829
InstallService.set_current_context(options[:context])
@@ -182,7 +183,18 @@ def update_controller_settings(controller_setting_id, params)
182183

183184
def create_controller_settings(params)
184185
response = create_account_controller_settings(server, account_id, params)
185-
Uffizzi::ResponseHelper.handle_failed_response(response) unless Uffizzi::ResponseHelper.created?(response)
186+
unless Uffizzi::ResponseHelper.created?(response)
187+
Uffizzi::ResponseHelper.handle_failed_response(response)
188+
raise Uffizzi::Error.new
189+
end
190+
end
191+
192+
def check_account_can_install
193+
response = check_can_install(server, account_id)
194+
unless Uffizzi::ResponseHelper.ok?(response)
195+
Uffizzi::ResponseHelper.handle_failed_response(response)
196+
raise Uffizzi::Error.new
197+
end
186198
end
187199

188200
def build_controller_setting_params(uri, installation_options)

lib/uffizzi/clients/api/api_client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ def fetch_accounts(server)
4444
build_response(response)
4545
end
4646

47+
def check_can_install(server, account_id)
48+
uri = account_can_install_uri(server, account_id)
49+
50+
response = http_client.make_get_request(uri)
51+
52+
build_response(response)
53+
end
54+
4755
def fetch_projects(server)
4856
uri = projects_uri(server)
4957
response = http_client.make_get_request(uri)

lib/uffizzi/clients/api/api_routes.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ def account_uri(server, account_name)
1111
"#{server}/api/cli/v1/accounts/#{account_name}"
1212
end
1313

14+
def account_can_install_uri(server, account_id)
15+
"#{server}/api/cli/v1/accounts/#{account_id}/check_can_install"
16+
end
17+
1418
def compose_file_uri(server, project_slug)
1519
"#{server}/api/cli/v1/projects/#{project_slug}/compose_file"
1620
end

test/support/uffizzi_stub_support.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ def stub_uffizzi_accounts_success(body)
4444
stub_request(:get, url).to_return(status: 200, body: body.to_json)
4545
end
4646

47+
def stub_uffizzi_check_can_install_success(account_id)
48+
url = account_can_install_uri(Uffizzi.configuration.server, account_id)
49+
50+
stub_request(:get, url).to_return(status: 200)
51+
end
52+
4753
def stub_uffizzi_account_success(body, account_name)
4854
url = account_uri(Uffizzi.configuration.server, account_name)
4955

test/uffizzi/cli/install_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def test_install
6262
stub_get_account_controller_settings_request(empty_controller_settings_body, account_id)
6363
stub_create_account_controller_settings_request({}, account_id)
6464
stub_update_account_success(account_body, account_name)
65+
stub_uffizzi_check_can_install_success(account_id)
6566

6667
@install.options = command_options(email: '[email protected]')
6768
@install.controller(host)
@@ -116,6 +117,7 @@ def test_install_if_settgins_exists
116117
stub_get_account_controller_settings_request(account_controller_settings_body, account_id)
117118
stub_update_account_controller_settings_request(account_controller_settings_body, account_id,
118119
account_controller_settings_body[:controller_settings][0][:id])
120+
stub_uffizzi_check_can_install_success(account_id)
119121

120122
@install.options = command_options(email: '[email protected]')
121123
@install.controller(host)

0 commit comments

Comments
 (0)