kongrations 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 545381fabd1ab7b6df0c4bc5fb341a1ee96ec2b1
4
- data.tar.gz: d0bbcc1e92fcb6c7a4ab792342be7e2ab0dbe467
3
+ metadata.gz: 0a6b4698c320f5a9ee42b313bb7222fca9dfd58e
4
+ data.tar.gz: 7b1005bfd77f063993db018c99ecc70af80c26a6
5
5
  SHA512:
6
- metadata.gz: 0a095700de6afeca8fc6bf31ad638661845fa8add224e576219209a8db4a6f8629ad30ebe68be931f64a325dabd02aec2fe56b36f5fee4028dea53aee2630047
7
- data.tar.gz: b34226c452f75a3cf5419aaaa859fee3d494c88d57857572fedda15a0c1545a026b340a1bba2335c6cb2d9d9951c8a4cf9470cb1be59519236863dfefd706f97
6
+ metadata.gz: 415697a6fc249d1930e7de92a84110ee2edf1a9c6ebdbb075ef85599b15e3e7ab2aa8c3304fe96ea6c9d55d466c8fff2934b2dfbb617c08aa62f07e401549cf9
7
+ data.tar.gz: 85884f80f4e7d461dd8ef7e18174e1edd7dd29190a97cc7c6b0c126c8c77ee9b8f4fee4541cd670622b417cf5a2c87163451d6035cea48261c3c4e569be95845
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  .env
2
2
  migrations-data/
3
3
  kongrations.yml
4
+ Gemfile.lock
5
+ coverage
@@ -1,7 +1,7 @@
1
1
  AllCops:
2
2
  Exclude:
3
3
  - './spec/fixtures/migrations/**/*.rb'
4
- TargetRubyVersion: 2.4
4
+ TargetRubyVersion: 2.2
5
5
  DisplayCopNames: true
6
6
 
7
7
  Style/Encoding:
@@ -0,0 +1,21 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ - 2.3.7
5
+ - 2.4.4
6
+ - ruby-head
7
+
8
+ before_install:
9
+ - gem update bundler
10
+
11
+ before_script:
12
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
13
+ - chmod +x ./cc-test-reporter
14
+ - ./cc-test-reporter before-build
15
+
16
+ script:
17
+ - bundle exec rubocop
18
+ - bundle exec rspec
19
+
20
+ after_script:
21
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Kongrations
2
2
 
3
+ [![Build Status](https://travis-ci.org/danilospa/kongrations.svg?branch=master)](https://travis-ci.org/danilospa/kongrations)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/90e3435368aaf9b4023a/maintainability)](https://codeclimate.com/github/danilospa/kongrations/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/90e3435368aaf9b4023a/test_coverage)](https://codeclimate.com/github/danilospa/kongrations/test_coverage)
6
+
3
7
  ## Description
4
8
 
5
9
  Kongrations is a migrations like for [Kong](https://github.com/Kong/kong) APIs and its associations like consumers and plugins.
@@ -66,7 +70,7 @@ config_env 'production' do |env|
66
70
  env.retries = 2
67
71
  end
68
72
 
69
- create__api do |api|
73
+ create_api do |api|
70
74
  api.payload = {
71
75
  name: 'my-api',
72
76
  uris: '/myapi',
@@ -86,6 +90,9 @@ Every request body described oh the Kong Admin API documentation must be set usi
86
90
 
87
91
  After running the migration, Kongrations create a file on `./migrations-data` for each Kong environment to store its state. This file should be commited into your version control system. Also, it's extremely important not to touch this file directly, since it's crucial for Kongrations to work normally.
88
92
 
93
+ Place your migration files inside `./migrations` folder. You can change the default folder putting a `path` key on `kongrations.yml` file.
94
+ You also need to use `.rb` extension on them.
95
+
89
96
  To run the migrations, use Kongrations cli, passing an optional parameter to specify the environment name (default environment name is `default`).
90
97
  Examples:
91
98
  ```shell
@@ -132,6 +139,41 @@ end
132
139
  delete_api 'api-name'
133
140
  ```
134
141
 
142
+ #### Create consumer
143
+
144
+ - [Kong Admin API Reference](https://getkong.org/docs/0.13.x/admin-api/#create-consumer)
145
+ - Usage: pass the request body through `consumer.payload`.
146
+ - Example:
147
+ ```ruby
148
+ create_consumer do |consumer|
149
+ consumer.payload = {
150
+ username: 'my-username'
151
+ }
152
+ end
153
+ ```
154
+
155
+ #### Update Consumer
156
+
157
+ - [Kong Admin API Reference](https://getkong.org/docs/0.13.x/admin-api/#update-consumer)
158
+ - Usage: pass your consumer username or custom_id right after `change_consumer` method, then pass the request body through `consumer.payload`.
159
+ - Example:
160
+ ```ruby
161
+ change_consumer 'username' do |consumer|
162
+ consumer.payload = {
163
+ username: 'new-username'
164
+ }
165
+ end
166
+ ```
167
+
168
+ #### Delete Consumer
169
+
170
+ - [Kong Admin API Reference](https://getkong.org/docs/0.13.x/admin-api/#delete-consumer)
171
+ - Usage: pass your username or custom_id right after `delete_consumer` method.
172
+ - Example:
173
+ ```ruby
174
+ delete_consumer 'username'
175
+ ```
176
+
135
177
  #### Create Plugin
136
178
 
137
179
  - [Kong Admin API Reference](https://getkong.org/docs/0.13.x/admin-api/#add-plugin)
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.executables << 'kongrations'
20
20
 
21
+ spec.required_ruby_version = '>= 2.2'
21
22
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
22
23
  f.match(%r{^(test|spec|features)/})
23
24
  end
@@ -28,5 +29,6 @@ Gem::Specification.new do |spec|
28
29
  spec.add_development_dependency 'rake', '~> 10.0'
29
30
  spec.add_development_dependency 'rspec', '3.7.0'
30
31
  spec.add_development_dependency 'rubocop', '0.54.0'
32
+ spec.add_development_dependency 'simplecov', '0.16.1'
31
33
  spec.add_development_dependency 'webmock', '3.3.0'
32
34
  end
@@ -5,7 +5,7 @@ require 'erb'
5
5
 
6
6
  module Kongrations
7
7
  module CurrentEnvironment
8
- FILE_NAME = 'kongrations.yml'
8
+ FILE_NAME = 'kongrations.yml'.freeze
9
9
 
10
10
  def self.load!(name)
11
11
  yaml = File.read(FILE_NAME)
@@ -43,6 +43,22 @@ module Kongrations
43
43
  DeleteApiRequest.new(name)
44
44
  end
45
45
 
46
+ def create_consumer
47
+ create_consumer_request = CreateConsumerRequest.new
48
+ yield(create_consumer_request)
49
+ create_consumer_request
50
+ end
51
+
52
+ def change_consumer(username)
53
+ change_consumer_request = ChangeConsumerRequest.new(username)
54
+ yield(change_consumer_request)
55
+ change_consumer_request
56
+ end
57
+
58
+ def delete_consumer(username)
59
+ DeleteConsumerRequest.new(username)
60
+ end
61
+
46
62
  def create_plugin_for_api(api_name)
47
63
  create_plugin_request = CreatePluginRequest.new(api_name)
48
64
  yield(create_plugin_request)
@@ -7,7 +7,7 @@ module Kongrations
7
7
  using HashExt
8
8
 
9
9
  module MigrationData
10
- PATH = './migrations-data'
10
+ PATH = './migrations-data'.freeze
11
11
 
12
12
  def self.load!
13
13
  @data = File.exist?(file_name) ? JSON.parse(File.read(file_name)) : {}
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kongrations/request'
4
+
5
+ module Kongrations
6
+ class ChangeConsumerRequest < Request
7
+ attr_accessor :username
8
+
9
+ def initialize(username)
10
+ @username = username
11
+ end
12
+
13
+ def path
14
+ "/consumers/#{username}"
15
+ end
16
+
17
+ def method
18
+ :patch
19
+ end
20
+ end
21
+ end
@@ -12,7 +12,7 @@ module Kongrations
12
12
  end
13
13
 
14
14
  def path
15
- plugin_id = migration_data[api_name]['plugins'][plugin_name]
15
+ plugin_id = migration_data['apis'][api_name]['plugins'][plugin_name]
16
16
  "/apis/#{api_name}/plugins/#{plugin_id}"
17
17
  end
18
18
 
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kongrations/request'
4
+
5
+ module Kongrations
6
+ class CreateConsumerRequest < Request
7
+ def path
8
+ '/consumers'
9
+ end
10
+
11
+ def method
12
+ :post
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kongrations/request'
4
+
5
+ module Kongrations
6
+ class DeleteConsumerRequest < Request
7
+ attr_accessor :username
8
+
9
+ def initialize(username)
10
+ @username = username
11
+ end
12
+
13
+ def path
14
+ "/consumers/#{username}"
15
+ end
16
+
17
+ def method
18
+ :delete
19
+ end
20
+ end
21
+ end
@@ -9,9 +9,11 @@ module Kongrations
9
9
  plugin_name = @request.payload[:name]
10
10
  plugin_id = body[:id]
11
11
  {
12
- api_name => {
13
- 'plugins' => {
14
- plugin_name => plugin_id
12
+ 'apis' => {
13
+ api_name => {
14
+ 'plugins' => {
15
+ plugin_name => plugin_id
16
+ }
15
17
  }
16
18
  }
17
19
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kongrations
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kongrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Albuquerque
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-06 00:00:00.000000000 Z
11
+ date: 2018-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.54.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.16.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.16.1
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: webmock
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -107,8 +121,8 @@ files:
107
121
  - ".gitignore"
108
122
  - ".rspec"
109
123
  - ".rubocop.yml"
124
+ - ".travis.yml"
110
125
  - Gemfile
111
- - Gemfile.lock
112
126
  - LICENSE.txt
113
127
  - README.md
114
128
  - Rakefile
@@ -122,10 +136,13 @@ files:
122
136
  - lib/kongrations/migration_data.rb
123
137
  - lib/kongrations/request.rb
124
138
  - lib/kongrations/requests/change_api_request.rb
139
+ - lib/kongrations/requests/change_consumer_request.rb
125
140
  - lib/kongrations/requests/change_plugin_request.rb
126
141
  - lib/kongrations/requests/create_api_request.rb
142
+ - lib/kongrations/requests/create_consumer_request.rb
127
143
  - lib/kongrations/requests/create_plugin_request.rb
128
144
  - lib/kongrations/requests/delete_api_request.rb
145
+ - lib/kongrations/requests/delete_consumer_request.rb
129
146
  - lib/kongrations/requests/delete_plugin_request.rb
130
147
  - lib/kongrations/response.rb
131
148
  - lib/kongrations/responses/create_plugin_response.rb
@@ -142,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
159
  requirements:
143
160
  - - ">="
144
161
  - !ruby/object:Gem::Version
145
- version: '0'
162
+ version: '2.2'
146
163
  required_rubygems_version: !ruby/object:Gem::Requirement
147
164
  requirements:
148
165
  - - ">="
@@ -1,69 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- kongrations (0.1.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- addressable (2.5.2)
10
- public_suffix (>= 2.0.2, < 4.0)
11
- ast (2.4.0)
12
- coderay (1.1.2)
13
- crack (0.4.3)
14
- safe_yaml (~> 1.0.0)
15
- diff-lcs (1.3)
16
- hashdiff (0.3.7)
17
- method_source (0.9.0)
18
- parallel (1.12.1)
19
- parser (2.5.0.4)
20
- ast (~> 2.4.0)
21
- powerpack (0.1.1)
22
- pry (0.11.3)
23
- coderay (~> 1.1.0)
24
- method_source (~> 0.9.0)
25
- public_suffix (3.0.2)
26
- rainbow (3.0.0)
27
- rake (10.5.0)
28
- rspec (3.7.0)
29
- rspec-core (~> 3.7.0)
30
- rspec-expectations (~> 3.7.0)
31
- rspec-mocks (~> 3.7.0)
32
- rspec-core (3.7.1)
33
- rspec-support (~> 3.7.0)
34
- rspec-expectations (3.7.0)
35
- diff-lcs (>= 1.2.0, < 2.0)
36
- rspec-support (~> 3.7.0)
37
- rspec-mocks (3.7.0)
38
- diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.7.0)
40
- rspec-support (3.7.1)
41
- rubocop (0.54.0)
42
- parallel (~> 1.10)
43
- parser (>= 2.5)
44
- powerpack (~> 0.1)
45
- rainbow (>= 2.2.2, < 4.0)
46
- ruby-progressbar (~> 1.7)
47
- unicode-display_width (~> 1.0, >= 1.0.1)
48
- ruby-progressbar (1.9.0)
49
- safe_yaml (1.0.4)
50
- unicode-display_width (1.3.0)
51
- webmock (3.3.0)
52
- addressable (>= 2.3.6)
53
- crack (>= 0.3.2)
54
- hashdiff
55
-
56
- PLATFORMS
57
- ruby
58
-
59
- DEPENDENCIES
60
- bundler (~> 1.16)
61
- kongrations!
62
- pry (= 0.11.3)
63
- rake (~> 10.0)
64
- rspec (= 3.7.0)
65
- rubocop (= 0.54.0)
66
- webmock (= 3.3.0)
67
-
68
- BUNDLED WITH
69
- 1.16.0