Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
the38th committed Mar 31, 2022
2 parents ab9c701 + ef0a499 commit 05850e2
Show file tree
Hide file tree
Showing 19 changed files with 513 additions and 7 deletions.
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 (0.3.8)
uffizzi-cli (0.4.0)
thor
tty-spinner

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ $ uffizzi config delete OPTION

Deletes specified option.

### disconnect ###

```
$ uffizzi disconnect CREDENTIAL_TYPE
```

Deletes credential of specified type

Supported credential types - `docker-hub`, `acr`, `ecr`, `gcr`

## Git workflow for the app:

1. Clone the repository and checkout to `develop` branch
Expand Down
4 changes: 2 additions & 2 deletions lib/uffizzi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'io/console'
require 'tty-spinner'

require 'thor'
require 'uffizzi/error'
require 'uffizzi/shell'
require 'uffizzi/version'
require 'uffizzi/clients/api/api_client'
Expand All @@ -11,8 +13,6 @@
require_relative '../config/uffizzi'

module Uffizzi
class Error < StandardError; end

class << self
def ui
@ui ||= Uffizzi::UI::Shell.new
Expand Down
10 changes: 10 additions & 0 deletions lib/uffizzi/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class CLI < Thor
require_relative 'cli/common'
class_option :help, type: :boolean, aliases: ['-h', 'help']

def self.exit_on_failure?
true
end

desc 'version', 'show version'
def version
require_relative 'version'
Expand Down Expand Up @@ -54,5 +58,11 @@ def connect(credential_type, credential_file_path = nil)
require_relative 'cli/connect'
Connect.new.run(credential_type, credential_file_path)
end

desc 'disconect CREDENTIAL_TYPE', 'Disonnect credentials from Uffizzi'
def disconnect(credential_type)
require_relative 'cli/disconnect'
Disconnect.new.run(credential_type)
end
end
end
43 changes: 43 additions & 0 deletions lib/uffizzi/cli/disconnect.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

require 'uffizzi'

module Uffizzi
class CLI::Disconnect
include ApiClient

def run(credential_type)
connection_type = case credential_type
when 'docker-hub'
Uffizzi.configuration.credential_types[:dockerhub]
when 'acr'
Uffizzi.configuration.credential_types[:azure]
when 'ecr'
Uffizzi.configuration.credential_types[:amazon]
when 'gcr'
Uffizzi.configuration.credential_types[:google]
else
raise Uffizzi::Error.new('Unsupported credential type.')
end

response = delete_credential(ConfigFile.read_option(:hostname), connection_type)

if ResponseHelper.no_content?(response)
Uffizzi.ui.say("Successfully disconnected #{connection_name(credential_type)} connection")
else
ResponseHelper.handle_failed_response(response)
end
end

private

def connection_name(credential_type)
{
'docker-hub' => 'DockerHub',
'acr' => 'ACR',
'ecr' => 'ECR',
'gcr' => 'GCR',
}[credential_type]
end
end
end
43 changes: 40 additions & 3 deletions lib/uffizzi/cli/preview/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,23 @@ module Uffizzi
class CLI::Preview::Service < Thor
include ApiClient

desc 'list', 'list'
desc 'uffizzi preview service logs [LOGS_TYPE] [DEPLOYMENT_ID] [CONTAINER_NAME]', 'logs'
def logs(logs_type, deployment_name, container_name = args)
return Uffizzi.ui.say('You are not logged in.') unless Uffizzi::AuthHelper.signed_in?
return Uffizzi.ui.say('This command needs project to be set in config file') unless Uffizzi::AuthHelper.project_set?

deployment_id = PreviewService.read_deployment_id(deployment_name)
response = service_logs_response(logs_type, deployment_id, container_name)
return Uffizzi.ui.say(response[:errors]) if response[:errors]

if ResponseHelper.ok?(response)
handle_succeed_logs_response(response, container_name)
else
ResponseHelper.handle_failed_response(response)
end
end

desc 'uffizzi preview service logs [DEPLOYMENT_ID]', 'list'
def list(deployment_name)
return Uffizzi.ui.say('You are not logged in.') unless Uffizzi::AuthHelper.signed_in?
return Uffizzi.ui.say('This command needs project to be set in config file') unless Uffizzi::AuthHelper.project_set?
Expand All @@ -20,21 +36,42 @@ def list(deployment_name)
response = fetch_deployment_services(hostname, project_slug, deployment_id)

if ResponseHelper.ok?(response)
handle_succeed_response(response, deployment_name)
handle_succeed_list_response(response, deployment_name)
else
ResponseHelper.handle_failed_response(response)
end
end

private

def handle_succeed_response(response, deployment_name)
def service_logs_response(logs_type, deployment_id, container_name)
project_slug = ConfigFile.read_option(:project)
hostname = ConfigFile.read_option(:hostname)

case logs_type
when 'container'
fetch_deployment_service_logs(hostname, project_slug, deployment_id, container_name)
else
raise Uffizzi::Error.new('Unknown log type')
end
end

def handle_succeed_list_response(response, deployment_name)
services = response[:body][:containers] || []
return Uffizzi.ui.say("There are no services associated with the preview #{deployment_name}") if services.empty?

services.each do |service|
Uffizzi.ui.say(service)
end
end

def handle_succeed_logs_response(response, container_name)
logs = response[:body][:logs] || []
return Uffizzi.ui.say("The service #{container_name} has no logs") if logs.empty?

logs.each do |log|
Uffizzi.ui.say(log)
end
end
end
end
14 changes: 14 additions & 0 deletions lib/uffizzi/clients/api/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ def fetch_deployment_services(hostname, project_slug, deployment_id)
build_response(response)
end

def delete_credential(hostname, credential_type)
uri = delete_credential_uri(hostname, credential_type)
response = Uffizzi::HttpClient.make_delete_request(uri)

build_response(response)
end

def fetch_deployment_service_logs(hostname, project_slug, deployment_id, container_name)
uri = preview_service_logs_uri(hostname, project_slug, deployment_id, container_name)
response = Uffizzi::HttpClient.make_get_request(uri)

build_response(response)
end

def set_compose_file(hostname, params, project_slug)
uri = compose_file_uri(hostname, project_slug)
response = Uffizzi::HttpClient.make_post_request(uri, params)
Expand Down
8 changes: 8 additions & 0 deletions lib/uffizzi/clients/api/api_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ def credentials_uri(hostname)
def preview_services_uri(hostname, project_slug, deployment_id)
"#{hostname}/api/cli/v1/projects/#{project_slug}/deployments/#{deployment_id}/containers"
end

def delete_credential_uri(hostname, credential_type)
"#{hostname}/api/cli/v1/account/credentials/#{credential_type}"
end

def preview_service_logs_uri(hostname, project_slug, deployment_id, container_name)
"#{hostname}/api/cli/v1/projects/#{project_slug}/deployments/#{deployment_id}/containers/#{container_name}/logs"
end
end
5 changes: 5 additions & 0 deletions lib/uffizzi/error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module Uffizzi
class Error < Thor::Error; 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 = '0.3.8'
VERSION = '0.4.0'
end
62 changes: 62 additions & 0 deletions man/uffizzi-preview_service_logs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.\" generated with Ronn-NG/v0.9.1
.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
.TH "PREVIEW" "" "March 2022" ""
.SH "NAME"
\fBpreview\fR \- manage previews
.SH "NAME"
.nf
uffizzi preview service logs \- show the logs for a container service
of a preview
.fi
.SH "SYNOPSIS"
.nf
uffizzi preview service logs LOG_TYPE [PREVIEW_ID] [SERVICE] [UFFIZZI_WIDE_FLAG \|\.\|\.\|\.]
.fi
.SH "DESCRIPTION"
.nf
Shows the logs for a given container service of a given preview\.

This command can fail for the following reasons:
\- There is no preview with the given PREVIEW_ID
\- There is no service with the name SERVICE

For more information on service logs, see:
https://docs\.uffizzi\.com/cli
.fi
.SH "LOG_TYPE"
.nf
LOG_TYPE is one of the following:

build
The build logs of a service\.

container
The container logs of a service\.
.fi
.SH "POSITIONAL ARGUMENTS"
.nf
[PREVIEW_ID]
The ID of the preview that includes the service you want to
show logs for\.

[SERVICE]
The name of the service you want to show logs for\.
.fi
.SH "UFFIZZI WIDE FLAGS"
.nf
These flags are available to all commands: \-\-project\. Run $ uffizzi
help for details\.
.fi
.SH "EXAMPLES"
.nf
The following command shows build logs for the service web\-app of the
preview with ID deployment\-14:

$ uffizzi preview service logs build deployment\-14 web\-app

The following command shows container logs for the service postgres\-db of
the preview with ID deployment\-14:

$ uffizzi preview service logs container deployment\-14 postgres\-db
.fi

Loading

0 comments on commit 05850e2

Please sign in to comment.