3scale_toolbox 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -144
  3. data/lib/3scale_toolbox.rb +0 -1
  4. data/lib/3scale_toolbox/commands.rb +12 -0
  5. data/lib/3scale_toolbox/commands/3scale_command.rb +1 -1
  6. data/lib/3scale_toolbox/commands/account_command.rb +23 -0
  7. data/lib/3scale_toolbox/commands/account_command/find_command.rb +41 -0
  8. data/lib/3scale_toolbox/commands/activedocs_command.rb +32 -0
  9. data/lib/3scale_toolbox/commands/activedocs_command/apply_command.rb +127 -0
  10. data/lib/3scale_toolbox/commands/activedocs_command/create_command.rb +65 -0
  11. data/lib/3scale_toolbox/commands/activedocs_command/delete_command.rb +49 -0
  12. data/lib/3scale_toolbox/commands/activedocs_command/list_command.rb +54 -0
  13. data/lib/3scale_toolbox/commands/application_command.rb +30 -0
  14. data/lib/3scale_toolbox/commands/application_command/apply_command.rb +179 -0
  15. data/lib/3scale_toolbox/commands/application_command/create_command.rb +110 -0
  16. data/lib/3scale_toolbox/commands/application_command/delete_command.rb +57 -0
  17. data/lib/3scale_toolbox/commands/application_command/list_command.rb +124 -0
  18. data/lib/3scale_toolbox/commands/application_command/show_command.rb +72 -0
  19. data/lib/3scale_toolbox/commands/copy_command/copy_service.rb +97 -28
  20. data/lib/3scale_toolbox/commands/import_command/import_csv.rb +16 -17
  21. data/lib/3scale_toolbox/commands/import_command/openapi.rb +14 -10
  22. data/lib/3scale_toolbox/commands/import_command/openapi/create_service_step.rb +3 -2
  23. data/lib/3scale_toolbox/commands/import_command/openapi/method.rb +0 -1
  24. data/lib/3scale_toolbox/commands/import_command/openapi/step.rb +8 -1
  25. data/lib/3scale_toolbox/commands/import_command/openapi/update_service_proxy_step.rb +17 -7
  26. data/lib/3scale_toolbox/commands/methods_command.rb +4 -4
  27. data/lib/3scale_toolbox/commands/methods_command/apply_command.rb +2 -2
  28. data/lib/3scale_toolbox/commands/methods_command/create_command.rb +1 -1
  29. data/lib/3scale_toolbox/commands/metrics_command.rb +4 -4
  30. data/lib/3scale_toolbox/commands/metrics_command/apply_command.rb +2 -2
  31. data/lib/3scale_toolbox/commands/metrics_command/create_command.rb +1 -1
  32. data/lib/3scale_toolbox/commands/plans_command/apply_command.rb +7 -7
  33. data/lib/3scale_toolbox/commands/plans_command/create_command.rb +5 -5
  34. data/lib/3scale_toolbox/commands/policy_registry_command.rb +22 -0
  35. data/lib/3scale_toolbox/commands/policy_registry_command/copy_command.rb +85 -0
  36. data/lib/3scale_toolbox/commands/proxy_config_command.rb +30 -0
  37. data/lib/3scale_toolbox/commands/proxy_config_command/list_command.rb +78 -0
  38. data/lib/3scale_toolbox/commands/proxy_config_command/promote_command.rb +68 -0
  39. data/lib/3scale_toolbox/commands/proxy_config_command/show_command.rb +88 -0
  40. data/lib/3scale_toolbox/commands/service_command.rb +34 -0
  41. data/lib/3scale_toolbox/commands/service_command/apply_command.rb +77 -0
  42. data/lib/3scale_toolbox/commands/service_command/create_command.rb +59 -0
  43. data/lib/3scale_toolbox/commands/service_command/delete_command.rb +49 -0
  44. data/lib/3scale_toolbox/commands/service_command/list_command.rb +50 -0
  45. data/lib/3scale_toolbox/commands/service_command/show_command.rb +63 -0
  46. data/lib/3scale_toolbox/commands/update_command/update_service.rb +6 -3
  47. data/lib/3scale_toolbox/entities.rb +4 -0
  48. data/lib/3scale_toolbox/entities/account.rb +63 -0
  49. data/lib/3scale_toolbox/entities/activedocs.rb +88 -0
  50. data/lib/3scale_toolbox/entities/application.rb +124 -0
  51. data/lib/3scale_toolbox/entities/application_plan.rb +28 -4
  52. data/lib/3scale_toolbox/entities/base_entity.rb +44 -0
  53. data/lib/3scale_toolbox/entities/proxy_config.rb +58 -0
  54. data/lib/3scale_toolbox/entities/service.rb +42 -8
  55. data/lib/3scale_toolbox/error.rb +8 -0
  56. data/lib/3scale_toolbox/tasks.rb +2 -1
  57. data/lib/3scale_toolbox/tasks/bump_proxy_version_task.rb +32 -0
  58. data/lib/3scale_toolbox/tasks/copy_service_settings_task.rb +38 -0
  59. data/lib/3scale_toolbox/version.rb +1 -1
  60. metadata +36 -5
  61. data/lib/3scale_toolbox/tasks/update_service_settings_task.rb +0 -49
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7b198d2a14662823d04de18bf2cc15b4e08b8b18e9900c888e54d2f7a72a3bb
4
- data.tar.gz: fcda8a6926e72cd0a44485f912fc89debd59369e3296420c172f1a899546688b
3
+ metadata.gz: 5b92f14c66af8c902ae8c68e2052f1fa95fa251eff222665f69e8758a5c4fae5
4
+ data.tar.gz: 77193321a8835f5e55276a6e454765c4a66f00b42af58a9d2ccecd3a60359804
5
5
  SHA512:
6
- metadata.gz: 95cbd6fb8d874ea31120d282d67ba5c61d3c5ef0a1d5df844844b7b0dfb8fd266dc0b62d486c2152896a692ff2243ee132a1617fc0ec07a94b21a13fab4251f9
7
- data.tar.gz: 93a97483feb149fd5fc27049d75a883f8cae1bf95787e0b80cae14585db37396f46d55b7ef8614a016fd73c25e552a2bc82ea625c48ec6c502e07709fd12458c
6
+ metadata.gz: bc467460e0db0d22ac18d8c5e8265bc9e3fd6fbb154f0f58d3b222b03a1d1d05980f16d9f21e9414822702bf119e7d6207282a57198af7344e9bf71d335df2d9
7
+ data.tar.gz: e24bc998136917729814dfcf634e9da8c68a20a6987f5a2080aff6811605904dc160ec1e763e2f06870e0062633f1a8f0abf21145b6cc074fac249ea71afb14e
data/README.md CHANGED
@@ -11,14 +11,18 @@ See the LICENSE and NOTICE files that should have been provided along with this
11
11
  ## Table of contents
12
12
  * [Installation](#installation)
13
13
  * [Usage](#usage)
14
- * [Copy a service](#copy-a-service)
15
- * [Update a service](#update-a-service)
16
- * [Import from CSV](#import-from-csv)
14
+ * [Copy a service](docs/copy-service.md)
15
+ * [Import from CSV](docs/import-csv.md)
17
16
  * [Import from OpenAPI definition](docs/openapi.md)
18
17
  * [Export/Import Application Plan](docs/export-import-app-plan.md)
19
18
  * Create, Apply, List, Show, Delete [Application plan](docs/app-plan.md)
20
19
  * Create, Apply, List, Delete [Metric](docs/metric.md)
21
20
  * Create, Apply, List, Delete [Method](docs/method.md)
21
+ * Create, Apply, List, Show, Delete [Service](docs/service.md)
22
+ * Create, Apply, List, Delete [ActiveDocs](docs/activedocs.md)
23
+ * List, Show, Promote [Proxy Configuration](docs/proxy-config.md)
24
+ * [Copy Policy Registry](docs/copy-policy-registry.md)
25
+ * Create, Apply, List, Show, Delete, Suspend, Resume [Applications](docs/applications.md)
22
26
  * [Remotes](docs/remotes.md)
23
27
  * [Development](#development)
24
28
  * [Testing](#testing)
@@ -46,11 +50,20 @@ DESCRIPTION
46
50
  3scale toolbox to manage your API from the terminal.
47
51
 
48
52
  COMMANDS
49
- copy copy super command
50
- help show help
51
- import import super command
52
- remote remotes super command
53
- update update super command
53
+ account account super command
54
+ activedocs activedocs super command
55
+ application application super command
56
+ application-plan application-plan super command
57
+ copy copy super command
58
+ help show help
59
+ import import super command
60
+ method method super command
61
+ metric metric super command
62
+ policy-registry policy-registry super command
63
+ proxy-config proxy-config super command
64
+ remote remotes super command
65
+ service services super command
66
+ update update super command
54
67
 
55
68
  OPTIONS
56
69
  -c --config-file=<value> 3scale toolbox configuration file (default:
@@ -62,142 +75,6 @@ OPTIONS
62
75
  --verbose Verbose mode
63
76
  ```
64
77
 
65
- ### Copy a service
66
- Will create a new service, copy existing proxy settings, pricing rules, activedocs, metrics, methods, application plans and mapping rules.
67
-
68
- 3scale instances can be either a [URL](docs/remotes.md#remote-urls) or the name of a [remote](docs/remotes.md).
69
-
70
- Help message:
71
-
72
- ```shell
73
- $ 3scale copy service --help
74
- NAME
75
- service - Copy service
76
-
77
- USAGE
78
- 3scale copy service [opts] -s <src> -d <dst>
79
- <service_id>
80
-
81
- DESCRIPTION
82
- Will create a new services, copy existing proxy settings, metrics,
83
- methods, policies, application plans and mapping rules.
84
-
85
- OPTIONS
86
- -d --destination=<value> 3scale target instance. Url or
87
- remote name
88
- -s --source=<value> 3scale source instance. Url or
89
- remote name
90
- -t --target_system_name=<value> Target system name. Default to
91
- source system name
92
-
93
- OPTIONS FOR COPY
94
- -h --help show help for this command
95
- -k --insecure Proceed and operate even for server
96
- connections otherwise considered
97
- insecure
98
- -v --version Prints the version of this command
99
- --verbose Verbose mode
100
- ```
101
-
102
- ```shell
103
- 3scale copy service NUMBER --source=foo --destination=https://access_token@foo2-admin.3scale.net
104
- ```
105
-
106
- ### Update a service
107
-
108
- Will update existing service, update proxy settings, pricing rules, activedocs, metrics, methods, application plans and mapping rules.
109
-
110
- 3scale instances can be either a [URL](docs/remotes.md#remote-urls) or the name of a [remote](docs/remotes.md).
111
-
112
- Help message:
113
-
114
- ```shell
115
- NAME
116
- service - Update service
117
-
118
- USAGE
119
- 3scale update service [opts] -s <src> -d <dst>
120
- <src_service_id> <dst_service_id>
121
-
122
- DESCRIPTION
123
- Will update existing service, update proxy settings, metrics, methods,
124
- application plans, policies and mapping rules.
125
-
126
- OPTIONS
127
- -d --destination=<value> 3scale target instance. Url or
128
- remote name
129
- -f --force Overwrites the mapping rules by deleting
130
- all rules from target service first
131
- -r --rules-only Updates only the mapping rules
132
- -s --source=<value> 3scale source instance. Url or
133
- remote name
134
-
135
- OPTIONS FOR UPDATE
136
- -h --help show help for this command
137
- -k --insecure Proceed and operate even for server
138
- connections otherwise considered insecure
139
- -v --version Prints the version of this command
140
- --verbose Verbose mode
141
- ```
142
-
143
- Example:
144
-
145
- ```shell
146
- $ 3scale update service -s https://9874598743@source.example.com -d foo 3 2
147
- ```
148
-
149
- ### Import from CSV
150
-
151
- Will create new services, metrics, methods, and mapping rules having as source comma separated values (CSV) formatted file.
152
-
153
- 3scale instances can be either a [URL](docs/remotes.md#remote-urls) or the name of a [remote](docs/remotes.md).
154
-
155
- CSV header
156
-
157
- ```csv
158
- service_name,endpoint_name,endpoint_http_method,endpoint_path,auth_mode,endpoint_system_name,type
159
- ```
160
-
161
- File example
162
-
163
- ```csv
164
- service_name,endpoint_name,endpoint_http_method,endpoint_path,auth_mode,endpoint_system_name,type
165
- Movies ,Movies (Biography),GET,/movies/biography/,api_key,movies_biography,metric
166
- Movies ,Movies (Drama),GET,/movies/drama/,api_key,movies_drama,method
167
- ```
168
-
169
- Help message:
170
-
171
- ```shell
172
- $ 3scale import csv -h
173
- NAME
174
- csv - Import csv file
175
-
176
- USAGE
177
- 3scale import csv [opts] -d <dst> -f <file>
178
-
179
- DESCRIPTION
180
- Create new services, metrics, methods and mapping rules from CSV
181
- formatted file
182
-
183
- OPTIONS
184
- -d --destination=<value> 3scale target instance. Url or remote name
185
- -f --file=<value> CSV formatted file
186
-
187
- OPTIONS FOR IMPORT
188
- -h --help show help for this command
189
- -k --insecure Proceed and operate even for server
190
- connections otherwise considered insecure
191
- -v --version Prints the version of this command
192
- --verbose Verbose mode
193
- ```
194
-
195
- Example:
196
-
197
- ```shell
198
- 3scale import csv --destination=https://provider_key@user-admin.3scale.net --file=examples/import_example.csv
199
- ```
200
-
201
78
  ## Development
202
79
 
203
80
  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.
@@ -23,7 +23,6 @@ require '3scale_toolbox/commands'
23
23
  require '3scale_toolbox/cli'
24
24
 
25
25
  module ThreeScaleToolbox
26
-
27
26
  def self.load_plugins
28
27
  plugin_paths.each { |plugin_path| require plugin_path }
29
28
  end
@@ -7,6 +7,12 @@ require '3scale_toolbox/commands/remote_command'
7
7
  require '3scale_toolbox/commands/plans_command'
8
8
  require '3scale_toolbox/commands/metrics_command'
9
9
  require '3scale_toolbox/commands/methods_command'
10
+ require '3scale_toolbox/commands/service_command'
11
+ require '3scale_toolbox/commands/activedocs_command'
12
+ require '3scale_toolbox/commands/account_command'
13
+ require '3scale_toolbox/commands/proxy_config_command'
14
+ require '3scale_toolbox/commands/policy_registry_command'
15
+ require '3scale_toolbox/commands/application_command'
10
16
 
11
17
  module ThreeScaleToolbox
12
18
  module Commands
@@ -19,6 +25,12 @@ module ThreeScaleToolbox
19
25
  ThreeScaleToolbox::Commands::PlansCommand,
20
26
  ThreeScaleToolbox::Commands::MetricsCommand,
21
27
  ThreeScaleToolbox::Commands::MethodsCommand,
28
+ ThreeScaleToolbox::Commands::ServiceCommand,
29
+ ThreeScaleToolbox::Commands::ActiveDocsCommand,
30
+ ThreeScaleToolbox::Commands::AccountCommand,
31
+ ThreeScaleToolbox::Commands::ProxyConfigCommand,
32
+ ThreeScaleToolbox::Commands::PolicyRegistryCommand,
33
+ ThreeScaleToolbox::Commands::ApplicationCommand,
22
34
  ].freeze
23
35
  end
24
36
  end
@@ -10,7 +10,7 @@ module ThreeScaleToolbox
10
10
  summary '3scale toolbox'
11
11
  description '3scale toolbox to manage your API from the terminal.'
12
12
  option :c, 'config-file', '3scale toolbox configuration file',
13
- argument: :required, default: ThreeScaleToolbox.default_config_file
13
+ argument: :required, default: ThreeScaleToolbox.default_config_file
14
14
  flag :v, :version, 'Prints the version of this command' do
15
15
  puts ThreeScaleToolbox::VERSION
16
16
  exit 0
@@ -0,0 +1,23 @@
1
+ require '3scale_toolbox/commands/account_command/find_command'
2
+
3
+ module ThreeScaleToolbox
4
+ module Commands
5
+ module AccountCommand
6
+ include ThreeScaleToolbox::Command
7
+
8
+ def self.command
9
+ Cri::Command.define do
10
+ name 'account'
11
+ usage 'acccount <sub-command> [options]'
12
+ summary 'account super command'
13
+ description 'Accounts commands'
14
+
15
+ run do |_opts, _args, cmd|
16
+ puts cmd.help
17
+ end
18
+ end
19
+ end
20
+ add_subcommand(Find::FindSubcommand)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,41 @@
1
+ require 'cri'
2
+ require '3scale_toolbox/base_command'
3
+
4
+ module ThreeScaleToolbox
5
+ module Commands
6
+ module AccountCommand
7
+ module Find
8
+ class FindSubcommand < Cri::CommandRunner
9
+ include ThreeScaleToolbox::Command
10
+
11
+ def self.command
12
+ Cri::Command.define do
13
+ name 'find'
14
+ usage 'find [opts] <remote> <text>'
15
+ summary 'find account'
16
+ description 'Find account by email, provider key or service token'
17
+
18
+ option :a, :'print-all', 'Print all the account info', argument: :forbidden
19
+ param :remote
20
+ param :text
21
+
22
+ runner FindSubcommand
23
+ end
24
+ end
25
+
26
+ def run
27
+ client = threescale_client(arguments[:remote])
28
+ account = ThreeScaleToolbox::Entities::Account.find_by_text(arguments[:text], client)
29
+ if account.nil?
30
+ puts 'Account not found'
31
+ return
32
+ end
33
+
34
+ account.verbose = options[:'print-all']
35
+ puts account
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,32 @@
1
+ require 'cri'
2
+ require '3scale_toolbox/base_command'
3
+ require '3scale_toolbox/commands/activedocs_command/delete_command'
4
+ require '3scale_toolbox/commands/activedocs_command/create_command'
5
+ require '3scale_toolbox/commands/activedocs_command/apply_command'
6
+ require '3scale_toolbox/commands/activedocs_command/list_command'
7
+
8
+ module ThreeScaleToolbox
9
+ module Commands
10
+ module ActiveDocsCommand
11
+ include ThreeScaleToolbox::Command
12
+
13
+ def self.command
14
+ Cri::Command.define do
15
+ name 'activedocs'
16
+ usage 'activedocs <sub-command> [options]'
17
+ summary 'activedocs super command'
18
+ description 'Manage your ActiveDocs'
19
+
20
+ run do |_opts, _args, cmd|
21
+ puts cmd.help
22
+ end
23
+ end
24
+ end
25
+
26
+ add_subcommand(Delete::DeleteSubcommand)
27
+ add_subcommand(Create::CreateSubcommand)
28
+ add_subcommand(Apply::ApplySubcommand)
29
+ add_subcommand(List::ListSubcommand)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,127 @@
1
+ module ThreeScaleToolbox
2
+ module Commands
3
+ module ActiveDocsCommand
4
+ module Apply
5
+ class ApplySubcommand < Cri::CommandRunner
6
+ include ThreeScaleToolbox::Command
7
+ include ThreeScaleToolbox::ResourceReader
8
+
9
+ def self.command
10
+ Cri::Command.define do
11
+ name 'apply'
12
+ usage 'apply <remote> <activedocs_id_or_system_name>'
13
+ summary 'Update activedocs'
14
+ description 'Create or update an ActiveDocs'
15
+ runner ApplySubcommand
16
+
17
+ param :remote
18
+ param :activedocs_id_or_system_name
19
+
20
+ option :i, :'service-id', "Specify the Service ID associated to the ActiveDocs", argument: :required
21
+ option :p, :'publish', "Specify it to publish the ActiveDocs on the Developer Portal. Otherwise it will be hidden", argument: :forbidden
22
+ option nil, :'hide', "Specify it to hide the ActiveDocs on the Developer Portal", argument: :forbidden
23
+ option nil, :'skip-swagger-validations', "Specify it to skip validation of the Swagger specification", argument: :forbidden
24
+ option :d, :'description', "Specify the description of the ActiveDocs", argument: :required
25
+ option :s, :'name', "Specify the name of the ActiveDocs", argument: :required
26
+ option nil, :'openapi-spec', "Specify the swagger spec. Can be a file, an URL or '-' to read from stdin. This option is mandatory when applying the ActiveDoc for the first time", argument: :required
27
+ end
28
+ end
29
+
30
+ def run
31
+ res = activedocs
32
+ validate_option_params
33
+ if !res
34
+ res = Entities::ActiveDocs::create(remote: remote, attrs: create_activedocs_attrs)
35
+ else
36
+ res.update(activedocs_attrs) unless activedocs_attrs.empty?
37
+ end
38
+
39
+ output_msg_array = ["Applied ActiveDocs id: #{res.id}"]
40
+ output_msg_array << "Published" if option_publish
41
+ output_msg_array << "Hidden" if option_hide
42
+ puts output_msg_array.join(";")
43
+ end
44
+
45
+ private
46
+
47
+ def remote
48
+ @remote ||= threescale_client(arguments[:remote])
49
+ end
50
+
51
+ def validate_option_params
52
+ if option_publish && option_hide
53
+ raise ThreeScaleToolbox::Error.new("--publish and --hide are mutually exclusive")
54
+ end
55
+ end
56
+
57
+ def check_openapi_spec_defined
58
+ if !option_openapi_spec
59
+ raise ThreeScaleToolbox::Error.new("--openapi-spec is mandatory when ActiveDocs is created")
60
+ end
61
+ end
62
+
63
+ def activedocs
64
+ @activedocs ||= find_activedocs
65
+ end
66
+
67
+ def ref
68
+ arguments[:activedocs_id_or_system_name]
69
+ end
70
+
71
+ def find_activedocs
72
+ Entities::ActiveDocs.find(remote: remote, ref: ref)
73
+ end
74
+
75
+ def option_publish
76
+ options.fetch(:publish, false)
77
+ end
78
+
79
+ def option_hide
80
+ options.fetch(:hide, false)
81
+ end
82
+
83
+ def option_openapi_spec
84
+ options[:'openapi-spec']
85
+ end
86
+
87
+ def activedocs_json_spec
88
+ @json_spec ||= read_activedocs_json_spec
89
+ end
90
+
91
+ def read_activedocs_json_spec
92
+ activedoc_spec = option_openapi_spec
93
+ activedoc_spec_content = load_resource(activedoc_spec)
94
+ JSON.pretty_generate(activedoc_spec_content)
95
+ end
96
+
97
+ def activedocs_attrs
98
+ activedocs_basic_attrs.tap do |params|
99
+ params["body"] = activedocs_json_spec if !option_openapi_spec.nil?
100
+ params["published"] = true if option_publish
101
+ params["published"] = false if option_hide
102
+ end
103
+ end
104
+
105
+ def activedocs_basic_attrs
106
+ {
107
+ "service_id" => options[:'service-id'],
108
+ "skip_swagger_validations" => options[:'skip-swagger-validations'],
109
+ "description" => options[:'description'],
110
+ "system_name" => options[:'system-name'],
111
+ "name" => options[:name],
112
+ }.compact
113
+ end
114
+
115
+ def create_activedocs_attrs
116
+ check_openapi_spec_defined
117
+ activedocs_attrs.merge(
118
+ "system_name" => ref,
119
+ "name" => ref,
120
+ "body" => activedocs_json_spec,
121
+ ) { |_key, oldval, _newval| oldval } # receiver of the merge message has key priority
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end