uffizzi-cli 0.5.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +69 -116
  3. data/config/uffizzi.rb +2 -1
  4. data/exe/uffizzi +1 -1
  5. data/lib/uffizzi/auth_helper.rb +3 -8
  6. data/lib/uffizzi/cli/common.rb +3 -3
  7. data/lib/uffizzi/cli/config.rb +38 -12
  8. data/lib/uffizzi/cli/connect.rb +82 -35
  9. data/lib/uffizzi/cli/disconnect.rb +2 -2
  10. data/lib/uffizzi/cli/login.rb +30 -11
  11. data/lib/uffizzi/cli/logout.rb +3 -3
  12. data/lib/uffizzi/cli/preview/service.rb +12 -11
  13. data/lib/uffizzi/cli/preview.rb +70 -127
  14. data/lib/uffizzi/cli/project/compose.rb +22 -26
  15. data/lib/uffizzi/cli/project/secret.rb +25 -14
  16. data/lib/uffizzi/cli/project.rb +33 -9
  17. data/lib/uffizzi/cli.rb +19 -22
  18. data/lib/uffizzi/clients/api/api_client.rb +108 -63
  19. data/lib/uffizzi/clients/api/api_routes.rb +38 -30
  20. data/lib/uffizzi/clients/api/http_client.rb +47 -45
  21. data/lib/uffizzi/config_file.rb +36 -20
  22. data/lib/uffizzi/date_helper.rb +45 -0
  23. data/lib/uffizzi/response_helper.rb +11 -7
  24. data/lib/uffizzi/services/command_service.rb +9 -0
  25. data/lib/uffizzi/services/compose_file_service.rb +3 -0
  26. data/lib/uffizzi/services/preview_service.rb +109 -0
  27. data/lib/uffizzi/shell.rb +7 -4
  28. data/lib/uffizzi/version.rb +1 -1
  29. data/lib/uffizzi.rb +4 -0
  30. data/man/uffizzi-config +65 -0
  31. data/man/uffizzi-config.html +144 -0
  32. data/man/uffizzi-config.ronn +55 -0
  33. data/man/uffizzi-connect +37 -0
  34. data/man/uffizzi-connect-acr +35 -0
  35. data/man/uffizzi-connect-acr.ronn +28 -0
  36. data/man/uffizzi-connect-docker-hub +34 -0
  37. data/man/uffizzi-connect-docker-hub.ronn +27 -0
  38. data/man/uffizzi-connect-ecr +35 -0
  39. data/man/uffizzi-connect-ecr.ronn +28 -0
  40. data/man/uffizzi-connect-gcr +40 -0
  41. data/man/uffizzi-connect-gcr.ronn +32 -0
  42. data/man/uffizzi-connect-ghcr +35 -0
  43. data/man/uffizzi-connect-ghcr.ronn +28 -0
  44. data/man/uffizzi-connect.ronn +31 -0
  45. data/man/uffizzi-disconnect +37 -0
  46. data/man/uffizzi-disconnect.ronn +31 -0
  47. data/man/uffizzi-login +2 -2
  48. data/man/uffizzi-login.ronn +2 -2
  49. data/man/uffizzi-preview-update +34 -0
  50. data/man/uffizzi-preview-update.ronn +33 -0
  51. data/man/uffizzi-project-set-default +34 -0
  52. data/man/uffizzi-project-set-default.html +111 -0
  53. data/man/uffizzi-project-set-default.ronn +26 -0
  54. metadata +26 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40afcffb213061f1da3d74393c334423329aabc97a7c28587659e7e1acdd704e
4
- data.tar.gz: d2507263bca660a24dfdb6e1ba8927633be123810c58c17df0dfe6618744482f
3
+ metadata.gz: e9ab52c8638dc3d5a8f6245ba337da95fcf986e39040458add0c1128857014f8
4
+ data.tar.gz: b897ce235bc887bd161a7262fecddc28228b523b167338b599051ba370b704d3
5
5
  SHA512:
6
- metadata.gz: c2399f33b5b86bd33f5051ddbaaaccb8116eb00840b64f4b29fdca4be758442d7e6af77306500ba1be34e77f5c7a556cb8ac8be689a4728879b47d558f86d413
7
- data.tar.gz: 8b4078751fc9bdcc38f772af6ef8778de4bff5f61a57020eee5f3c2ff1f8b1c7b26c9b0d1b82d8c0ca8049f10a2cbc3c3280675f3ac7cb4aff162f5921a63c58
6
+ metadata.gz: a2976d6389a9a1d5c9d53ab66e34de98c391b250e2b4e5ebf636189b12f7e7a366e5140ef1c8583ce952d68fd8734600945402b6e38b10dea28700b71eb2bcf6
7
+ data.tar.gz: 78aa15c2dd0f21febc64c73c2a77e86de98ccda9a90278069ced243f3264f74240d5530aa67828515a4e03f858fb3e2d1d5d1713eca63127d027cbd4b3ea89ac
data/README.md CHANGED
@@ -4,22 +4,20 @@ A command-line interace (CLI) for [Uffizzi App](https://github.com/UffizziCloud/
4
4
 
5
5
  ## Uffizzi Overview
6
6
 
7
- Uffizzi is the Full-stack Previews Engine that makes it easy for your team to preview code changes before merging—whether frontend, backend or microserivce. Define your full-stack apps with a familiar syntax based on Docker Compose, and Uffizzi will create on-demand test environments when you open pull requests or build new images. Preview URLs are updated when there’s a new commit, so your team can catch issues early, iterate quickly, and accelerate your release cycles.
7
+ Uffizzi is an open-source engine for creating lightweight, ephemeral test environments for APIs and full-stack applications. Uffizzi enables teams to preview new features before merging and to mitigate the risk of introducing regressions into a codebase. Each preview gets a shareable URL that's updated when you push new commits or image tags, so teams can provide continual feedback during the development/QA process. Previews can be configured to expire or be destroyed when a pull request is closed, so environments exist only as long as they are needed. Uffizzi also helps deconflict shared development environments since previews are deployed as isolated namespaces—there is no risk of clobbering another developer's preview.
8
8
 
9
- ## Getting started with Uffizzi
9
+ While Uffizzi depends on Kubernetes, it does not require end-users to interface with Kubernetes directly. Instead, Uffizzi leverages Docker Compose as its configuration file format, so developers do not need modify Kubernetes manifests or even know about Kubernetes.
10
10
 
11
- The fastest and easiest way to get started with Uffizzi is via the fully hosted version available at https://uffizzi.com, which includes free plans for small teams and qualifying open-source projects.
12
-
13
- Alternatively, you can self-host Uffizzi via the open-source repositories available here on GitHub. The remainder of this README is intended for users interested in self-hosting Uffizzi or for those who are just curious about how Uffizzi works.
11
+ Uffizzi is designed to integrate with any CI/CD system.
14
12
 
15
13
  ## Uffizzi Architecture
14
+ <img src="https://github.com/UffizziCloud/uffizzi_app/blob/main/docs/images/uffizzi-architecture.png" description="Uffizzi Architecture" width="320"/>
16
15
 
17
16
  Uffizzi consists of the following components:
18
17
 
19
18
  - [Uffizzi App](https://github.com/UffizziCloud/uffizzi_app) - The primary REST API for creating and managing Previews
20
19
  - [Uffizzi Controller](https://github.com/UffizziCloud/uffizzi_controller) - A smart proxy service that handles requests from Uffizzi App to the Kubernetes API
21
20
  - Uffizzi CLI (this repository) - A command-line interface for Uffizzi App
22
- - [Uffizzi Dashboard](https://app.uffizzi.com) - A graphical user interface for Uffizzi App, available as a paid service at https://uffizzi.com
23
21
 
24
22
  To host Uffizzi yourself, you will also need the following external dependencies:
25
23
 
@@ -29,198 +27,153 @@ To host Uffizzi yourself, you will also need the following external dependencies
29
27
 
30
28
  ## Installation
31
29
 
32
- Add this line to your application's `Gemfile`:
33
-
34
- ```ruby
35
- gem 'uffizzi-cli'
36
- ```
37
-
38
- And then execute:
39
-
40
- $ bundle install
41
-
42
- Or install it yourself as:
43
-
44
- $ gem install uffizzi-cli
45
-
46
- ### Docker image
30
+ The Uffizzi CLI can be used interactively or as part of an automated workflow (e.g. GitHub Actions). Both options use the `uffizzi/cli` container image available on Docker Hub.
47
31
 
48
- We also provide an image on Docker Hub:
32
+ ### Interactive mode
49
33
 
50
- ```bash
51
- docker run -it --rm uffizzi/cli project list
34
+ Run the CLI as a Docker container in interactive mode:
35
+ ```
36
+ docker run --interactive --rm --tty --entrypoint=sh uffizzi/cli
52
37
  ```
53
38
 
54
39
  If you specify the following environment variables, the Docker image's
55
40
  entrypoint script can log you into Uffizzi before executing your command.
56
41
 
57
42
  - `UFFIZZI_USER`
58
- - `UFFIZZI_HOSTNAME`
43
+ - `UFFIZZI_SERVER`
59
44
  - `UFFIZZI_PASSWORD`
60
45
  - `UFFIZZI_PROJECT` (optional)
61
46
 
62
- ## Development
63
-
64
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
65
-
66
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67
-
68
- Run rubocop:
69
- `bundle exec rubocop -A`
70
-
71
- ## Testing
72
-
73
- Run tests:
74
- `bundle exec rake test`
47
+ ### Automated mode
75
48
 
76
- Run tests from a file:
77
- `bundle exec rake test TEST=test/uffizzi/cli/preview_test.rb`
78
-
79
- Run single test
80
- `bundle exec rake test TEST=test/uffizzi/cli/preview_test.rb TESTOPTS="--name=test_name"`
81
-
82
- ## Commands
83
-
84
- ### login
49
+ If you want to use Uffizzi as part of an automated workflow, you can pass the Uffizzi commands to the Docker run command. For example:
85
50
 
86
51
  ```
87
- $ uffizzi login --user your@email.com --hostname localhost:8080
52
+ docker run -it --rm uffizzi/cli project list
88
53
  ```
89
54
 
90
- Logging you into the app which you set in the hostname option.
91
-
92
- ### login options
55
+ ## Sample commands and examples
93
56
 
94
- | Option | Aliase | Description |
95
- | ------------ | ------ | ------------------------- |
96
- | `--user` | `-u` | Your email for logging in |
97
- | `--hostname` | | Adress of your app |
57
+ ### help
98
58
 
99
- If hostname uses basic authentication you can specify options for it by setting `basic_auth_user` and `basic_auth_password` via `config set` command.
59
+ The `help` subcommand can be used to see more information about a particular command.
100
60
 
101
- ### project
61
+ Examples:
102
62
 
103
63
  ```
104
- $ uffizzi project
64
+ uffizzi help
105
65
  ```
106
66
 
107
- Use this command to configure your projects. This command has 2 subcommands `list` and `compose`.
108
-
109
67
  ```
110
- $ uffizzi project list
68
+ uffizzi preview help
111
69
  ```
112
70
 
113
- Shows all your projects' slugs
114
-
115
- If you have only one project it will be added to your config file automatically, if there's more than one project you need to set up your project manually with the command `uffizzi config set YOUR_PROJECT_SLUG`
116
-
117
- ### compose
118
-
119
71
  ```
120
- $ uffizzi project compose
72
+ uffizzi project compose help
121
73
  ```
122
74
 
123
- That's the subcommand for project command. Use it to configure your compose file. This command has 3 subcommands `set`, `describe` and `unset`.
75
+ ### login
124
76
 
125
77
  ```
126
- $ uffizzi project compose set -f path_to_your_compose_file.yml
78
+ uffizzi login --server=localhost:8080 --username=your@email.com
127
79
  ```
128
80
 
129
- Creates a new or updates existed compose file in uffizzi app for project specified in config file
81
+ Log in to the app with the specified server.
130
82
 
131
- ```
132
- $ uffizzi project compose describe
133
- ```
83
+ #### login options
134
84
 
135
- Shows the content of compose file related to project specified in config file if it's valid or validation errors if it's not
85
+ | Option | Aliase | Description |
86
+ | ------------ | ------ | ------------------------- |
87
+ | `--username` | `-u` | Your email for logging in |
88
+ | `--server` | | The URL of the Uffizzi installation |
136
89
 
137
- ```
138
- $ uffizzi project compose unset
139
- ```
90
+ If server uses basic authentication you can specify options for it by setting `basic_auth_user` and `basic_auth_password` via `config set` command.
140
91
 
141
- Removes compose file related to project specified in config file
92
+ ### config
142
93
 
143
- You need to set project before use any of these commands via `uffizzi config set project YOUR_PROJECT_SLUG` command
94
+ Use this command to configure your cli app.
144
95
 
145
- ### compose options
96
+ ```
97
+ $ uffizzi config
98
+ ```
146
99
 
147
- | Option | Aliase | Description |
148
- | -------- | ------ | ------------------------- |
149
- | `--file` | `-f` | Path to your compose file |
100
+ Launching interactive setup guide that sets the values for `server`, `username` and `project`
150
101
 
151
- ### config
102
+ ### config subcommands
152
103
 
153
- Use this command to configure your cli app. This command has 4 subcommands `list`, `get`, `set`, and `delete`.
104
+ This command has 4 subcommands `list`, `get`, `set`, and `delete`.
154
105
 
155
106
  ```
156
- $ uffizzi config list
107
+ uffizzi config list
157
108
  ```
158
109
 
159
110
  Shows all options and their values from the config file.
160
111
 
161
112
  ```
162
- $ uffizzi config get OPTION
113
+ uffizzi config get-value OPTION
163
114
  ```
164
115
 
165
116
  Shows the value of the specified option.
166
117
 
167
118
  ```
168
- $ uffizzi config set OPTION VALUE
119
+ uffizzi config set OPTION VALUE
169
120
  ```
170
121
 
171
122
  Sets specified value for specified option. If a specified option already exists and has value it will be overwritten.
172
123
 
173
124
  ```
174
- $ uffizzi config delete OPTION
125
+ uffizzi config unset OPTION
175
126
  ```
176
127
 
177
- Deletes specified option.
128
+ Unsets specified option.
178
129
 
179
- ### disconnect ###
130
+ ### project
180
131
 
181
132
  ```
182
- $ uffizzi disconnect CREDENTIAL_TYPE
133
+ uffizzi project
183
134
  ```
184
135
 
185
- Deletes credential of specified type
186
-
187
- Supported credential types - `docker-hub`, `acr`, `ecr`, `gcr`
188
-
189
- ## Generate manual
136
+ Use this command to configure your projects. This command has 2 subcommands `list` and `compose`.
190
137
 
191
- In order to generate a manual, create a `.ronn` file having a name pattern like `uffizzi-{command-name}` (for example `uffizzi-project-compose`) in the `man` directory and run `bundle exec ronn man/{filename}.ronn`
138
+ ```
139
+ uffizzi project list
140
+ ```
192
141
 
193
- ## Git workflow for the app:
142
+ Shows all your projects' slugs
194
143
 
195
- 1. Clone the repository and checkout to `develop` branch
144
+ If you have only one project it will be added to your config file automatically, if there's more than one project you need to set up your project manually with the commands `uffizzi config set YOUR_PROJECT_SLUG` or `uffizzi project set-default YOUR_PROJECT_SLUG`
196
145
 
197
- 2. Pull repository to ensure you have the latest changes
198
146
  ```
199
- git pull --rebase develop
147
+ $ uffizzi project set-default PROJECT_SLUG
200
148
  ```
149
+ Create a preview from a compose file.
150
+
151
+ Sets the default project given with the given project slug. When set, all commands use this project as the default context unless overridden by the --project flag.
152
+
153
+ ### preview
154
+
155
+ Create and manage previews
201
156
 
202
- 3. Start new branch from `develop`
203
157
  ```
204
- git checkout -b feature/short_issue_description (e.g. feature/add_domain_settings)
158
+ uffizzi preview create docker-compose.uffizzi.yml
205
159
  ```
160
+ Create a preview from a compose file.
206
161
 
207
- 4. Make changes you need for the feature, commit them to the repo
208
162
  ```
209
- git add .
210
- git commit -m 'short commit description' (e.g. git commit -m 'added domain settings')
211
- git push origin BRANCH_NAME
163
+ uffizzi preview delete deployment-21
212
164
  ```
165
+ Delete a preview with preview ID `deployment-21`.
213
166
 
214
- 4. You already can create PR with develop branch as a target. Once the feature is ready let us know in the channel - we will review
167
+ ### disconnect
215
168
 
216
- 5. Merge your feature to `qa` branch and push. Ensure your pipeline is successful
217
169
  ```
218
- git checkout qa
219
- git pull --rebase qa
220
- git merge --no-ff BRANCH_NAME
221
- git push origin qa
170
+ uffizzi disconnect CREDENTIAL_TYPE
222
171
  ```
223
172
 
173
+ Deletes credential of specified type
174
+
175
+ Supported credential types - `docker-hub`, `acr`, `ecr`, `gcr`
176
+
224
177
  ## Contributing
225
178
 
226
- Bug reports and pull requests are welcome on GitHub at https://github.com/UffizziCloud/uffizzi_cli.
179
+ Bug reports and pull requests are welcome on GitHub at https://github.com/UffizziCloud/uffizzi_cli. See `CONTRIBUTING.md` in this repository.
data/config/uffizzi.rb CHANGED
@@ -12,7 +12,7 @@ module Uffizzi
12
12
  end
13
13
 
14
14
  configure do |config|
15
- config.hostname = 'http://web:7000'
15
+ config.server = 'http://web:7000'
16
16
  config.credential_types = {
17
17
  dockerhub: 'UffizziCore::Credential::DockerHub',
18
18
  azure: 'UffizziCore::Credential::Azure',
@@ -20,5 +20,6 @@ module Uffizzi
20
20
  amazon: 'UffizziCore::Credential::Amazon',
21
21
  github_container_registry: 'UffizziCore::Credential::GithubContainerRegistry',
22
22
  }
23
+ config.default_server = 'app.uffizzi.com'
23
24
  end
24
25
  end
data/exe/uffizzi CHANGED
@@ -2,4 +2,4 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'uffizzi/cli'
5
- Uffizzi::CLI.start
5
+ Uffizzi::Cli.start
@@ -5,14 +5,9 @@ module Uffizzi
5
5
  class << self
6
6
  def signed_in?
7
7
  ConfigFile.exists? &&
8
- ConfigFile.option_exists?(:account_id) &&
9
- ConfigFile.option_exists?(:cookie) &&
10
- ConfigFile.option_exists?(:hostname)
11
- end
12
-
13
- def project_set?
14
- ConfigFile.exists? &&
15
- ConfigFile.option_exists?(:project)
8
+ ConfigFile.option_has_value?(:account_id) &&
9
+ ConfigFile.option_has_value?(:cookie) &&
10
+ ConfigFile.option_has_value?(:server)
16
11
  end
17
12
  end
18
13
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  require 'open3'
4
4
 
5
- module Cli
6
- class Common
5
+ module Uffizzi
6
+ class Cli::Common
7
7
  class << self
8
8
  def show_manual(command_name)
9
- manual_doc_path = "man/#{command_name}"
9
+ manual_doc_path = File.join(Uffizzi.root, "man/#{command_name}")
10
10
 
11
11
  Open3.pipeline("man #{manual_doc_path}")
12
12
  end
@@ -4,29 +4,38 @@ require 'uffizzi'
4
4
  require 'uffizzi/clients/api/api_client'
5
5
 
6
6
  module Uffizzi
7
- class CLI::Config < Thor
7
+ class Cli::Config < Thor
8
8
  include ApiClient
9
9
 
10
- desc 'list', 'list'
10
+ desc 'list', 'Lists all options and their values from the config file'
11
11
  def list
12
12
  run('list')
13
13
  end
14
14
 
15
- desc 'get [PROPERTY]', 'get'
16
- def get(property)
15
+ desc 'get [PROPERTY]', 'Displays the value of the specified option'
16
+ def get_value(property)
17
17
  run('get', property)
18
18
  end
19
19
 
20
- desc 'set [PROPERTY] [VALUE]', 'set'
20
+ desc 'set [PROPERTY] [VALUE]', 'Sets the value of the specified option'
21
21
  def set(property, value)
22
22
  run('set', property, value)
23
23
  end
24
24
 
25
- desc 'delete [PROPERTY]', 'delete'
26
- def delete(property)
27
- run('delete', property)
25
+ desc 'unset [PROPERTY]', 'Deletes the value of the specified option'
26
+ def unset(property)
27
+ run('unset', property)
28
28
  end
29
29
 
30
+ desc 'setup', 'setup'
31
+ def setup
32
+ run('setup')
33
+ end
34
+
35
+ map('get-value' => :get_value)
36
+
37
+ default_task :setup
38
+
30
39
  private
31
40
 
32
41
  def run(command, property = nil, value = nil)
@@ -37,11 +46,26 @@ module Uffizzi
37
46
  handle_get_command(property)
38
47
  when 'set'
39
48
  handle_set_command(property, value)
40
- when 'delete'
41
- handle_delete_command(property)
49
+ when 'unset'
50
+ handle_unset_command(property)
51
+ when 'setup'
52
+ handle_setup_command
42
53
  end
43
54
  end
44
55
 
56
+ def handle_setup_command
57
+ Uffizzi.ui.say("Configure the default properties that will be used to authenticate with your \
58
+ \nUffizzi API service and manage previews.\n")
59
+ server = Uffizzi.ui.ask('Server: ', default: Uffizzi.configuration.default_server.to_s)
60
+ username = Uffizzi.ui.ask('Username: ')
61
+ project = Uffizzi.ui.ask('Project: ')
62
+ ConfigFile.delete
63
+ ConfigFile.write_option(:server, server)
64
+ ConfigFile.write_option(:username, username)
65
+ ConfigFile.write_option(:project, project)
66
+ Uffizzi.ui.say('To login, run: uffizzi login')
67
+ end
68
+
45
69
  def handle_list_command
46
70
  ConfigFile.list
47
71
  end
@@ -55,10 +79,12 @@ module Uffizzi
55
79
 
56
80
  def handle_set_command(property, value)
57
81
  ConfigFile.write_option(property.to_sym, value)
82
+ Uffizzi.ui.say("Updated property [#{property}]")
58
83
  end
59
84
 
60
- def handle_delete_command(property)
61
- ConfigFile.delete_option(property.to_sym)
85
+ def handle_unset_command(property)
86
+ ConfigFile.unset_option(property.to_sym)
87
+ Uffizzi.ui.say("Unset property [#{property}]")
62
88
  end
63
89
  end
64
90
  end
@@ -3,29 +3,25 @@
3
3
  require 'uffizzi'
4
4
 
5
5
  module Uffizzi
6
- class CLI::Connect
6
+ class Cli::Connect < Thor
7
7
  include ApiClient
8
8
 
9
- def run(credential_type, credential_file_path)
10
- case credential_type
11
- when 'docker-hub'
12
- handle_docker_hub
13
- when 'acr'
14
- handle_azure
15
- when 'ecr'
16
- handle_amazon
17
- when 'ghcr'
18
- handle_github_container_registry
19
- when 'gcr'
20
- handle_google(credential_file_path)
9
+ desc 'list-credentials', 'List existing credentials for an account'
10
+ def list_credentials
11
+ server = ConfigFile.read_option(:server)
12
+ response = fetch_credentials(server)
13
+ if ResponseHelper.ok?(response)
14
+ handle_list_credentials_success(response)
21
15
  else
22
- Uffizzi.ui.say('Unsupported credential type.')
16
+ ResponseHelper.handle_failed_response(response)
23
17
  end
24
18
  end
25
19
 
26
- private
20
+ desc 'docker-hub', 'Connect to Docker Hub (hub.docker.com)'
21
+ def docker_hub
22
+ type = Uffizzi.configuration.credential_types[:dockerhub]
23
+ check_credential_existance(type, 'docker-hub')
27
24
 
28
- def handle_docker_hub
29
25
  username = Uffizzi.ui.ask('Username: ')
30
26
  password = Uffizzi.ui.ask('Password: ', echo: false)
31
27
 
@@ -35,8 +31,8 @@ module Uffizzi
35
31
  type: Uffizzi.configuration.credential_types[:dockerhub],
36
32
  }
37
33
 
38
- hostname = ConfigFile.read_option(:hostname)
39
- response = create_credential(hostname, params)
34
+ server = ConfigFile.read_option(:server)
35
+ response = create_credential(server, params)
40
36
 
41
37
  if ResponseHelper.created?(response)
42
38
  print_success_message('DockerHub')
@@ -45,7 +41,11 @@ module Uffizzi
45
41
  end
46
42
  end
47
43
 
48
- def handle_azure
44
+ desc 'acr', 'Connect to Azure Container Registry (azurecr.io)'
45
+ def acr
46
+ type = Uffizzi.configuration.credential_types[:azure]
47
+ check_credential_existance(type, 'acr')
48
+
49
49
  registry_url = prepare_registry_url(Uffizzi.ui.ask('Registry Domain: '))
50
50
  username = Uffizzi.ui.ask('Docker ID: ')
51
51
  password = Uffizzi.ui.ask('Password/Access Token: ', echo: false)
@@ -54,11 +54,11 @@ module Uffizzi
54
54
  username: username,
55
55
  password: password,
56
56
  registry_url: registry_url,
57
- type: Uffizzi.configuration.credential_types[:azure],
57
+ type: type,
58
58
  }
59
59
 
60
- hostname = ConfigFile.read_option(:hostname)
61
- response = create_credential(hostname, params)
60
+ server = ConfigFile.read_option(:server)
61
+ response = create_credential(server, params)
62
62
 
63
63
  if ResponseHelper.created?(response)
64
64
  print_success_message('ACR')
@@ -67,7 +67,11 @@ module Uffizzi
67
67
  end
68
68
  end
69
69
 
70
- def handle_amazon
70
+ desc 'ecr', 'Connect to Amazon Elastic Container Registry'
71
+ def ecr
72
+ type = Uffizzi.configuration.credential_types[:amazon]
73
+ check_credential_existance(type, 'ecr')
74
+
71
75
  registry_url = prepare_registry_url(Uffizzi.ui.ask('Registry Domain: '))
72
76
  username = Uffizzi.ui.ask('Access key ID: ')
73
77
  password = Uffizzi.ui.ask('Secret access key: ', echo: false)
@@ -76,11 +80,11 @@ module Uffizzi
76
80
  username: username,
77
81
  password: password,
78
82
  registry_url: registry_url,
79
- type: Uffizzi.configuration.credential_types[:amazon],
83
+ type: type,
80
84
  }
81
85
 
82
- hostname = ConfigFile.read_option(:hostname)
83
- response = create_credential(hostname, params)
86
+ server = ConfigFile.read_option(:server)
87
+ response = create_credential(server, params)
84
88
 
85
89
  if ResponseHelper.created?(response)
86
90
  print_success_message('ECR')
@@ -89,7 +93,11 @@ module Uffizzi
89
93
  end
90
94
  end
91
95
 
92
- def handle_google(credential_file_path)
96
+ desc 'gcr', 'Connect to Google Container Registry (gcr.io)'
97
+ def gcr(credential_file_path = nil)
98
+ type = Uffizzi.configuration.credential_types[:google]
99
+ check_credential_existance(type, 'gcr')
100
+
93
101
  return Uffizzi.ui.say('Path to google service account key file wasn\'t specified.') if credential_file_path.nil?
94
102
 
95
103
  begin
@@ -100,11 +108,11 @@ module Uffizzi
100
108
 
101
109
  params = {
102
110
  password: credential_content,
103
- type: Uffizzi.configuration.credential_types[:google],
111
+ type: type,
104
112
  }
105
113
 
106
- hostname = ConfigFile.read_option(:hostname)
107
- response = create_credential(hostname, params)
114
+ server = ConfigFile.read_option(:server)
115
+ response = create_credential(server, params)
108
116
 
109
117
  if ResponseHelper.created?(response)
110
118
  print_success_message('GCR')
@@ -113,26 +121,35 @@ module Uffizzi
113
121
  end
114
122
  end
115
123
 
116
- def handle_github_container_registry
124
+ desc 'ghcr', 'Connect to GitHub Container Registry (ghcr.io)'
125
+ def ghcr
126
+ type = Uffizzi.configuration.credential_types[:github_container_registry]
127
+ check_credential_existance(type, 'gchr')
128
+
117
129
  username = Uffizzi.ui.ask('Github Username: ')
118
130
  password = Uffizzi.ui.ask('Access Token: ', echo: false)
119
131
 
120
132
  params = {
121
133
  username: username,
122
134
  password: password,
123
- type: Uffizzi.configuration.credential_types[:github_container_registry],
135
+ type: type,
124
136
  }
125
137
 
126
- hostname = ConfigFile.read_option(:hostname)
127
- response = create_credential(hostname, params)
138
+ server = ConfigFile.read_option(:server)
139
+ response = create_credential(server, params)
128
140
 
129
141
  if ResponseHelper.created?(response)
130
- print_success_message('GitHub Container Registry')
142
+ print_success_message('GHCR')
131
143
  else
132
144
  ResponseHelper.handle_failed_response(response)
133
145
  end
134
146
  end
135
147
 
148
+ map 'list-credentials' => 'list_credentials'
149
+ map 'docker-hub' => 'docker_hub'
150
+
151
+ private
152
+
136
153
  def prepare_registry_url(registry_url)
137
154
  return registry_url if registry_url.match?(/^(?:http(s)?:\/\/)/)
138
155
 
@@ -142,5 +159,35 @@ module Uffizzi
142
159
  def print_success_message(connection_name)
143
160
  Uffizzi.ui.say("Successfully connected to #{connection_name}")
144
161
  end
162
+
163
+ def check_credential_existance(type, connection_name)
164
+ server = ConfigFile.read_option(:server)
165
+ response = check_credential(server, type)
166
+ return if ResponseHelper.ok?(response)
167
+
168
+ message = "Credentials of type #{connection_name} already exist for this account. " \
169
+ "To remove them, run $ uffizzi disconnect #{connection_name}."
170
+ raise Uffizzi::Error.new(message)
171
+ end
172
+
173
+ def handle_list_credentials_success(response)
174
+ credentials = response[:body][:credentials]
175
+ credentials.each do |credential|
176
+ Uffizzi.ui.say(credential_readable_name(credential))
177
+ end
178
+ end
179
+
180
+ def credential_readable_name(credential)
181
+ map = {
182
+ 'UffizziCore::Credential::DockerHub' => 'docker-hub',
183
+ 'UffizziCore::Credential::Github' => 'github',
184
+ 'UffizziCore::Credential::Azure' => 'acr',
185
+ 'UffizziCore::Credential::Amazon' => 'ecr',
186
+ 'UffizziCore::Credential::GithubContainerRegistry' => 'ghcr',
187
+ 'UffizziCore::Credential::Google' => 'gcr',
188
+ }
189
+
190
+ map[credential]
191
+ end
145
192
  end
146
193
  end