Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
* Create, Apply, List, Delete [Method](docs/method.md)
* Create, Apply, List, Show, Delete [Service](docs/service.md)
* Create, Apply, List, Delete [ActiveDocs](docs/activedocs.md)
* List, Show, Promote, Export, Deploy [Proxy Configuration](docs/proxy-config.md)
* Show, Update, Deploy [APIcast proxy settings](docs/proxy.md)
* List, Show, Promote, Export [Staging/Production Proxy Configuration](docs/proxy-config.md)
* [Copy Policy Registry](docs/copy-policy-registry.md)
* Create, Apply, List, Show, Delete, Suspend, Resume [Applications](docs/applications.md)
* [Export/Import Product Policy Chain](docs/export-import-policy-chain.md)
Expand Down Expand Up @@ -86,6 +87,7 @@ COMMANDS
policies policies super command
policy-registry policy-registry super command
product product super command
proxy proxy super command
proxy-config proxy-config super command
remote remotes super command
service services super command
Expand Down
7 changes: 6 additions & 1 deletion docs/proxy-config.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
## Proxy Configuration

Commands to manage the proxy configuration for a given environment (staging/production).

* [List Proxy Configurations](#list)
* [Show Proxy Configuration](#show)
* [Promote Proxy Configuration](#promote)
* [Export Proxy Configuration](#export)
* [Deploy Proxy Configuration](#deploy)
* ~[Deploy Proxy Configuration](#deploy)~(**deprecated**)

### List

Expand Down Expand Up @@ -81,6 +83,9 @@ OPTIONS

### Deploy

*This command has been deprecated.*
*[Check out the new proxy deploy command](proxy.md#deploy)*

```shell
NAME
deploy - Promotes the APIcast configuration to the Staging Environment
Expand Down
68 changes: 68 additions & 0 deletions docs/proxy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
## Proxy Configuration

* [Deploy Proxy Configuration](#deploy)
* [Update Proxy Configuration](#update)
* [Show Proxy Configuration](#show)

### Deploy

```shell
NAME
deploy - Promotes the APIcast configuration to the Staging Environment

USAGE
3scale proxy deploy <remote> <service>

DESCRIPTION
Promotes the APIcast configuration to the Staging Environment (Production
Environment in case of Service Mesh).

OPTIONS
-o --output=<value> Output format. One of: json|yaml
```

### Update

Update APIcast configuration command. Only specified parameters will be updated.

Check out 3scale API docs (*https://tenant-admin.3scale.example.com/admin/api-docs*) **Proxy Update** doc
for a list of valid APIcast parameters.

Example:

```shel
3scale proxy update supertest api -p credentials_location=query -p error_status_auth_failed=500 -p 'error_auth_failed=Authentication failed oohhh'
```

```shell
NAME
update - Update APIcast configuration

USAGE
3scale proxy update <remote> <service>

DESCRIPTION
Update APIcast configuration

OPTIONS
-o --output=<value> Output format. One of: json|yaml
-p --param=<value> APIcast configuration parameters. Format:
[--param key=value]. Multiple options
allowed.
```

### Show

```shell
NAME
show - Fetch (undeployed) APIcast configuration

USAGE
3scale proxy show <remote> <service>

DESCRIPTION
Fetch (undeployed) APIcast configuration

OPTIONS
-o --output=<value> Output format. One of: json|yaml
```
2 changes: 2 additions & 0 deletions lib/3scale_toolbox/commands.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require '3scale_toolbox/commands/3scale_command'
require '3scale_toolbox/commands/proxy_command'
require '3scale_toolbox/commands/help_command'
require '3scale_toolbox/commands/import_command'
require '3scale_toolbox/commands/update_command'
Expand Down Expand Up @@ -37,6 +38,7 @@ module Commands
ThreeScaleToolbox::Commands::BackendCommand,
ThreeScaleToolbox::Commands::ProductCommand,
ThreeScaleToolbox::Commands::PoliciesCommand,
ThreeScaleToolbox::Commands::ProxyCommand,
].freeze
end
end
28 changes: 28 additions & 0 deletions lib/3scale_toolbox/commands/proxy_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require '3scale_toolbox/commands/proxy_command/update_command'
require '3scale_toolbox/commands/proxy_command/deploy_command'
require '3scale_toolbox/commands/proxy_command/show_command'

module ThreeScaleToolbox
module Commands
module ProxyCommand
include ThreeScaleToolbox::Command

def self.command
Cri::Command.define do
name 'proxy'
usage 'proxy <sub-command> [options]'
summary 'proxy super command'
description 'APIcast configuration commands'

run do |_opts, _args, cmd|
puts cmd.help
end
end
end

add_subcommand(UpdateSubcommand)
add_subcommand(DeploySubcommand)
add_subcommand(ShowSubcommand)
end
end
end
54 changes: 54 additions & 0 deletions lib/3scale_toolbox/commands/proxy_command/deploy_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module ThreeScaleToolbox
module Commands
module ProxyCommand
class DeploySubcommand < Cri::CommandRunner
include ThreeScaleToolbox::Command

def self.command
Cri::Command.define do
name 'deploy'
usage 'deploy <remote> <service>'
summary 'Promotes the APIcast configuration to the Staging Environment'
description 'Promotes the APIcast configuration to the Staging Environment (Production Environment in case of Service Mesh).'

param :remote
param :service_ref

ThreeScaleToolbox::CLI.output_flag(self)

runner DeploySubcommand
end
end

def run
printer.print_record service.proxy_deploy
end

private

def remote
@remote ||= threescale_client(arguments[:remote])
end

def service_ref
arguments[:service_ref]
end

def find_service
Entities::Service.find(remote: remote,
ref: service_ref).tap do |svc|
raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
end
end

def service
@service ||= find_service
end

def printer
options.fetch(:output, CLI::JsonPrinter.new)
end
end
end
end
end
54 changes: 54 additions & 0 deletions lib/3scale_toolbox/commands/proxy_command/show_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module ThreeScaleToolbox
module Commands
module ProxyCommand
class ShowSubcommand < Cri::CommandRunner
include ThreeScaleToolbox::Command

def self.command
Cri::Command.define do
name 'show'
usage 'show <remote> <service>'
summary 'Fetch (undeployed) APIcast configuration'
description 'Fetch (undeployed) APIcast configuration'

param :remote
param :service_ref

ThreeScaleToolbox::CLI.output_flag(self)

runner ShowSubcommand
end
end

def run
printer.print_record service.proxy
end

private

def remote
@remote ||= threescale_client(arguments[:remote])
end

def service_ref
arguments[:service_ref]
end

def find_service
Entities::Service.find(remote: remote,
ref: service_ref).tap do |svc|
raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
end
end

def service
@service ||= find_service
end

def printer
options.fetch(:output, CLI::JsonPrinter.new)
end
end
end
end
end
75 changes: 75 additions & 0 deletions lib/3scale_toolbox/commands/proxy_command/update_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
module ThreeScaleToolbox
module Commands
module ProxyCommand
class UpdateSubcommand < Cri::CommandRunner
include ThreeScaleToolbox::Command

class ProxyParamTransformer
def call(param_str)
params = param_str.split('=', 2)

raise ArgumentError unless params.compact.length == 2

raise ArgumentError unless !params[0].empty? && !params[1].empty?

{ params[0] => params[1] }
end
end

def self.command
Cri::Command.define do
name 'update'
usage 'update <remote> <service>'
summary 'Update APIcast configuration'
description 'Update APIcast configuration'

param :remote
param :service_ref

ThreeScaleToolbox::CLI.output_flag(self)
option :p, :param, 'APIcast configuration parameters. Format: [--param key=value]. Multiple options allowed. ', argument: :required, multiple: true, transform: ProxyParamTransformer.new

runner UpdateSubcommand
end
end

def run
raise ThreeScaleToolbox::Error, 'APIcast configuration parameters required' if proxy_attrs.empty?

printer.print_record(service.update_proxy(proxy_attrs))
end

private

def remote
@remote ||= threescale_client(arguments[:remote])
end

def service_ref
arguments[:service_ref]
end

def find_service
Entities::Service.find(remote: remote,
ref: service_ref).tap do |svc|
raise ThreeScaleToolbox::Error, "Service #{service_ref} does not exist" if svc.nil?
end
end

def service
@service ||= find_service
end

def proxy_attrs
(options[:param] || []).inject({}) do |acc, s|
acc.merge!(s)
end
end

def printer
options.fetch(:output, CLI::JsonPrinter.new)
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def self.command
Cri::Command.define do
name 'deploy'
usage 'deploy <remote> <service>'
summary 'Promotes the APIcast configuration to the Staging Environment'
description 'Promotes the APIcast configuration to the Staging Environment (Production Environment in case of Service Mesh).'
summary '[DEPRECATED] Promotes the APIcast configuration to the Staging Environment'
description '[DEPRECATED] Promotes the APIcast configuration to the Staging Environment (Production Environment in case of Service Mesh).'

param :remote
param :service_ref
Expand All @@ -21,6 +21,7 @@ def self.command
end

def run
warn "\e[1m\e[31mThis command has been deprecated. Use '3scale proxy deploy' instead\e[0m"
printer.print_record service.proxy_deploy
end

Expand Down
26 changes: 26 additions & 0 deletions spec/unit/commands/proxy_command/deploy_command_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
RSpec.describe ThreeScaleToolbox::Commands::ProxyCommand::DeploySubcommand do
context '#run' do
let(:remote) { instance_double(ThreeScale::API::Client) }
let(:remote_name) { 'myremote' }
let(:service_ref) { 'myservice' }
let(:service_id) { 1 }
let(:arguments) { {remote: remote_name, service_ref: service_ref} }
let(:options) { {} }
let(:proxy_attrs) { { 'id' => '1' } }
let(:pretty_printed_proxy) { JSON.pretty_generate(proxy_attrs) + "\n" }
let(:service_class) { class_double(ThreeScaleToolbox::Entities::Service).as_stubbed_const }
let(:service) { instance_double(ThreeScaleToolbox::Entities::Service) }

subject { described_class.new(options, arguments, nil) }

before :example do
expect(subject).to receive(:threescale_client).with(remote_name).and_return(remote)
expect(service_class).to receive(:find).with(remote: remote, ref: service_ref).and_return(service)
expect(service).to receive(:proxy_deploy).and_return(proxy_attrs)
end

it 'promotes APIcast configuration to staging' do
expect { subject.run }.to output(pretty_printed_proxy).to_stdout
end
end
end
Loading