Skip to content

Commit

Permalink
Merge pull request #137 from 3scale/crud-metrics
Browse files Browse the repository at this point in the history
Crud metrics
  • Loading branch information
eguzki authored May 14, 2019
2 parents 087b7f2 + 030c57c commit b8a155b
Show file tree
Hide file tree
Showing 111 changed files with 2,889 additions and 528 deletions.
2 changes: 1 addition & 1 deletion 3scale_toolbox.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'webmock', '~> 3.4'
spec.required_ruby_version = '>= 2.4'

spec.add_dependency '3scale-api', '~> 0.3.0'
spec.add_dependency '3scale-api', '~> 0.4.0'
spec.add_dependency 'cri', '~> 2.15'
spec.add_dependency 'json-schema', '~> 2.8'
end
28 changes: 5 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ See the LICENSE and NOTICE files that should have been provided along with this
* [Copy a service](#copy-a-service)
* [Update a service](#update-a-service)
* [Import from CSV](#import-from-csv)
* [Import from OpenAPI definition](#import-openapi)
* [Export/Import Application Plan](#export-import-application-plan)
* [Import from OpenAPI definition](docs/openapi.md)
* [Export/Import Application Plan](docs/export-import-app-plan.md)
* Create, Apply, List, Show, Delete [Application plan](docs/app-plan.md)
* [Remotes](#remotes)
* Create, Apply, List, Delete [Metric](docs/metric.md)
* Create, Apply, List, Delete [Method](docs/method.md)
* [Remotes](docs/remotes.md)
* [Development](#development)
* [Testing](#testing)
* [Develop your own core command](#develop-core-command)
Expand Down Expand Up @@ -196,26 +198,6 @@ Example:
3scale import csv --destination=https://[email protected] --file=examples/import_example.csv
```

### Import OpenAPI

Using an API definition format like OpenAPI, import to your 3scale API

Currently, only OpenAPI __2.0__ specification (f.k.a. __swagger__) is supported.

[Import from OpenAPI](docs/openapi.md)

### Export Import Application Plan

A single application plan can be exported/imported as `yaml` format.

[Export/Import Application Plan](docs/export-import-app-plan.md)

### Remotes

Manage set of 3scale instances.

[Howto](docs/remotes.md)

## Development

After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec 3scale` to use the gem in this directory, ignoring other installed copies of this gem.
Expand Down
2 changes: 1 addition & 1 deletion docs/app-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ NAME

USAGE
3scale application-plan create [opts] <remote>
<service> <plan_name>
<service> <plan-name>

DESCRIPTION
Create application plan
Expand Down
126 changes: 126 additions & 0 deletions docs/method.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
## Method

* [Create new method](#create)
* [Apply method](#apply)
* [List methods](#list)
* [Delete method](#delete)

### Create

* Creates a new method
* Only method name is required. `system-name` can be override with optional parameter.
* `service` positional argument is a service reference. It can be either service `id`, or service `system_name`. Toolbox will figure it out.
* This is not idempotent command. If method with the same name already exists, command will fail.
* Create a `disabled` method by `--disabled` flag. By default, it will be `enabled`.
* Several other options can be set. Check `usage`

```shell
NAME
create - create method

USAGE
3scale methods create [opts] <remote>
<service> <method-name>

DESCRIPTION
Create method

OPTIONS
--description=<value> Method description
--disabled Disables this method in all application
plans
-t --system-name=<value> Method system name

OPTIONS FOR METHODS
-c --config-file=<value> 3scale toolbox configuration file (default:
$HOME/.3scalerc.yaml)
-h --help show help for this command
-k --insecure Proceed and operate even for server
connections otherwise considered insecure
-v --version Prints the version of this command
--verbose Verbose mode
```

### Apply

* Update existing method. Create new one if it does not exist.
* `service` positional argument is a service reference. It can be either service `id`, or service `system_name`. Toolbox will figure it out.
* `method` positional argument is a method reference. It can be either method `id`, or method `system_name`. Toolbox will figure it out.
* This is command is `idempotent`.
* Update to `disabled` method by `--disabled` flag.
* Update to `enabled` method by `--enabled` flag.
* Several other options can be set. Check `usage`

```shell
NAME
apply - Update method

USAGE
3scale methods apply [opts] <remote> <service>
<method>

DESCRIPTION
Update (create if it does not exist) method

OPTIONS
--description=<value> Method description
--disabled Disables this method in all application
plans
--enabled Enables this method in all application
plans
-n --name=<value> Method name

OPTIONS FOR METHODS
-c --config-file=<value> 3scale toolbox configuration file (default:
$HOME/.3scalerc.yaml)
-h --help show help for this command
-k --insecure Proceed and operate even for server
connections otherwise considered insecure
-v --version Prints the version of this command
--verbose Verbose mode
```
### List
```shell
NAME
list - list methods

USAGE
3scale methods list [opts] <remote> <service>

DESCRIPTION
List methods

OPTIONS FOR METHODS
-c --config-file=<value> 3scale toolbox configuration file (default:
$HOME/.3scalerc.yaml)
-h --help show help for this command
-k --insecure Proceed and operate even for server
connections otherwise considered insecure
-v --version Prints the version of this command
--verbose Verbose mode
```
### Delete
```shell
NAME
delete - delete method

USAGE
3scale methods delete [opts] <remote>
<service> <method>

DESCRIPTION
Delete method

OPTIONS FOR METHODS
-c --config-file=<value> 3scale toolbox configuration file (default:
$HOME/.3scalerc.yaml)
-h --help show help for this command
-k --insecure Proceed and operate even for server
connections otherwise considered insecure
-v --version Prints the version of this command
--verbose Verbose mode
```
128 changes: 128 additions & 0 deletions docs/metric.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
## Metric

* [Create new metric](#create)
* [Apply metric](#apply)
* [List metrics](#list)
* [Delete metric](#delete)

### Create

* Creates a new metric
* Only metric name is required. `system-name` can be override with optional parameter.
* `service` positional argument is a service reference. It can be either service `id`, or service `system_name`. Toolbox will figure it out.
* This is not idempotent command. If metric with the same name already exists, command will fail.
* Create a `disabled` metric by `--disabled` flag. By default, it will be `enabled`.
* Several other options can be set. Check `usage`

```shell
NAME
create - create metric

USAGE
3scale metrics create [opts] <remote>
<service> <metric-name>

DESCRIPTION
Create metric

OPTIONS
--description=<value> Metric description
--disabled Disables this metric in all application
plans
-t --system-name=<value> Application plan system name
--unit=<value> Metric unit. Default hit

OPTIONS FOR METRICS
-c --config-file=<value> 3scale toolbox configuration file (default:
$HOME/.3scalerc.yaml)
-h --help show help for this command
-k --insecure Proceed and operate even for server
connections otherwise considered insecure
-v --version Prints the version of this command
--verbose Verbose mode
```

### Apply

* Update existing metric. Create new one if it does not exist.
* `service` positional argument is a service reference. It can be either service `id`, or service `system_name`. Toolbox will figure it out.
* `metric` positional argument is a metric reference. It can be either metric `id`, or metric `system_name`. Toolbox will figure it out.
* This is command is `idempotent`.
* Update to `disabled` metric by `--disabled` flag.
* Update to `enabled` metric by `--enabled` flag.
* Several other options can be set. Check `usage`

```shell
NAME
apply - Update metric

USAGE
3scale metrics apply [opts] <remote> <service>
<metric>

DESCRIPTION
Update (create if it does not exist) metric

OPTIONS
--description=<value> Metric description
--disabled Disables this metric in all application
plans
--enabled Enables this metric in all application
plans
-n --name=<value> Metric name
--unit=<value> Metric unit. Default hit

OPTIONS FOR METRICS
-c --config-file=<value> 3scale toolbox configuration file (default:
$HOME/.3scalerc.yaml)
-h --help show help for this command
-k --insecure Proceed and operate even for server
connections otherwise considered insecure
-v --version Prints the version of this command
--verbose Verbose mode
```
### List
```shell
NAME
list - list metrics

USAGE
3scale metrics list [opts] <remote> <service>

DESCRIPTION
List metrics

OPTIONS FOR METRICS
-c --config-file=<value> 3scale toolbox configuration file (default:
$HOME/.3scalerc.yaml)
-h --help show help for this command
-k --insecure Proceed and operate even for server
connections otherwise considered insecure
-v --version Prints the version of this command
--verbose Verbose mode
```
### Delete
```shell
NAME
delete - delete metric

USAGE
3scale metrics delete [opts] <remote>
<service> <metric>

DESCRIPTION
Delete metric

OPTIONS FOR METRICS
-c --config-file=<value> 3scale toolbox configuration file (default:
$HOME/.3scalerc.yaml)
-h --help show help for this command
-k --insecure Proceed and operate even for server
connections otherwise considered insecure
-v --version Prints the version of this command
--verbose Verbose mode
```
1 change: 0 additions & 1 deletion lib/3scale_toolbox/base_command.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

module ThreeScaleToolbox
module Command
def self.included(base)
Expand Down
4 changes: 4 additions & 0 deletions lib/3scale_toolbox/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
require '3scale_toolbox/commands/update_command'
require '3scale_toolbox/commands/remote_command'
require '3scale_toolbox/commands/plans_command'
require '3scale_toolbox/commands/metrics_command'
require '3scale_toolbox/commands/methods_command'

module ThreeScaleToolbox
module Commands
Expand All @@ -15,6 +17,8 @@ module Commands
ThreeScaleToolbox::Commands::UpdateCommand,
ThreeScaleToolbox::Commands::RemoteCommand::RemoteCommand,
ThreeScaleToolbox::Commands::PlansCommand,
ThreeScaleToolbox::Commands::MetricsCommand,
ThreeScaleToolbox::Commands::MethodsCommand,
].freeze
end
end
2 changes: 1 addition & 1 deletion lib/3scale_toolbox/commands/copy_command/copy_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def run

source_service = Entities::Service.new(id: arguments[:service_id],
remote: threescale_client(source))
target_service = create_new_service(source_service.show_service, destination)
target_service = create_new_service(source_service.attrs, destination)
puts "new service id #{target_service.id}"
context = create_context(source_service, target_service)
tasks = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def call
private

def activedocs_system_name
@activedocs_system_name ||= service.show_service['system_name']
@activedocs_system_name ||= service.attrs['system_name']
end

def find_activedocs_id
Expand All @@ -53,7 +53,7 @@ def rewritten_openapi
# Other processing steps can work with original openapi spec
Helper.hash_deep_dup(resource).tap do |activedocs|
# public production base URL
URI(service.show_proxy.fetch('endpoint')).tap do |uri|
URI(service.proxy.fetch('endpoint')).tap do |uri|
activedocs['host'] = "#{uri.host}:#{uri.port}"
activedocs['schemes'] = [uri.scheme]
end
Expand Down
Loading

0 comments on commit b8a155b

Please sign in to comment.