From dca62663ff441e9a396350b8d7eac132cc5f730d Mon Sep 17 00:00:00 2001 From: Aleksey Stepanov Date: Tue, 6 Sep 2022 15:06:12 +0400 Subject: [PATCH 1/9] [#157] improved json output for preview list command and improved logic of outputting --- lib/uffizzi/cli/preview.rb | 22 +++++++++++----------- lib/uffizzi/shell.rb | 31 ++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/lib/uffizzi/cli/preview.rb b/lib/uffizzi/cli/preview.rb index ef837fe4..a2e119ab 100644 --- a/lib/uffizzi/cli/preview.rb +++ b/lib/uffizzi/cli/preview.rb @@ -15,7 +15,7 @@ class Cli::Preview < Thor desc 'list', 'List all previews' method_option :filter, required: false, type: :string, aliases: '-f' - method_option :output, required: false, type: :string, aliases: '-o', enum: ['json'] + method_option :output, required: false, type: :string, aliases: '-o', enum: ['pretty-json'] def list run('list') end @@ -87,6 +87,7 @@ def handle_list_command(project_slug, filter) def handle_create_command(file_path, project_slug, labels) Uffizzi.ui.disable_stdout unless options[:output].nil? + params = prepare_params(file_path, labels) response = create_deployment(ConfigFile.read_option(:server), project_slug, params) @@ -180,13 +181,12 @@ def handle_succeed_list_response(response) deployments = response[:body][:deployments] || [] raise Uffizzi::Error.new('The project has no active deployments') if deployments.empty? - deployments.each do |deployment| - if Uffizzi.ui.output_format.nil? - Uffizzi.ui.say("deployment-#{deployment[:id]}") - else - Uffizzi.ui.pretty_say(deployment) - end + if Uffizzi.ui.output_format.nil? + deployments = deployments.reduce('') do |acc, deployment| + "#{acc}deployment-#{deployment[:id]}\n" + end.strip end + Uffizzi.ui.say(deployments) end def handle_succeed_delete_response(deployment_id) @@ -202,9 +202,8 @@ def handle_succeed_describe_response(response) container end - deployment.each_key do |key| - Uffizzi.ui.say("#{key}: #{deployment[key]}") - end + deployment_data = deployment.reduce('') { |acc, (key, value)| "#{acc}#{key}: #{value}\n" }.strip + Uffizzi.ui.say(deployment_data) end def hide_secrets(secret_variables) @@ -240,7 +239,8 @@ def display_deployment_data(deployment, success) Uffizzi.ui.say(preview_url) if success else deployment_data = build_deployment_data(deployment) - Uffizzi.ui.output(deployment_data) + Uffizzi.ui.enable_stdout + Uffizzi.ui.say(deployment_data) end end diff --git a/lib/uffizzi/shell.rb b/lib/uffizzi/shell.rb index d5f9b7e8..c672d4d2 100644 --- a/lib/uffizzi/shell.rb +++ b/lib/uffizzi/shell.rb @@ -12,7 +12,17 @@ def initialize end def say(message) - @shell.say(message) + formatted_message = case output_format + when 'pretty-json' + format_to_pretty_json(message) + when 'json' + format_to_json(message) + when 'github-action' + format_to_github_action(message) + else + message + end + @shell.say(formatted_message) end def print_in_columns(messages) @@ -42,25 +52,24 @@ def disable_stdout $stdout = StringIO.new end - def output(data) + def enable_stdout $stdout = IO.new(1, 'w') - json_format? ? output_in_json(data) : output_in_github_format(data) end private - def json_format? - output_format == 'json' + def format_to_json(data) + data.to_json end - def output_in_json(data) - say(data.to_json) + def format_to_pretty_json(data) + JSON.pretty_generate(data) end - def output_in_github_format(data) - data.each_key do |key| - say("::set-output name=#{key}::#{data[key]}") - end + def format_to_github_action(data) + return '' unless data.is_a?(Hash) + + data.reduce('') { |acc, (key, value)| "#{acc}::set-output name=#{key}::#{value}\n" } end end end From 74d7a2059732314008892811845bc8b0e791974e Mon Sep 17 00:00:00 2001 From: Aleksey Stepanov Date: Tue, 6 Sep 2022 15:07:56 +0400 Subject: [PATCH 2/9] [#157] changed flag description in manual for preview list command --- man/uffizzi-preview-list | 6 +++--- man/uffizzi-preview-list.ronn | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/man/uffizzi-preview-list b/man/uffizzi-preview-list index cde51b90..477313b5 100644 --- a/man/uffizzi-preview-list +++ b/man/uffizzi-preview-list @@ -1,6 +1,6 @@ .\" generated with Ronn-NG/v0.9.1 .\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "UFFIZZI\-PREVIEW\-LIST" "" "August 2022" "" +.TH "UFFIZZI\-PREVIEW\-LIST" "" "September 2022" "" .SH "NAME" \fBuffizzi\-preview\-list\fR \- list previews in a project .SH "SYNOPSIS" @@ -20,7 +20,7 @@ https://github\.com/UffizziCloud/uffizzi_cli \-\-filter=METADATA Metadata to filtering list of deployments\. -\-\-output=json +\-\-output=pretty\-json Use this option for a more detailed description of listed deployments\. .fi @@ -41,7 +41,7 @@ To list all previews in a project with name my_project, run: To list all previews in json format, run: - $ uffizzi preview list \-\-output="json" + $ uffizzi preview list \-\-output="pretty\-json" To list all previews filtered by metadata using single label, run: diff --git a/man/uffizzi-preview-list.ronn b/man/uffizzi-preview-list.ronn index 432a961a..82d3595f 100644 --- a/man/uffizzi-preview-list.ronn +++ b/man/uffizzi-preview-list.ronn @@ -15,7 +15,7 @@ uffizzi-preview-list - list previews in a project --filter=METADATA Metadata to filtering list of deployments. - --output=json + --output=pretty-json Use this option for a more detailed description of listed deployments. @@ -34,7 +34,7 @@ uffizzi-preview-list - list previews in a project To list all previews in json format, run: - $ uffizzi preview list --output="json" + $ uffizzi preview list --output="pretty-json" To list all previews filtered by metadata using single label, run: From 54970166fd92d6d60e837ec97fcb46b0cee5295c Mon Sep 17 00:00:00 2001 From: Aleksey Stepanov Date: Tue, 6 Sep 2022 15:08:45 +0400 Subject: [PATCH 3/9] [#157] fixed old tests and added new one for preview list command with output flag --- test/support/mocks/mock_shell.rb | 42 +++++++++++++++++++++++--------- test/uffizzi/cli/preview_test.rb | 16 +++++++++++- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/test/support/mocks/mock_shell.rb b/test/support/mocks/mock_shell.rb index d53ef17b..0db822da 100644 --- a/test/support/mocks/mock_shell.rb +++ b/test/support/mocks/mock_shell.rb @@ -5,10 +5,23 @@ class MockShell def initialize @messages = [] + @output_enabled = true end def say(message) - @messages << message + return unless @output_enabled + + formatted_message = case output_format + when 'pretty-json' + format_to_pretty_json(message) + when 'json' + format_to_json(message) + when 'github-action' + format_to_github_action(message) + else + message + end + @messages << formatted_message end def last_message @@ -32,21 +45,28 @@ def describe_project(project) end def disable_stdout - true + @output_enabled = false end - def output(data) - case output_format - when 'json' - say(data.to_json) - when 'github-action' - data.each_key do |key| - say("::set-output name=#{key}::#{data[key]}") - end - end + def enable_stdout + @output_enabled = true end def pretty_say(collection, _index = true) collection end + + private + + def format_to_json(data) + data.to_json + end + + def format_to_pretty_json(data) + JSON.pretty_generate(data) + end + + def format_to_github_action(data) + data.reduce('') { |acc, (key, value)| "#{acc}::set-output name=#{key}::#{value}\n" } + end end diff --git a/test/uffizzi/cli/preview_test.rb b/test/uffizzi/cli/preview_test.rb index 72da102a..02fd63e7 100644 --- a/test/uffizzi/cli/preview_test.rb +++ b/test/uffizzi/cli/preview_test.rb @@ -28,6 +28,20 @@ def test_list_preview assert_requested(stubbed_uffizzi_preview_list) end + def test_list_preview_with_output_option + body = json_fixture('files/uffizzi/uffizzi_preview_list.json') + filter = {} + stubbed_uffizzi_preview_list = stub_uffizzi_preview_list_success(body, @project_slug, filter) + + deployments = body[:deployments] + + @preview.options = command_options(output: 'pretty-json') + @preview.list + + assert_equal(JSON.pretty_generate(deployments), Uffizzi.ui.last_message) + assert_requested(stubbed_uffizzi_preview_list) + end + def test_list_preview_with_filter_success body = json_fixture('files/uffizzi/uffizzi_preview_list.json') filter = { @@ -392,7 +406,7 @@ def test_update_preview_success_with_format @preview.update("deployment-#{deployment_id}", 'test/compose_files/test_compose_success.yml') expected_message_keys = ['name=id', 'name=url', 'containers_uri'] - actual_messages = Uffizzi.ui.messages.last(3) + actual_messages = Uffizzi.ui.messages.last.split("\n") expected_message_keys.zip(actual_messages).each do |(expected_msg_key, actual_msg)| assert_match(expected_msg_key, actual_msg) From 20895f21be8ca97969ec57b3adc4e084fe9d599c Mon Sep 17 00:00:00 2001 From: Aleksey Stepanov Date: Tue, 6 Sep 2022 18:32:38 +0400 Subject: [PATCH 4/9] [#157] added constants for output formats --- lib/uffizzi/cli/preview.rb | 3 ++- lib/uffizzi/shell.rb | 10 +++++++--- test/support/mocks/mock_shell.rb | 10 +++++++--- test/uffizzi/cli/preview_test.rb | 4 ++-- test/uffizzi/cli/project_test.rb | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/uffizzi/cli/preview.rb b/lib/uffizzi/cli/preview.rb index a2e119ab..66076429 100644 --- a/lib/uffizzi/cli/preview.rb +++ b/lib/uffizzi/cli/preview.rb @@ -146,7 +146,8 @@ def handle_events_command(deployment_name, project_slug) end def handle_succeed_events_response(response) - Uffizzi.ui.pretty_say(response[:body][:events]) + Uffizzi.ui.output_format = Uffizzi::UI::Shell::PRETTY_JSON + Uffizzi.ui.say(response[:body][:events]) end def handle_delete_command(deployment_name, project_slug) diff --git a/lib/uffizzi/shell.rb b/lib/uffizzi/shell.rb index c672d4d2..8c3dd48a 100644 --- a/lib/uffizzi/shell.rb +++ b/lib/uffizzi/shell.rb @@ -7,17 +7,21 @@ module UI class Shell attr_accessor :output_format + PRETTY_JSON = 'pretty-json' + REGULAR_JSON = 'json' + GITHUB_ACTION = 'github-action' + def initialize @shell = Thor::Shell::Basic.new end def say(message) formatted_message = case output_format - when 'pretty-json' + when PRETTY_JSON format_to_pretty_json(message) - when 'json' + when REGULAR_JSON format_to_json(message) - when 'github-action' + when GITHUB_ACTION format_to_github_action(message) else message diff --git a/test/support/mocks/mock_shell.rb b/test/support/mocks/mock_shell.rb index 0db822da..b82e9b5f 100644 --- a/test/support/mocks/mock_shell.rb +++ b/test/support/mocks/mock_shell.rb @@ -3,6 +3,10 @@ class MockShell attr_accessor :messages, :output_format + PRETTY_JSON = 'pretty-json' + REGULAR_JSON = 'json' + GITHUB_ACTION = 'github-action' + def initialize @messages = [] @output_enabled = true @@ -12,11 +16,11 @@ def say(message) return unless @output_enabled formatted_message = case output_format - when 'pretty-json' + when PRETTY_JSON format_to_pretty_json(message) - when 'json' + when REGULAR_JSON format_to_json(message) - when 'github-action' + when GITHUB_ACTION format_to_github_action(message) else message diff --git a/test/uffizzi/cli/preview_test.rb b/test/uffizzi/cli/preview_test.rb index 02fd63e7..2b8e1554 100644 --- a/test/uffizzi/cli/preview_test.rb +++ b/test/uffizzi/cli/preview_test.rb @@ -35,7 +35,7 @@ def test_list_preview_with_output_option deployments = body[:deployments] - @preview.options = command_options(output: 'pretty-json') + @preview.options = command_options(output: Uffizzi::UI::Shell::PRETTY_JSON) @preview.list assert_equal(JSON.pretty_generate(deployments), Uffizzi.ui.last_message) @@ -402,7 +402,7 @@ def test_update_preview_success_with_format stubbed_uffizzi_preview_deploy_containers = stub_uffizzi_preview_deploy_containers_success(@project_slug, deployment_id) stubbed_uffizzi_preview_activity_items = stub_uffizzi_preview_activity_items_success(activity_items_body, @project_slug, deployment_id) - @preview.options = command_options(output: 'github-action') + @preview.options = command_options(output: Uffizzi::UI::Shell::GITHUB_ACTION) @preview.update("deployment-#{deployment_id}", 'test/compose_files/test_compose_success.yml') expected_message_keys = ['name=id', 'name=url', 'containers_uri'] diff --git a/test/uffizzi/cli/project_test.rb b/test/uffizzi/cli/project_test.rb index 06c9de33..fb5b67f2 100644 --- a/test/uffizzi/cli/project_test.rb +++ b/test/uffizzi/cli/project_test.rb @@ -114,7 +114,7 @@ def test_project_describe_success project_slug = body[:project][:slug] stubbed_uffizzi_projects = stub_uffizzi_project_success(body, project_slug) - @project.options = { output: 'json' } + @project.options = { output: Uffizzi::UI::Shell::REGULAR_JSON } @project.describe(project_slug.to_s) From d2671f2383d7e842a09561708829014b1f2ca9d7 Mon Sep 17 00:00:00 2001 From: Aleksey Stepanov Date: Tue, 6 Sep 2022 20:05:14 +0400 Subject: [PATCH 5/9] [#157] added option --silent to few commands --- lib/uffizzi/cli.rb | 3 +++ lib/uffizzi/cli/config.rb | 2 ++ lib/uffizzi/cli/connect.rb | 6 ++++++ lib/uffizzi/cli/login.rb | 1 + lib/uffizzi/cli/login_by_identity_token.rb | 1 + 5 files changed, 13 insertions(+) diff --git a/lib/uffizzi/cli.rb b/lib/uffizzi/cli.rb index 4d2d98a4..4d8e9272 100644 --- a/lib/uffizzi/cli.rb +++ b/lib/uffizzi/cli.rb @@ -19,6 +19,7 @@ def version desc 'login [OPTIONS]', 'Login to Uffizzi to view and manage your previews' method_option :server, required: false, aliases: '-s' method_option :username, required: false, aliases: '-u' + method_option :silent, required: false, type: :boolean def login require_relative 'cli/login' Login.new(options).run @@ -27,6 +28,7 @@ def login desc 'login_by_identity_token [OPTIONS]', 'Login or register to Uffizzi to view and manage your previews' method_option :server, required: true, aliases: '-s' method_option :token, required: true, aliases: '-t' + method_option :silent, required: false, type: :boolean def login_by_identity_token require_relative 'cli/login_by_identity_token' LoginByIdentityToken.new(options).run @@ -52,6 +54,7 @@ def logout subcommand 'preview', Cli::Preview desc 'connect', 'connect' + method_option :silent, required: false, type: :boolean require_relative 'cli/connect' subcommand 'connect', Cli::Connect diff --git a/lib/uffizzi/cli/config.rb b/lib/uffizzi/cli/config.rb index 84aa0f75..535a4c8a 100644 --- a/lib/uffizzi/cli/config.rb +++ b/lib/uffizzi/cli/config.rb @@ -18,6 +18,7 @@ def get_value(property) end desc 'set [PROPERTY] [VALUE]', 'Sets the value of the specified option' + method_option :silent, required: false, type: :boolean def set(property, value) run('set', property, value) end @@ -78,6 +79,7 @@ def handle_get_command(property) end def handle_set_command(property, value) + Uffizzi.ui.disable_stdout if @options[:silent] ConfigFile.write_option(property.to_sym, value) Uffizzi.ui.say("Updated property [#{property}]") end diff --git a/lib/uffizzi/cli/connect.rb b/lib/uffizzi/cli/connect.rb index 5405056f..f32d24ec 100644 --- a/lib/uffizzi/cli/connect.rb +++ b/lib/uffizzi/cli/connect.rb @@ -26,6 +26,7 @@ def list_credentials method_option :username, type: :string, aliases: :u method_option :password, type: :string, aliases: :p def docker_hub + Uffizzi.ui.disable_stdout if options[:silent] type = Uffizzi.configuration.credential_types[:dockerhub] credential_exists = credential_exists?(type) handle_existing_credential_options('docker-hub') if credential_exists @@ -57,6 +58,7 @@ def docker_hub method_option :username, type: :string, aliases: :u method_option :password, type: :string, aliases: :p def docker_registry + Uffizzi.ui.disable_stdout if @options[:silent] type = Uffizzi.configuration.credential_types[:docker_registry] credential_exists = credential_exists?(type) handle_existing_credential_options('docker-registry') if credential_exists @@ -89,6 +91,7 @@ def docker_registry method_option :username, type: :string, aliases: :u method_option :password, type: :string, aliases: :p def acr + Uffizzi.ui.disable_stdout if @options[:silent] type = Uffizzi.configuration.credential_types[:azure] credential_exists = credential_exists?(type) handle_existing_credential_options('acr') if credential_exists @@ -121,6 +124,7 @@ def acr method_option :id, type: :string method_option :secret, type: :string, aliases: :s def ecr + Uffizzi.ui.disable_stdout if @options[:silent] type = Uffizzi.configuration.credential_types[:amazon] credential_exists = credential_exists?(type) handle_existing_credential_options('ecr') if credential_exists @@ -150,6 +154,7 @@ def ecr desc: 'Skip raising an error within check the credential' method_option :update_credential_if_exists, type: :boolean, default: false def gcr(credential_file_path = nil) + Uffizzi.ui.disable_stdout if @options[:silent] type = Uffizzi.configuration.credential_types[:google] credential_exists = credential_exists?(type) handle_existing_credential_options('gcr') if credential_exists @@ -179,6 +184,7 @@ def gcr(credential_file_path = nil) method_option :username, type: :string, aliases: :u method_option :token, type: :string, aliases: :t def ghcr + Uffizzi.ui.disable_stdout if @options[:silent] type = Uffizzi.configuration.credential_types[:github_registry] credential_exists = credential_exists?(type) handle_existing_credential_options('ghcr') if credential_exists diff --git a/lib/uffizzi/cli/login.rb b/lib/uffizzi/cli/login.rb index acdabc0e..c5dc0d78 100644 --- a/lib/uffizzi/cli/login.rb +++ b/lib/uffizzi/cli/login.rb @@ -15,6 +15,7 @@ def initialize(options) end def run + Uffizzi.ui.disable_stdout if @options[:silent] Uffizzi.ui.say('Login to Uffizzi server.') server = set_server diff --git a/lib/uffizzi/cli/login_by_identity_token.rb b/lib/uffizzi/cli/login_by_identity_token.rb index ecbc1af1..17578b49 100644 --- a/lib/uffizzi/cli/login_by_identity_token.rb +++ b/lib/uffizzi/cli/login_by_identity_token.rb @@ -13,6 +13,7 @@ def initialize(options) end def run + Uffizzi.ui.disable_stdout if @options[:silent] token = @options[:token] server = @options[:server] params = prepare_request_params(token) From 43fa4d51120a781e382457ba57ab3bd89880571e Mon Sep 17 00:00:00 2001 From: Aleksey Stepanov Date: Tue, 6 Sep 2022 20:13:20 +0400 Subject: [PATCH 6/9] [#157] updated manuals for commads using --silent flag --- man/uffizzi-config | 5 +++-- man/uffizzi-config.ronn | 3 ++- man/uffizzi-connect-acr | 5 ++++- man/uffizzi-connect-acr.ronn | 2 ++ man/uffizzi-connect-docker-hub | 5 ++++- man/uffizzi-connect-docker-hub.ronn | 2 ++ man/uffizzi-connect-docker-registry | 5 ++++- man/uffizzi-connect-docker-registry.ronn | 2 ++ man/uffizzi-connect-ecr | 5 ++++- man/uffizzi-connect-ecr.ronn | 2 ++ man/uffizzi-connect-gcr | 6 +++++- man/uffizzi-connect-gcr.ronn | 5 +++++ man/uffizzi-connect-ghcr | 5 ++++- man/uffizzi-connect-ghcr.ronn | 2 ++ man/uffizzi-login | 7 ++++++- man/uffizzi-login-by-identity-token | 7 ++++++- man/uffizzi-login-by-identity-token.html | 8 +++++++- man/uffizzi-login-by-identity-token.ronn | 4 ++++ man/uffizzi-login.ronn | 5 +++++ 19 files changed, 73 insertions(+), 12 deletions(-) diff --git a/man/uffizzi-config b/man/uffizzi-config index 9d863227..f6c09bc7 100644 --- a/man/uffizzi-config +++ b/man/uffizzi-config @@ -1,6 +1,6 @@ .\" generated with Ronn-NG/v0.9.1 .\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "CONFIG" "" "May 2022" "" +.TH "CONFIG" "" "September 2022" "" .SH "NAME" \fBconfig\fR \- configure the Uffizzi command\-line interface (CLI) .SH "SYNOPSIS" @@ -32,7 +32,8 @@ COMMAND is one of the following: Lists all options and their values from the config file\. set OPTION VALUE - Sets the value of the specified option\. + Sets the value of the specified option\. This command has \-\-silent flag + which disable any output during execution\. unset OPTION Deletes the value of the specified option\. diff --git a/man/uffizzi-config.ronn b/man/uffizzi-config.ronn index a2f0bec0..ba63fe70 100644 --- a/man/uffizzi-config.ronn +++ b/man/uffizzi-config.ronn @@ -26,7 +26,8 @@ uffizzi config - configure the Uffizzi command-line interface (CLI) Lists all options and their values from the config file. set OPTION VALUE - Sets the value of the specified option. + Sets the value of the specified option. This command has --silent flag + which disable any output during execution. unset OPTION Deletes the value of the specified option. diff --git a/man/uffizzi-connect-acr b/man/uffizzi-connect-acr index c253c1be..955be0ef 100644 --- a/man/uffizzi-connect-acr +++ b/man/uffizzi-connect-acr @@ -1,6 +1,6 @@ .\" generated with Ronn-NG/v0.9.1 .\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "UFFIZZI\-CONNECT\-ACR" "" "August 2022" "" +.TH "UFFIZZI\-CONNECT\-ACR" "" "September 2022" "" .SH "NAME" \fBuffizzi\-connect\-acr\fR \- grant a Uffizzi user account access to a private Azure Container Registry (ACR) .SH "SYNOPSIS" @@ -31,6 +31,9 @@ Username for the service\. .TP \fB\-p\fR, \fB\-\-password=\fR Password for the service\. +.TP +\fB\-\-silent\fR +Disable any output during execution\. .SH "EXAMPLES" The following command will prompt the user to enter ACR credentials, including registry domain, Docker ID and password or access token: .P diff --git a/man/uffizzi-connect-acr.ronn b/man/uffizzi-connect-acr.ronn index 6e42bbc1..07680ee2 100644 --- a/man/uffizzi-connect-acr.ronn +++ b/man/uffizzi-connect-acr.ronn @@ -32,6 +32,8 @@ https://docs.uffizzi.com/guides/container-registry-integrations Username for the service. * `-p`, `--password=`: Password for the service. +* `--silent`: + Disable any output during execution. ## EXAMPLES diff --git a/man/uffizzi-connect-docker-hub b/man/uffizzi-connect-docker-hub index 87aabefa..21442e4a 100644 --- a/man/uffizzi-connect-docker-hub +++ b/man/uffizzi-connect-docker-hub @@ -1,6 +1,6 @@ .\" generated with Ronn-NG/v0.9.1 .\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "UFFIZZI\-CONNECT\-DOCKER\-HUB" "" "August 2022" "" +.TH "UFFIZZI\-CONNECT\-DOCKER\-HUB" "" "September 2022" "" .SH "NAME" \fBuffizzi\-connect\-docker\-hub\fR \- grant a Uffizzi user account access to a private Docker Hub registry\. .SH "SYNOPSIS" @@ -28,6 +28,9 @@ Username for the service\. .TP \fB\-p\fR, \fB\-\-password=\fR Password for the service\. +.TP +\fB\-\-silent\fR +Disable any output during execution\. .SH "EXAMPLES" The following command will prompt the user to enter Docker Hub credentials, including Docker ID and password or access token: .P diff --git a/man/uffizzi-connect-docker-hub.ronn b/man/uffizzi-connect-docker-hub.ronn index 422f1fee..cd587700 100644 --- a/man/uffizzi-connect-docker-hub.ronn +++ b/man/uffizzi-connect-docker-hub.ronn @@ -30,6 +30,8 @@ https://docs.uffizzi.com/guides/container-registry-integrations Username for the service. * `-p`, `--password=`: Password for the service. +* `--silent`: + Disable any output during execution. ## EXAMPLES diff --git a/man/uffizzi-connect-docker-registry b/man/uffizzi-connect-docker-registry index 1503ad50..db7eabed 100644 --- a/man/uffizzi-connect-docker-registry +++ b/man/uffizzi-connect-docker-registry @@ -1,6 +1,6 @@ .\" generated with Ronn-NG/v0.9.1 .\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "UFFIZZI\-CONNECT\-DOCKER\-REGISTRY" "" "August 2022" "" +.TH "UFFIZZI\-CONNECT\-DOCKER\-REGISTRY" "" "September 2022" "" .SH "NAME" \fBuffizzi\-connect\-docker\-registry\fR \- grant a Uffizzi user account access to a Docker Container Registry\. .SH "SYNOPSIS" @@ -31,6 +31,9 @@ Username for the service\. .TP \fB\-p\fR, \fB\-\-password=\fR Password for the service\. +.TP +\fB\-\-silent\fR +Disable any output during execution\. .SH "EXAMPLES" The following command will prompt the user to enter Docker Container Registry credentials, including username and password: .P diff --git a/man/uffizzi-connect-docker-registry.ronn b/man/uffizzi-connect-docker-registry.ronn index 89fc1f7f..b79e6797 100644 --- a/man/uffizzi-connect-docker-registry.ronn +++ b/man/uffizzi-connect-docker-registry.ronn @@ -32,6 +32,8 @@ https://docs.uffizzi.com/guides/container-registry-integrations Username for the service. * `-p`, `--password=`: Password for the service. +* `--silent`: + Disable any output during execution. ## EXAMPLES diff --git a/man/uffizzi-connect-ecr b/man/uffizzi-connect-ecr index 5f4c688c..42d3747a 100644 --- a/man/uffizzi-connect-ecr +++ b/man/uffizzi-connect-ecr @@ -1,6 +1,6 @@ .\" generated with Ronn-NG/v0.9.1 .\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "UFFIZZI\-CONNECT\-ECR" "" "August 2022" "" +.TH "UFFIZZI\-CONNECT\-ECR" "" "September 2022" "" .SH "NAME" \fBuffizzi\-connect\-ecr\fR \- grant a Uffizzi user account access to a private Amazon Elastic Container Registry (ECR) .SH "SYNOPSIS" @@ -31,6 +31,9 @@ Access key id for the service\. .TP \fB\-s\fR, \fB\-\-secret=\fR Secret access key for the service\. +.TP +\fB\-\-silent\fR +Disable any output during execution\. .SH "EXAMPLES" The following command will prompt the user to enter ACR credentials, including registry domain, access key ID and secret access key: .P diff --git a/man/uffizzi-connect-ecr.ronn b/man/uffizzi-connect-ecr.ronn index 1ec3e844..c2624320 100644 --- a/man/uffizzi-connect-ecr.ronn +++ b/man/uffizzi-connect-ecr.ronn @@ -32,6 +32,8 @@ https://docs.uffizzi.com/guides/container-registry-integrations Access key id for the service. * `-s`, `--secret=`: Secret access key for the service. +* `--silent`: + Disable any output during execution. ## EXAMPLES diff --git a/man/uffizzi-connect-gcr b/man/uffizzi-connect-gcr index 35a01f52..6ef71aac 100644 --- a/man/uffizzi-connect-gcr +++ b/man/uffizzi-connect-gcr @@ -1,6 +1,6 @@ .\" generated with Ronn-NG/v0.9.1 .\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "UFFIZZI\-CONNECT\-GCR" "" "August 2022" "" +.TH "UFFIZZI\-CONNECT\-GCR" "" "September 2022" "" .SH "NAME" \fBuffizzi\-connect\-gcr\fR \- grant a Uffizzi user account access to a private Google Container Registry (GCR) .SH "SYNOPSIS" @@ -25,6 +25,10 @@ https://docs\.uffizzi\.com/guides/container\-registry\-integrations .TP KEY_FILE A Google Cloud service account key file\. The key file is a JSON file that grants Uffizzi access to a private GCR\. +.SH "OPTIONS" +.TP +\fB\-\-silent\fR +Disable any output during execution\. .SH "EXAMPLES" The following command uses a Google Cloud service account key file called sa\-private\-key\.json to connect to a private GCR: .P diff --git a/man/uffizzi-connect-gcr.ronn b/man/uffizzi-connect-gcr.ronn index 457c3193..f0aa51bb 100644 --- a/man/uffizzi-connect-gcr.ronn +++ b/man/uffizzi-connect-gcr.ronn @@ -28,6 +28,11 @@ https://docs.uffizzi.com/guides/container-registry-integrations * KEY_FILE: A Google Cloud service account key file. The key file is a JSON file that grants Uffizzi access to a private GCR. +## OPTIONS + +* `--silent`: + Disable any output during execution. + ## EXAMPLES The following command uses a Google Cloud service account key diff --git a/man/uffizzi-connect-ghcr b/man/uffizzi-connect-ghcr index 8a31e840..0e3b9e03 100644 --- a/man/uffizzi-connect-ghcr +++ b/man/uffizzi-connect-ghcr @@ -1,6 +1,6 @@ .\" generated with Ronn-NG/v0.9.1 .\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "UFFIZZI\-CONNECT\-GHCR" "" "August 2022" "" +.TH "UFFIZZI\-CONNECT\-GHCR" "" "September 2022" "" .SH "NAME" \fBuffizzi\-connect\-ghcr\fR \- grant a Uffizzi user account access to a private GitHub Container Registry (GHCR) .SH "SYNOPSIS" @@ -28,6 +28,9 @@ Username for the service\. .TP \fB\-t\fR, \fB\-\-token=\fR Access token for the service\. +.TP +\fB\-\-silent\fR +Disable any output during execution\. .SH "EXAMPLES" The following command will prompt the user to enter GHCR credentials, including GitHub account name and personal access token (PAT): .P diff --git a/man/uffizzi-connect-ghcr.ronn b/man/uffizzi-connect-ghcr.ronn index ae8df6d3..9fa92dbf 100644 --- a/man/uffizzi-connect-ghcr.ronn +++ b/man/uffizzi-connect-ghcr.ronn @@ -30,6 +30,8 @@ https://docs.uffizzi.com/guides/container-registry-integrations Username for the service. * `-t`, `--token=`: Access token for the service. +* `--silent`: + Disable any output during execution. ## EXAMPLES diff --git a/man/uffizzi-login b/man/uffizzi-login index 11b0c1e3..181e08fb 100644 --- a/man/uffizzi-login +++ b/man/uffizzi-login @@ -1,6 +1,6 @@ .\" generated with Ronn-NG/v0.9.1 .\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "UFFIZZI\-LOGIN" "" "May 2022" "" +.TH "UFFIZZI\-LOGIN" "" "September 2022" "" .SH "NAME" \fBuffizzi\-login\fR \- login to Uffizzi to view and manage your previews\. .SH "SYNOPSIS" @@ -19,6 +19,11 @@ https://github\.com/UffizziCloud/uffizzi_cli These flags are available to all commands: \-\-project\. Run $ uffizzi help for details\. .fi +.SH "FLAGS" +.nf +\-\-silent + Disable any output during execution\. +.fi .SH "EXAMPLES" .nf To login to the default host with the default user account, run: diff --git a/man/uffizzi-login-by-identity-token b/man/uffizzi-login-by-identity-token index b1918721..b1f831bb 100644 --- a/man/uffizzi-login-by-identity-token +++ b/man/uffizzi-login-by-identity-token @@ -1,6 +1,6 @@ .\" generated with Ronn-NG/v0.9.1 .\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "UFFIZZI\-LOGIN\-BY\-IDENTITY\-TOKEN" "" "August 2022" "" +.TH "UFFIZZI\-LOGIN\-BY\-IDENTITY\-TOKEN" "" "September 2022" "" .SH "NAME" \fBuffizzi\-login\-by\-identity\-token\fR \- login to Uffizzi using a OIDC token provided by a CI/CD pipeline .SH "SYNOPSIS" @@ -20,6 +20,11 @@ https://github\.com/UffizziCloud/uffizzi_cli These flags are available to all commands: \-\-project\. Run $ uffizzi help for details\. .fi +.SH "FLAGS" +.nf +\-\-silent + Disable any output during execution\. +.fi .SH "EXAMPLES" .nf To login from the CI/CD pipeline, run: diff --git a/man/uffizzi-login-by-identity-token.html b/man/uffizzi-login-by-identity-token.html index c39e1817..2ca6dbb6 100644 --- a/man/uffizzi-login-by-identity-token.html +++ b/man/uffizzi-login-by-identity-token.html @@ -57,6 +57,7 @@ SYNOPSIS DESCRIPTION UFFIZZI WIDE FLAGS + FLAGS EXAMPLES @@ -89,6 +90,11 @@

UFFIZZI WIDE FLAGS

help for details. +

FLAGS

+
--silent
+    Disable any output during execution.
+
+

EXAMPLES

To login from the CI/CD pipeline, run:
 
@@ -97,7 +103,7 @@ 

EXAMPLES

  1. -
  2. August 2022
  3. +
  4. September 2022
  5. uffizzi-login-by-identity-token
diff --git a/man/uffizzi-login-by-identity-token.ronn b/man/uffizzi-login-by-identity-token.ronn index 90182077..1544e9fc 100644 --- a/man/uffizzi-login-by-identity-token.ronn +++ b/man/uffizzi-login-by-identity-token.ronn @@ -15,6 +15,10 @@ These flags are available to all commands: --project. Run $ uffizzi help for details. +## FLAGS + --silent + Disable any output during execution. + ## EXAMPLES To login from the CI/CD pipeline, run: diff --git a/man/uffizzi-login.ronn b/man/uffizzi-login.ronn index 2e7c5a4a..fe33196f 100644 --- a/man/uffizzi-login.ronn +++ b/man/uffizzi-login.ronn @@ -14,6 +14,11 @@ These flags are available to all commands: --project. Run $ uffizzi help for details. +## FLAGS + --silent + Disable any output during execution. + + ## EXAMPLES To login to the default host with the default user account, run: From 4c625f79334dcb03966f12715ea1df9727b7f692 Mon Sep 17 00:00:00 2001 From: Aleksey Stepanov Date: Wed, 7 Sep 2022 15:43:04 +0400 Subject: [PATCH 7/9] [#157] revomed unused method --- lib/uffizzi/shell.rb | 4 ---- test/support/mocks/mock_shell.rb | 4 ---- 2 files changed, 8 deletions(-) diff --git a/lib/uffizzi/shell.rb b/lib/uffizzi/shell.rb index 8c3dd48a..3e0db781 100644 --- a/lib/uffizzi/shell.rb +++ b/lib/uffizzi/shell.rb @@ -48,10 +48,6 @@ def last_message @shell.send(:stdout).string.strip end - def pretty_say(collection, index = true) - ap(collection, { index: index }) - end - def disable_stdout $stdout = StringIO.new end diff --git a/test/support/mocks/mock_shell.rb b/test/support/mocks/mock_shell.rb index b82e9b5f..7e0273e4 100644 --- a/test/support/mocks/mock_shell.rb +++ b/test/support/mocks/mock_shell.rb @@ -56,10 +56,6 @@ def enable_stdout @output_enabled = true end - def pretty_say(collection, _index = true) - collection - end - private def format_to_json(data) From 373025ba1fb40860b8d85b1ed8c2e56aec83669a Mon Sep 17 00:00:00 2001 From: Aleksey Stepanov Date: Wed, 7 Sep 2022 15:43:43 +0400 Subject: [PATCH 8/9] [#157] added silent option to commands --- docker-entrypoint.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index a92e3778..acfc657b 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -7,10 +7,10 @@ if [ $UFFIZZI_SERVER ] && [ $UFFIZZI_PASSWORD ] then - uffizzi login --username "${UFFIZZI_USER}" --server "${UFFIZZI_SERVER}" + uffizzi login --username "${UFFIZZI_USER}" --server "${UFFIZZI_SERVER}" --silent if [ $UFFIZZI_PROJECT ] then - uffizzi config set project "${UFFIZZI_PROJECT}" + uffizzi config set project "${UFFIZZI_PROJECT}" --silent fi else if @@ -18,7 +18,7 @@ else [ $REQUEST_TOKEN_URL ] then OIDC_TOKEN=$(curl -sLS "${REQUEST_TOKEN_URL}&audience=uffizzi" -H "User-Agent: actions/oidc-client" -H "Authorization: Bearer $REQUEST_TOKEN") - uffizzi login_by_identity_token --token "${OIDC_TOKEN}" --server "${UFFIZZI_SERVER}" + uffizzi login_by_identity_token --token "${OIDC_TOKEN}" --server "${UFFIZZI_SERVER}" --silent else echo "Specify environment variables to login before executing Uffizzi CLI." echo "UFFIZZI_USER, UFFIZZI_SERVER, UFFIZZI_PASSWORD, and optionally UFFIZZI_PROJECT" @@ -31,7 +31,7 @@ if [ $DOCKERHUB_USERNAME ] && [ $DOCKERHUB_PASSWORD ] then - uffizzi connect docker-hub --update-credential-if-exists + uffizzi connect docker-hub --update-credential-if-exists --silent fi if @@ -39,7 +39,7 @@ if [ $DOCKER_REGISTRY_PASSWORD ] && [ $DOCKER_REGISTRY_URL ] then - uffizzi connect docker-registry --update-credential-if-exists + uffizzi connect docker-registry --update-credential-if-exists --silent fi if @@ -47,7 +47,7 @@ if [ $ACR_PASSWORD ] && [ $ACR_REGISTRY_URL ] then - uffizzi connect acr --update-credential-if-exists + uffizzi connect acr --update-credential-if-exists --silent fi if @@ -55,20 +55,20 @@ if [ $AWS_SECRET_ACCESS_KEY ] && [ $AWS_REGISTRY_URL ] then - uffizzi connect ecr --update-credential-if-exists + uffizzi connect ecr --update-credential-if-exists --silent fi if [ $GCLOUD_SERVICE_KEY ] then - uffizzi connect gcr --update-credential-if-exists + uffizzi connect gcr --update-credential-if-exists --silent fi if [ $GITHUB_USERNAME ] && [ $GITHUB_ACCESS_TOKEN ] then - uffizzi connect ghcr --update-credential-if-exists + uffizzi connect ghcr --update-credential-if-exists --silent fi exec uffizzi "$@" From f1231d14e6fba2f553557b9b2e56e531e97fc300 Mon Sep 17 00:00:00 2001 From: Aleksey Stepanov Date: Wed, 7 Sep 2022 15:44:09 +0400 Subject: [PATCH 9/9] [#157] added tests for commands with silent option --- test/test_helper.rb | 2 + test/uffizzi/cli/config_test.rb | 13 ++ test/uffizzi/cli/connect_test.rb | 138 ++++++++++++++++++ .../cli/login_by_identity_token_test.rb | 16 ++ test/uffizzi/cli/login_test.rb | 14 ++ 5 files changed, 183 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index d9ffd28f..b57aa7d8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -38,6 +38,8 @@ def before_setup @mock_shell = MockShell.new Uffizzi::UI::Shell.stubs(:new).returns(@mock_shell) Uffizzi::ConfigFile.stubs(:config_path).returns(TEST_CONFIG_PATH) + Uffizzi.ui.messages.clear + Uffizzi.ui.enable_stdout end def before_teardown diff --git a/test/uffizzi/cli/config_test.rb b/test/uffizzi/cli/config_test.rb index cef9b248..6c7cfdf7 100644 --- a/test/uffizzi/cli/config_test.rb +++ b/test/uffizzi/cli/config_test.rb @@ -43,6 +43,19 @@ def test_set_with_property_and_value assert_equal("Updated property [#{property}]", Uffizzi.ui.last_message) end + def test_silent_set_with_property_and_value + new_cookie = '_uffizzi=test2' + property = 'cookie' + + refute_equal(Uffizzi::ConfigFile.read_option(:cookie), new_cookie) + + @config.options = command_options(silent: true) + @config.set(property, new_cookie) + + assert_equal(Uffizzi::ConfigFile.read_option(:cookie), new_cookie) + refute(Uffizzi.ui.last_message) + end + def test_set_without_config cookie = '_uffizzi=test' property = 'cookie' diff --git a/test/uffizzi/cli/connect_test.rb b/test/uffizzi/cli/connect_test.rb index 4d1b5497..6743b7cc 100644 --- a/test/uffizzi/cli/connect_test.rb +++ b/test/uffizzi/cli/connect_test.rb @@ -41,6 +41,30 @@ def test_connect_docker_hub_success assert_requested(stubbed_check_credential) end + def test_silent_connect_docker_hub_success + body = json_fixture('files/uffizzi/credentials/dockerhub_credential.json') + stubbed_uffizzi_create_credential = stub_uffizzi_create_credential(@account_id, body) + stubbed_check_credential = stub_uffizzi_check_credential_success(@account_id, Uffizzi.configuration.credential_types[:dockerhub]) + + credential_params = { + username: generate(:string), + password: generate(:string), + } + + console_mock = mock('console_mock') + console_mock.stubs(:write) + console_mock.stubs(:gets).returns(credential_params[:username]) + console_mock.stubs(:getpass).returns(credential_params[:password]) + IO.stubs(:console).returns(console_mock) + + @cli.options = command_options(silent: true) + @cli.docker_hub + + refute(Uffizzi.ui.last_message) + assert_requested(stubbed_uffizzi_create_credential) + assert_requested(stubbed_check_credential) + end + def test_connect_docker_registry_success body = json_fixture('files/uffizzi/credentials/docker_registry_credentials.json') stubbed_uffizzi_create_credential = stub_uffizzi_create_credential(@account_id, body) @@ -65,6 +89,31 @@ def test_connect_docker_registry_success assert_requested(stubbed_check_credential) end + def test_silent_connect_docker_registry_success + body = json_fixture('files/uffizzi/credentials/docker_registry_credentials.json') + stubbed_uffizzi_create_credential = stub_uffizzi_create_credential(@account_id, body) + stubbed_check_credential = stub_uffizzi_check_credential_success(@account_id, Uffizzi.configuration.credential_types[:docker_registry]) + + credential_params = { + registry_url: generate(:url), + username: generate(:string), + password: generate(:string), + } + + console_mock = mock('console_mock') + console_mock.stubs(:write) + console_mock.stubs(:gets).returns(credential_params[:registry_url], credential_params[:username]) + console_mock.stubs(:getpass).returns(credential_params[:password]) + IO.stubs(:console).returns(console_mock) + + @cli.options = command_options(silent: true) + @cli.docker_registry + + refute(Uffizzi.ui.last_message) + assert_requested(stubbed_uffizzi_create_credential) + assert_requested(stubbed_check_credential) + end + def test_connect_azure_success body = json_fixture('files/uffizzi/credentials/azure_credential.json') stubbed_uffizzi_create_credential = stub_uffizzi_create_credential(@account_id, body) @@ -89,6 +138,31 @@ def test_connect_azure_success assert_requested(stubbed_check_credential) end + def test_silent_connect_azure_success + body = json_fixture('files/uffizzi/credentials/azure_credential.json') + stubbed_uffizzi_create_credential = stub_uffizzi_create_credential(@account_id, body) + stubbed_check_credential = stub_uffizzi_check_credential_success(@account_id, Uffizzi.configuration.credential_types[:azure]) + + credential_params = { + registry_url: generate(:url), + username: generate(:string), + password: generate(:string), + } + + console_mock = mock('console_mock') + console_mock.stubs(:write) + console_mock.stubs(:gets).returns(credential_params[:registry_url], credential_params[:username]) + console_mock.stubs(:getpass).returns(credential_params[:password]) + IO.stubs(:console).returns(console_mock) + + @cli.options = command_options(silent: true) + @cli.acr + + refute(Uffizzi.ui.last_message) + assert_requested(stubbed_uffizzi_create_credential) + assert_requested(stubbed_check_credential) + end + def test_connect_amazon_success body = json_fixture('files/uffizzi/credentials/amazon_credential.json') stubbed_uffizzi_create_credential = stub_uffizzi_create_credential(@account_id, body) @@ -113,6 +187,31 @@ def test_connect_amazon_success assert_requested(stubbed_check_credential) end + def test_silent_connect_amazon_success + body = json_fixture('files/uffizzi/credentials/amazon_credential.json') + stubbed_uffizzi_create_credential = stub_uffizzi_create_credential(@account_id, body) + stubbed_check_credential = stub_uffizzi_check_credential_success(@account_id, Uffizzi.configuration.credential_types[:amazon]) + + credential_params = { + registry_url: generate(:url), + username: generate(:string), + password: generate(:string), + } + + console_mock = mock('console_mock') + console_mock.stubs(:write) + console_mock.stubs(:gets).returns(credential_params[:registry_url], credential_params[:username]) + console_mock.stubs(:getpass).returns(credential_params[:password]) + IO.stubs(:console).returns(console_mock) + + @cli.options = command_options(silent: true) + @cli.ecr + + refute(Uffizzi.ui.last_message) + assert_requested(stubbed_uffizzi_create_credential) + assert_requested(stubbed_check_credential) + end + def test_connect_google_success body = json_fixture('files/uffizzi/credentials/google_credential.json') credential_path = "#{Dir.pwd}/test/fixtures/files/google/service-account.json" @@ -127,6 +226,21 @@ def test_connect_google_success assert_requested(stubbed_check_credential) end + def test_silent_connect_google_success + body = json_fixture('files/uffizzi/credentials/google_credential.json') + credential_path = "#{Dir.pwd}/test/fixtures/files/google/service-account.json" + + stubbed_uffizzi_create_credential = stub_uffizzi_create_credential(@account_id, body) + stubbed_check_credential = stub_uffizzi_check_credential_success(@account_id, Uffizzi.configuration.credential_types[:google]) + + @cli.options = command_options(silent: true) + @cli.gcr(credential_path) + + refute(Uffizzi.ui.last_message) + assert_requested(stubbed_uffizzi_create_credential) + assert_requested(stubbed_check_credential) + end + def test_connect_github_registry_success body = json_fixture('files/uffizzi/credentials/github_registry_credential.json') stubbed_uffizzi_create_credential = stub_uffizzi_create_credential(@account_id, body) @@ -150,6 +264,30 @@ def test_connect_github_registry_success assert_requested(stubbed_check_credential) end + def test_silent_connect_github_registry_success + body = json_fixture('files/uffizzi/credentials/github_registry_credential.json') + stubbed_uffizzi_create_credential = stub_uffizzi_create_credential(@account_id, body) + stubbed_check_credential = stub_uffizzi_check_credential_success(@account_id, Uffizzi.configuration.credential_types[:github_registry]) + + credential_params = { + username: generate(:string), + password: generate(:string), + } + + console_mock = mock('console_mock') + console_mock.stubs(:write) + console_mock.stubs(:gets).returns(credential_params[:username]) + console_mock.stubs(:getpass).returns(credential_params[:password]) + IO.stubs(:console).returns(console_mock) + + @cli.options = command_options(silent: true) + @cli.ghcr + + refute(Uffizzi.ui.last_message) + assert_requested(stubbed_uffizzi_create_credential) + assert_requested(stubbed_check_credential) + end + def test_connect_credential_failed body = json_fixture('files/uffizzi/credentials/credential_failed.json') stubbed_uffizzi_create_credential = stub_uffizzi_create_credential_fail(@account_id, body) diff --git a/test/uffizzi/cli/login_by_identity_token_test.rb b/test/uffizzi/cli/login_by_identity_token_test.rb index 58d135af..8efdfe4b 100644 --- a/test/uffizzi/cli/login_by_identity_token_test.rb +++ b/test/uffizzi/cli/login_by_identity_token_test.rb @@ -22,6 +22,22 @@ def test_login_success_with_oidc assert(Uffizzi::ConfigFile.option_exists?(:project)) end + def test_silent_login_success_with_oidc + body = json_fixture('files/uffizzi/uffizzi_login_by_jwt_success.json') + stubbed_uffizzi_login = stub_uffizzi_login_by_identity_token_success(body) + + refute(Uffizzi::ConfigFile.option_exists?(:server)) + refute(Uffizzi::ConfigFile.option_exists?(:username)) + + @cli.options = command_options(token: 'token', server: Uffizzi.configuration.server, silent: true) + @cli.login_by_identity_token + + refute(Uffizzi.ui.last_message) + assert_requested(stubbed_uffizzi_login) + assert(Uffizzi::ConfigFile.option_exists?(:account_id)) + assert(Uffizzi::ConfigFile.option_exists?(:project)) + end + def test_login_failed body = json_fixture('files/uffizzi/uffizzi_login_by_jwt_failure.json') stubbed_uffizzi_login = stub_uffizzi_login_by_identity_token_failure(body) diff --git a/test/uffizzi/cli/login_test.rb b/test/uffizzi/cli/login_test.rb index c5881e47..67ce3c6b 100644 --- a/test/uffizzi/cli/login_test.rb +++ b/test/uffizzi/cli/login_test.rb @@ -30,6 +30,20 @@ def test_login_success_with_options_provided assert(Uffizzi::ConfigFile.option_exists?(:account_id)) end + def test_silent_login + body = json_fixture('files/uffizzi/uffizzi_login_success.json') + stubbed_uffizzi_login = stub_uffizzi_login_success(body) + + @cli.options = command_options(username: @command_params[:username], server: @command_params[:server], silent: true) + @cli.login + + refute(Uffizzi.ui.last_message) + assert_requested(stubbed_uffizzi_login) + assert(Uffizzi::ConfigFile.option_exists?(:server)) + assert(Uffizzi::ConfigFile.option_exists?(:username)) + assert(Uffizzi::ConfigFile.option_exists?(:account_id)) + end + def test_login_success_with_options_from_config body = json_fixture('files/uffizzi/uffizzi_login_success.json') stubbed_uffizzi_login = stub_uffizzi_login_success(body)