Skip to content

Commit

Permalink
Merge pull request #419 from UffizziCloud/feature/1307-check-for-busi…
Browse files Browse the repository at this point in the history
…ness_plan-before-uffizzi-install

Feature/1307 check for business plan before uffizzi install
  • Loading branch information
moklidia authored Aug 5, 2024
2 parents fe5aae3 + c74a266 commit 5491eb0
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/uffizzi/cli/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class Cli::Install < Thor
method_option :'node-selector-template', required: false, type: :string
def controller(hostname)
Uffizzi::AuthHelper.check_login
check_account_can_install

# InstallService.kubectl_exists?
# InstallService.helm_exists?
InstallService.kubectl_exists?
InstallService.helm_exists?

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

def create_controller_settings(params)
response = create_account_controller_settings(server, account_id, params)
Uffizzi::ResponseHelper.handle_failed_response(response) unless Uffizzi::ResponseHelper.created?(response)
unless Uffizzi::ResponseHelper.created?(response)
Uffizzi::ResponseHelper.handle_failed_response(response)
raise Uffizzi::Error.new
end
end

def check_account_can_install
response = check_can_install(server, account_id)
unless Uffizzi::ResponseHelper.ok?(response)
Uffizzi::ResponseHelper.handle_failed_response(response)
raise Uffizzi::Error.new
end
end

def build_controller_setting_params(uri, installation_options)
Expand Down
8 changes: 8 additions & 0 deletions lib/uffizzi/clients/api/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def fetch_accounts(server)
build_response(response)
end

def check_can_install(server, account_id)
uri = account_can_install_uri(server, account_id)

response = http_client.make_get_request(uri)

build_response(response)
end

def fetch_projects(server)
uri = projects_uri(server)
response = http_client.make_get_request(uri)
Expand Down
4 changes: 4 additions & 0 deletions lib/uffizzi/clients/api/api_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def account_uri(server, account_name)
"#{server}/api/cli/v1/accounts/#{account_name}"
end

def account_can_install_uri(server, account_id)
"#{server}/api/cli/v1/accounts/#{account_id}/check_can_install"
end

def compose_file_uri(server, project_slug)
"#{server}/api/cli/v1/projects/#{project_slug}/compose_file"
end
Expand Down
6 changes: 6 additions & 0 deletions test/support/uffizzi_stub_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def stub_uffizzi_accounts_success(body)
stub_request(:get, url).to_return(status: 200, body: body.to_json)
end

def stub_uffizzi_check_can_install_success(account_id)
url = account_can_install_uri(Uffizzi.configuration.server, account_id)

stub_request(:get, url).to_return(status: 200)
end

def stub_uffizzi_account_success(body, account_name)
url = account_uri(Uffizzi.configuration.server, account_name)

Expand Down
2 changes: 2 additions & 0 deletions test/uffizzi/cli/install_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_install
stub_get_account_controller_settings_request(empty_controller_settings_body, account_id)
stub_create_account_controller_settings_request({}, account_id)
stub_update_account_success(account_body, account_name)
stub_uffizzi_check_can_install_success(account_id)

@install.options = command_options(email: '[email protected]')
@install.controller(host)
Expand Down Expand Up @@ -116,6 +117,7 @@ def test_install_if_settgins_exists
stub_get_account_controller_settings_request(account_controller_settings_body, account_id)
stub_update_account_controller_settings_request(account_controller_settings_body, account_id,
account_controller_settings_body[:controller_settings][0][:id])
stub_uffizzi_check_can_install_success(account_id)

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

0 comments on commit 5491eb0

Please sign in to comment.