From a108bac591a0b032e22655613a53e819c55c825a Mon Sep 17 00:00:00 2001 From: Zipofar Date: Fri, 4 Aug 2023 18:46:08 +0300 Subject: [PATCH 1/5] [292] Add --all flag to cluster list --- lib/uffizzi/cli/cluster.rb | 30 +++++++++++++++---- lib/uffizzi/clients/api/api_client.rb | 7 +++++ lib/uffizzi/clients/api/api_routes.rb | 4 +++ ...fizzi_clusters_list_with_project_name.json | 21 +++++++++++++ test/uffizzi/cli/cluster_test.rb | 9 ++++++ 5 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/files/uffizzi/uffizzi_clusters_list_with_project_name.json diff --git a/lib/uffizzi/cli/cluster.rb b/lib/uffizzi/cli/cluster.rb index 74f3b3a9..1b6796c8 100644 --- a/lib/uffizzi/cli/cluster.rb +++ b/lib/uffizzi/cli/cluster.rb @@ -16,6 +16,7 @@ class Error < StandardError; end include ApiClient desc 'list', 'List all clusters' + method_option :all, required: false, type: :boolean, aliases: '-a' method_option :output, required: false, type: :string, aliases: '-o', enum: ['json', 'pretty-json'] def list run('list') @@ -75,8 +76,13 @@ def run(command, command_args = {}) end def handle_list_command(project_slug) - oidc_token = ConfigFile.read_option(:oidc_token) - response = get_clusters(ConfigFile.read_option(:server), project_slug, oidc_token: oidc_token) + is_all = options[:all] + response = if is_all + get_account_clusters(ConfigFile.read_option(:server), ConfigFile.read_option(:account, :id)) + else + oidc_token = ConfigFile.read_option(:oidc_token) + get_clusters(ConfigFile.read_option(:server), project_slug, oidc_token: oidc_token) + end if ResponseHelper.ok?(response) handle_succeed_list_response(response) @@ -242,11 +248,25 @@ def handle_succeed_list_response(response) clusters = response[:body][:clusters] || [] raise Uffizzi::Error.new('The project has no active clusters') if clusters.empty? - if Uffizzi.ui.output_format.nil? - clusters = clusters.map { |cluster| "- #{cluster[:name]}" }.join("\n").strip + clusters_data = if Uffizzi.ui.output_format.nil? + render_plain_cluster_list(clusters) + else + clusters.map { |c| c.slice(:name, :project) } end - Uffizzi.ui.say(clusters) + Uffizzi.ui.say(clusters_data) + end + + def render_plain_cluster_list(clusters) + clusters.map do |cluster| + project_name = cluster.dig(:project, :name) + + if project_name.present? + "- Cluster name: #{cluster[:name].strip} Project name: #{project_name.strip}" + else + "- #{cluster[:name]}" + end + end.join("\n") end def handle_succeed_describe(cluster_data) diff --git a/lib/uffizzi/clients/api/api_client.rb b/lib/uffizzi/clients/api/api_client.rb index 08c16fa4..66c54fc0 100644 --- a/lib/uffizzi/clients/api/api_client.rb +++ b/lib/uffizzi/clients/api/api_client.rb @@ -293,6 +293,13 @@ def delete_cluster(server, project_slug, params) build_response(response) end + def get_account_clusters(server, account_id) + uri = account_projects_uri(server, account_id) + response = http_client.make_get_request(uri) + + build_response(response) + end + private def http_client diff --git a/lib/uffizzi/clients/api/api_routes.rb b/lib/uffizzi/clients/api/api_routes.rb index 750cb76e..95cf7721 100644 --- a/lib/uffizzi/clients/api/api_routes.rb +++ b/lib/uffizzi/clients/api/api_routes.rb @@ -121,4 +121,8 @@ def access_tokens_url(server) def browser_sign_in_url(server, session_id) "#{server}/sign_in?session_id=#{session_id}" end + + def account_clusters_uri(server, account_id) + "#{server}/api/cli/v1/accounts/#{account_id}/clusters" + end end diff --git a/test/fixtures/files/uffizzi/uffizzi_clusters_list_with_project_name.json b/test/fixtures/files/uffizzi/uffizzi_clusters_list_with_project_name.json new file mode 100644 index 00000000..42f374af --- /dev/null +++ b/test/fixtures/files/uffizzi/uffizzi_clusters_list_with_project_name.json @@ -0,0 +1,21 @@ +{ + "clusters":[ + { + "name":"uffizzi-test-cluster-1", + "project": { + "name": "Project 1" + } + }, + { + "name":"uffizzi-test-cluster-2", + "project": { + "name": "Project 1" + } + }, + { + "name":"uffizzi-test-cluster-3", + "project": { + "name": "Project Second" + } + }] +} diff --git a/test/uffizzi/cli/cluster_test.rb b/test/uffizzi/cli/cluster_test.rb index 95cdadb3..a4ca0271 100644 --- a/test/uffizzi/cli/cluster_test.rb +++ b/test/uffizzi/cli/cluster_test.rb @@ -117,6 +117,15 @@ def test_list_clusters assert_requested(stubbed_uffizzi_cluster_get_request) end + def test_list_clusters_with_all_flag + clusters_get_body = json_fixture('files/uffizzi/uffizzi_clusters_list_with_project_name.json') + stubbed_uffizzi_cluster_get_request = stub_uffizzi_get_clusters(clusters_get_body, @project_slug) + + @cluster.list + + assert_requested(stubbed_uffizzi_cluster_get_request) + end + def test_update_kubeconfig_if_kubeconfig_exists_with_another_cluster @cluster.options = command_options(kubeconfig: @kubeconfig_path) From 215a4002ee81df044fc29f96b7a6b5adf61b93c1 Mon Sep 17 00:00:00 2001 From: Zipofar Date: Thu, 10 Aug 2023 17:05:18 +0300 Subject: [PATCH 2/5] [292] Fix and refactor --- lib/uffizzi/cli/cluster.rb | 2 +- lib/uffizzi/clients/api/api_client.rb | 8 ++++---- lib/uffizzi/clients/api/api_routes.rb | 2 +- test/support/uffizzi_stub_support.rb | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/uffizzi/cli/cluster.rb b/lib/uffizzi/cli/cluster.rb index 1b6796c8..84287e3d 100644 --- a/lib/uffizzi/cli/cluster.rb +++ b/lib/uffizzi/cli/cluster.rb @@ -81,7 +81,7 @@ def handle_list_command(project_slug) get_account_clusters(ConfigFile.read_option(:server), ConfigFile.read_option(:account, :id)) else oidc_token = ConfigFile.read_option(:oidc_token) - get_clusters(ConfigFile.read_option(:server), project_slug, oidc_token: oidc_token) + get_project_clusters(ConfigFile.read_option(:server), project_slug, oidc_token: oidc_token) end if ResponseHelper.ok?(response) diff --git a/lib/uffizzi/clients/api/api_client.rb b/lib/uffizzi/clients/api/api_client.rb index 66c54fc0..b18582a6 100644 --- a/lib/uffizzi/clients/api/api_client.rb +++ b/lib/uffizzi/clients/api/api_client.rb @@ -248,15 +248,15 @@ def get_k8s_container_description(server, project_slug, deployment_id, container build_response(response) end - def get_clusters(server, project_slug, params) - uri = clusters_uri(server, project_slug, oidc_token: params[:oidc_token]) + def get_project_clusters(server, project_slug, params = nil) + uri = project_clusters_uri(server, project_slug, oidc_token: params[:oidc_token]) response = http_client.make_get_request(uri) build_response(response) end def create_cluster(server, project_slug, params) - uri = clusters_uri(server, project_slug, oidc_token: nil) + uri = project_clusters_uri(server, project_slug, oidc_token: nil) response = http_client.make_post_request(uri, params) build_response(response) @@ -294,7 +294,7 @@ def delete_cluster(server, project_slug, params) end def get_account_clusters(server, account_id) - uri = account_projects_uri(server, account_id) + uri = account_clusters_uri(server, account_id) response = http_client.make_get_request(uri) build_response(response) diff --git a/lib/uffizzi/clients/api/api_routes.rb b/lib/uffizzi/clients/api/api_routes.rb index 95cf7721..ecc142b0 100644 --- a/lib/uffizzi/clients/api/api_routes.rb +++ b/lib/uffizzi/clients/api/api_routes.rb @@ -98,7 +98,7 @@ def k8s_container_description_uri(server, project_slug, deployment_id, container "#{server}/api/cli/v1/projects/#{project_slug}/deployments/#{deployment_id}/containers/#{container_name}/k8s_container_description" end - def clusters_uri(server, project_slug, oidc_token:) + def project_clusters_uri(server, project_slug, oidc_token:) return "#{server}/api/cli/v1/projects/#{project_slug}/clusters" if oidc_token.nil? "#{server}/api/cli/v1/projects/#{project_slug}/clusters?token=#{oidc_token}" diff --git a/test/support/uffizzi_stub_support.rb b/test/support/uffizzi_stub_support.rb index d2d8028f..99fba5c1 100644 --- a/test/support/uffizzi_stub_support.rb +++ b/test/support/uffizzi_stub_support.rb @@ -177,7 +177,7 @@ def stub_uffizzi_delete_credential_fail(account_id, body, credential_type) end def stub_uffizzi_create_cluster(body, project_slug) - uri = clusters_uri(Uffizzi.configuration.server, project_slug, oidc_token: nil) + uri = project_clusters_uri(Uffizzi.configuration.server, project_slug, oidc_token: nil) stub_request(:post, uri).to_return(status: 201, body: body.to_json) end @@ -189,7 +189,7 @@ def stub_get_cluster_request(body, project_slug) end def stub_uffizzi_get_clusters(body, project_slug) - uri = clusters_uri(Uffizzi.configuration.server, project_slug, oidc_token: nil) + uri = project_clusters_uri(Uffizzi.configuration.server, project_slug, oidc_token: nil) stub_request(:get, uri).to_return(status: 200, body: body.to_json) end From 3751424a48ed6dc7878e21206570bee16d3f7c0f Mon Sep 17 00:00:00 2001 From: Zipofar Date: Wed, 23 Aug 2023 15:14:14 +0300 Subject: [PATCH 3/5] [279] Fix Bump --- .github/workflows/create-test-binary.yml | 65 ++++++++++++++++++++++++ lib/uffizzi/clients/api/http_client.rb | 3 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/create-test-binary.yml diff --git a/.github/workflows/create-test-binary.yml b/.github/workflows/create-test-binary.yml new file mode 100644 index 00000000..6d69cae8 --- /dev/null +++ b/.github/workflows/create-test-binary.yml @@ -0,0 +1,65 @@ +name: Create Linux release +on: + push: + tags: + - 'test*.*.*' +env: + RELEASE_VERSION: ${{ github.ref_name }} + LINUX_BIN_PATH: uffizzi-linux + DARWIN_BIN_PATH: uffizzi-darwin +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +jobs: + make: + strategy: + matrix: + os: [ubuntu-20.04, macos-12] + fail-fast: false + runs-on: ${{ matrix.os }} + steps: + - name: 'Install Linux dependencies' + if: matrix.os == 'ubuntu-20.04' + run: | + sudo apt update + sudo apt install -y build-essential squashfs-tools curl gcc make bison + - name: 'Install MacOs dependencies' + if: matrix.os == 'macos-12' + run: | + brew install squashfs + - uses: actions/checkout@v2 + - name: 'Set up Ruby' + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.0.3' + - name: 'Create Linux Bin' + if: matrix.os == 'ubuntu-20.04' + run: | + wget https://github.com/pmq20/ruby-packer/releases/download/linux-x64/rubyc + chmod +x ./rubyc + ./rubyc --openssl-dir=/etc/ssl ./uffizzi --output=${{ env.LINUX_BIN_PATH }} + - name: 'Create Darwin Bin' + if: matrix.os == 'macos-12' + run: | + export PATH="$(brew --prefix)/opt/openssl@1.1/bin:$PATH" + export LDFLAGS="-L$(brew --prefix)/opt/openssl@1.1/lib" + export CPPFLAGS="-I$(brew --prefix)/opt/openssl@1.1/include" + export PKG_CONFIG_PATH="$(brew --prefix)/opt/openssl@1.1/lib/pkgconfig" + export SSL_CERT_FILE=$(ruby -e "require 'openssl'; puts OpenSSL::X509::DEFAULT_CERT_FILE") + + wget https://github.com/pmq20/ruby-packer/releases/download/darwin-x64/rubyc + chmod +x ./rubyc + ./rubyc --openssl-dir=/etc/ssl ./uffizzi --output=${{ env.DARWIN_BIN_PATH }} + - name: Upload Artifacts + uses: actions/upload-artifact@v2 + if: matrix.os == 'ubuntu-20.04' + with: + name: ${{ env.LINUX_BIN_PATH }} + path: ${{ env.LINUX_BIN_PATH }} + - name: Upload Artifacts + uses: actions/upload-artifact@v2 + if: matrix.os == 'macos-12' + with: + name: ${{ env.DARWIN_BIN_PATH }} + path: ${{ env.DARWIN_BIN_PATH }} diff --git a/lib/uffizzi/clients/api/http_client.rb b/lib/uffizzi/clients/api/http_client.rb index a8984e92..e6913df9 100644 --- a/lib/uffizzi/clients/api/http_client.rb +++ b/lib/uffizzi/clients/api/http_client.rb @@ -74,8 +74,9 @@ def build_request(uri, params, method) def get_headers(access_token) content_type_headers = { 'Content-Type' => 'application/json' } auth_headers = access_token ? { 'Authorization' => "Bearer #{access_token}" } : {} + cli_version = { 'x-uffizzi-cli-version' => Uffizzi::VERSION } - content_type_headers.merge(auth_headers) + content_type_headers.merge(auth_headers).merge(cli_version) end end end From 67e9c45203975c64b7f7c48c061efd0f25e593fb Mon Sep 17 00:00:00 2001 From: Zipofar Date: Wed, 23 Aug 2023 18:46:23 +0300 Subject: [PATCH 4/5] [279] Separate binary creation --- .github/workflows/create-test-binary.yml | 59 ++--------------------- .github/workflows/make-binary.yml | 61 ++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/make-binary.yml diff --git a/.github/workflows/create-test-binary.yml b/.github/workflows/create-test-binary.yml index 6d69cae8..28741083 100644 --- a/.github/workflows/create-test-binary.yml +++ b/.github/workflows/create-test-binary.yml @@ -3,63 +3,14 @@ on: push: tags: - 'test*.*.*' -env: - RELEASE_VERSION: ${{ github.ref_name }} - LINUX_BIN_PATH: uffizzi-linux - DARWIN_BIN_PATH: uffizzi-darwin concurrency: group: ${{ github.ref }} cancel-in-progress: true jobs: - make: - strategy: - matrix: - os: [ubuntu-20.04, macos-12] - fail-fast: false - runs-on: ${{ matrix.os }} - steps: - - name: 'Install Linux dependencies' - if: matrix.os == 'ubuntu-20.04' - run: | - sudo apt update - sudo apt install -y build-essential squashfs-tools curl gcc make bison - - name: 'Install MacOs dependencies' - if: matrix.os == 'macos-12' - run: | - brew install squashfs - - uses: actions/checkout@v2 - - name: 'Set up Ruby' - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.0.3' - - name: 'Create Linux Bin' - if: matrix.os == 'ubuntu-20.04' - run: | - wget https://github.com/pmq20/ruby-packer/releases/download/linux-x64/rubyc - chmod +x ./rubyc - ./rubyc --openssl-dir=/etc/ssl ./uffizzi --output=${{ env.LINUX_BIN_PATH }} - - name: 'Create Darwin Bin' - if: matrix.os == 'macos-12' - run: | - export PATH="$(brew --prefix)/opt/openssl@1.1/bin:$PATH" - export LDFLAGS="-L$(brew --prefix)/opt/openssl@1.1/lib" - export CPPFLAGS="-I$(brew --prefix)/opt/openssl@1.1/include" - export PKG_CONFIG_PATH="$(brew --prefix)/opt/openssl@1.1/lib/pkgconfig" - export SSL_CERT_FILE=$(ruby -e "require 'openssl'; puts OpenSSL::X509::DEFAULT_CERT_FILE") + build-binary: + uses: ./.github/workflows/make-binary.yml + with: + linux-bin-path: uffizzi-linux + darwin-bin-path: uffizzi-darwin - wget https://github.com/pmq20/ruby-packer/releases/download/darwin-x64/rubyc - chmod +x ./rubyc - ./rubyc --openssl-dir=/etc/ssl ./uffizzi --output=${{ env.DARWIN_BIN_PATH }} - - name: Upload Artifacts - uses: actions/upload-artifact@v2 - if: matrix.os == 'ubuntu-20.04' - with: - name: ${{ env.LINUX_BIN_PATH }} - path: ${{ env.LINUX_BIN_PATH }} - - name: Upload Artifacts - uses: actions/upload-artifact@v2 - if: matrix.os == 'macos-12' - with: - name: ${{ env.DARWIN_BIN_PATH }} - path: ${{ env.DARWIN_BIN_PATH }} diff --git a/.github/workflows/make-binary.yml b/.github/workflows/make-binary.yml new file mode 100644 index 00000000..e0a9f73e --- /dev/null +++ b/.github/workflows/make-binary.yml @@ -0,0 +1,61 @@ +on: + workflow_call: + inputs: + linux-bin-path: + required: true + type: string + darwin-bin-path: + required: true + type: string +jobs: + make-binary: + strategy: + matrix: + os: [ubuntu-20.04, macos-12] + fail-fast: false + runs-on: ${{ matrix.os }} + steps: + - name: 'Install Linux dependencies' + if: matrix.os == 'ubuntu-20.04' + run: | + sudo apt update + sudo apt install -y build-essential squashfs-tools curl gcc make bison + - name: 'Install MacOs dependencies' + if: matrix.os == 'macos-12' + run: | + brew install squashfs + - uses: actions/checkout@v2 + - name: 'Set up Ruby' + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.0.3' + - name: 'Create Linux Bin' + if: matrix.os == 'ubuntu-20.04' + run: | + wget https://github.com/pmq20/ruby-packer/releases/download/linux-x64/rubyc + chmod +x ./rubyc + ./rubyc --openssl-dir=/etc/ssl ./uffizzi --output=${{ env.LINUX_BIN_PATH }} + - name: 'Create Darwin Bin' + if: matrix.os == 'macos-12' + run: | + export PATH="$(brew --prefix)/opt/openssl@1.1/bin:$PATH" + export LDFLAGS="-L$(brew --prefix)/opt/openssl@1.1/lib" + export CPPFLAGS="-I$(brew --prefix)/opt/openssl@1.1/include" + export PKG_CONFIG_PATH="$(brew --prefix)/opt/openssl@1.1/lib/pkgconfig" + export SSL_CERT_FILE=$(ruby -e "require 'openssl'; puts OpenSSL::X509::DEFAULT_CERT_FILE") + + wget https://github.com/pmq20/ruby-packer/releases/download/darwin-x64/rubyc + chmod +x ./rubyc + ./rubyc --openssl-dir=/etc/ssl ./uffizzi --output=${{ inputs.darwin-bin-path }} + - name: Upload Artifacts + uses: actions/upload-artifact@v2 + if: matrix.os == 'ubuntu-20.04' + with: + name: ${{ inputs.linux-bin-path }} + path: ${{ inputs.linux-bin-path }} + - name: Upload Artifacts + uses: actions/upload-artifact@v2 + if: matrix.os == 'macos-12' + with: + name: ${{ inputs.darwin-bin-path }} + path: ${{ inputs.darwin-bin-path }} From e096b1c298747f8b1accafe88103d8509ac73ec7 Mon Sep 17 00:00:00 2001 From: Lidia Mokevnina Date: Mon, 28 Aug 2023 11:10:02 +0200 Subject: [PATCH 5/5] Change version to 2.0.25 --- Gemfile.lock | 2 +- lib/uffizzi/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0e6aa37b..53167fb2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - uffizzi-cli (2.0.24) + uffizzi-cli (2.0.25) activesupport awesome_print faker diff --git a/lib/uffizzi/version.rb b/lib/uffizzi/version.rb index e2e48538..6a3dd9bc 100644 --- a/lib/uffizzi/version.rb +++ b/lib/uffizzi/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Uffizzi - VERSION = '2.0.24' + VERSION = '2.0.25' end