Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
moklidia committed Aug 28, 2023
2 parents e8d04a9 + e096b1c commit 533a8fb
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 14 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/create-test-binary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Create Linux release
on:
push:
tags:
- 'test*.*.*'
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
build-binary:
uses: ./.github/workflows/make-binary.yml
with:
linux-bin-path: uffizzi-linux
darwin-bin-path: uffizzi-darwin

61 changes: 61 additions & 0 deletions .github/workflows/make-binary.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]/bin:$PATH"
export LDFLAGS="-L$(brew --prefix)/opt/[email protected]/lib"
export CPPFLAGS="-I$(brew --prefix)/opt/[email protected]/include"
export PKG_CONFIG_PATH="$(brew --prefix)/opt/[email protected]/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 }}
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
uffizzi-cli (2.0.24)
uffizzi-cli (2.0.25)
activesupport
awesome_print
faker
Expand Down
30 changes: 25 additions & 5 deletions lib/uffizzi/cli/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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')
Expand Down Expand Up @@ -78,8 +79,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_project_clusters(ConfigFile.read_option(:server), project_slug, oidc_token: oidc_token)
end

if ResponseHelper.ok?(response)
handle_succeed_list_response(response)
Expand Down Expand Up @@ -247,11 +253,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)
Expand Down
13 changes: 10 additions & 3 deletions lib/uffizzi/clients/api/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -293,6 +293,13 @@ def delete_cluster(server, project_slug, params)
build_response(response)
end

def get_account_clusters(server, account_id)
uri = account_clusters_uri(server, account_id)
response = http_client.make_get_request(uri)

build_response(response)
end

private

def http_client
Expand Down
6 changes: 5 additions & 1 deletion lib/uffizzi/clients/api/api_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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
3 changes: 2 additions & 1 deletion lib/uffizzi/clients/api/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/uffizzi/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Uffizzi
VERSION = '2.0.24'
VERSION = '2.0.25'
end
Original file line number Diff line number Diff line change
@@ -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"
}
}]
}
4 changes: 2 additions & 2 deletions test/support/uffizzi_stub_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
9 changes: 9 additions & 0 deletions test/uffizzi/cli/cluster_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 533a8fb

Please sign in to comment.