Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[381] Add status command #387

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ GEM
power_assert (>= 1.1)
mocha (1.13.0)
mustache (0.99.8)
nokogiri (1.13.1-aarch64-linux)
nokogiri (1.15.5-aarch64-linux)
racc (~> 1.4)
nokogiri (1.13.1-x86_64-linux)
nokogiri (1.15.5-x86_64-linux)
racc (~> 1.4)
open3 (0.1.1)
parallel (1.21.0)
Expand Down
4 changes: 4 additions & 0 deletions lib/uffizzi/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def disconnect(credential_type)
require_relative 'cli/uninstall'
subcommand 'uninstall', Cli::Uninstall

desc 'status', 'status'
require_relative 'cli/status'
subcommand 'status', Cli::Status

map preview: :compose

class << self
Expand Down
43 changes: 43 additions & 0 deletions lib/uffizzi/cli/status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

require 'uffizzi'
require 'uffizzi/config_file'

module Uffizzi
class Cli::Status < Thor
include ApiClient

default_task :describe

desc 'describe', 'Show account status'
def describe
Uffizzi::AuthHelper.check_login

account_name = ConfigFile.read_option(:account)[:name]
response = fetch_account(ConfigFile.read_option(:server), account_name)

if ResponseHelper.ok?(response)
handle_describe_success_response(response)
elsif ResponseHelper.not_found?(response)
Uffizzi.ui.say("Account with name #{account_name} does not exist")
else
ResponseHelper.handle_failed_response(response)
end
end

private

def handle_describe_success_response(response)
account = response[:body][:account]
account_rendered_params = {
account: account[:name],
plan: "Uffizzi #{account[:product_name]}",
api: account[:api_url],
controller: account[:vclusters_controller_url],
}

Uffizzi.ui.output_format = Uffizzi::UI::Shell::PRETTY_LIST
Uffizzi.ui.say(account_rendered_params)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"account":
{
{
"id": 1,
"name": "test",
"projects": [
{
"id": 1,
"slug": "uffizzi-test-slug-1"
}
]
],
"api_url": "http://app.uffizzi.com",
"vclusters_controller_url": "http://controller.uffizzi.com",
"product_name": "Starter Plan"
}
}
23 changes: 23 additions & 0 deletions test/uffizzi/cli/status_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'test_helper'

class StatusTest < Minitest::Test
def setup
@status = Uffizzi::Cli::Status.new

sign_in
Uffizzi::ConfigFile.write_option(:project, 'uffizzi')
end

def test_status
body = json_fixture('files/uffizzi/uffizzi_account_success_with_one_project.json')
account_name = Uffizzi::ConfigFile.read_option(:account, :name)
stubbed_uffizzi_account = stub_uffizzi_account_success(body, account_name)

@status.describe

assert_requested(stubbed_uffizzi_account)
assert_match("API: #{body[:account][:api_url]}", Uffizzi.ui.last_message)
end
end
1 change: 0 additions & 1 deletion test/uffizzi/cli/uninstall_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'byebug'
require 'psych'
require 'base64'
require 'test_helper'
Expand Down
Loading