stack_master-http_parameter_resolver 0.1.0 → 0.2.0
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b89594059633e161706bc026846c819415c097796c91c31d1a89afc313728f5a
|
4
|
+
data.tar.gz: bdc13b782a995e1ba77e03d0a366ae2f535d01753217c054641c682a36d47c20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82078bb8899bee49e39899f74d840e1b9f83b9fcb37f6defd366616f3d2bdb7057cf84c4147f5298d6fe8be6837d3fc8207dd7a40f3c8440b7c4da83be92ebf2
|
7
|
+
data.tar.gz: 7751f2b2d6b0b19c0918873e1d443589b619d66a9c0dff25aeac87202f83a7334475e2d07d8b7ead3a7cae5aa00b26c72efd7e9cbde6a720334ef3cd6015460b
|
data/CHANGELOG.md
CHANGED
@@ -7,13 +7,32 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
-
[Unreleased]: https://github.com/envato/stack_master-http_parameter_resolver/compare/v0.
|
10
|
+
[Unreleased]: https://github.com/envato/stack_master-http_parameter_resolver/compare/v0.2.0...HEAD
|
11
|
+
|
12
|
+
## [0.2.0] - 2020-05-25
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
|
16
|
+
- Introduce strategies for parsing the HTTP response ([#2]). This changes how
|
17
|
+
to configure the parameter resolver. eg.
|
18
|
+
|
19
|
+
```diff
|
20
|
+
cloudflare_cidr_ips:
|
21
|
+
- http: https://www.cloudflare.com/ips-v4
|
22
|
+
+ http:
|
23
|
+
+ url: https://www.cloudflare.com/ips-v4
|
24
|
+
+ strategy: one_per_line
|
25
|
+
```
|
26
|
+
|
27
|
+
[0.2.0]: https://github.com/envato/stack_master-http_parameter_resolver/compare/v0.1.0...v0.2.0
|
28
|
+
[#2]: https://github.com/envato/stack_master-http_parameter_resolver/pull/2
|
11
29
|
|
12
30
|
## [0.1.0] - 2020-01-14
|
13
31
|
|
14
32
|
### Added
|
15
33
|
|
16
34
|
- Initial functionality: Obtaining parameters from HTTP calls returning plain
|
17
|
-
text.
|
35
|
+
text, ([#1]).
|
18
36
|
|
19
|
-
[
|
37
|
+
[0.1.0]: https://github.com/envato/stack_master-http_parameter_resolver/tree/v0.1.0
|
38
|
+
[#1]: https://github.com/envato/stack_master-http_parameter_resolver/pull/1
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# StackMaster::HttpParameterResolver
|
2
2
|
|
3
|
+
[![License MIT](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/envato/stack_master-http_parameter_resolver/blob/master/LICENSE.txt)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/stack_master-http_parameter_resolver.svg)](https://rubygems.org/gems/stack_master-http_parameter_resolver)
|
3
5
|
[![Build Status](https://travis-ci.org/envato/stack_master-http_parameter_resolver.svg?branch=master)](https://travis-ci.org/envato/stack_master-http_parameter_resolver)
|
4
6
|
|
5
7
|
A [StackMaster] parameter resolver that obtains values via HTTP calls.
|
@@ -16,11 +18,15 @@ gem 'stack_master-http_parameter_resolver'
|
|
16
18
|
|
17
19
|
And then execute:
|
18
20
|
|
19
|
-
|
21
|
+
```sh
|
22
|
+
bundle install
|
23
|
+
```
|
20
24
|
|
21
25
|
Or install it yourself as:
|
22
26
|
|
23
|
-
|
27
|
+
```sh
|
28
|
+
gem install stack_master-http_parameter_resolver
|
29
|
+
```
|
24
30
|
|
25
31
|
## Usage
|
26
32
|
|
@@ -28,15 +34,21 @@ For example, to resolve the Cloudflare IPv4 ranges:
|
|
28
34
|
|
29
35
|
```yaml
|
30
36
|
cloudflare_ips:
|
31
|
-
http:
|
37
|
+
http:
|
38
|
+
url: https://www.cloudflare.com/ips-v4
|
39
|
+
strategy: one_per_line
|
32
40
|
```
|
33
41
|
|
34
42
|
To obtain both the Cloudlare IPv4 and IPv6 ranges:
|
35
43
|
|
36
44
|
```yaml
|
37
45
|
cloudflare_ips:
|
38
|
-
- http:
|
39
|
-
|
46
|
+
- http:
|
47
|
+
url: https://www.cloudflare.com/ips-v4
|
48
|
+
strategy: one_per_line
|
49
|
+
- http:
|
50
|
+
url: https://www.cloudflare.com/ips-v6
|
51
|
+
strategy: one_per_line
|
40
52
|
```
|
41
53
|
|
42
54
|
## Development
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StackMaster
|
4
|
+
module HttpParameterResolver
|
5
|
+
module Strategy
|
6
|
+
class OnePerLine
|
7
|
+
def accept
|
8
|
+
'text/plain'
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse(response)
|
12
|
+
response.body.split(/[\r\n]+/)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,30 +1,66 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_support/core_ext/string/inflections'
|
3
4
|
require 'faraday'
|
4
5
|
|
6
|
+
Dir[File.join(__dir__, '..', 'http_parameter_resolver', 'strategy', '**', '*.rb')]
|
7
|
+
.sort.each { |file| require file }
|
8
|
+
|
5
9
|
module StackMaster
|
6
10
|
module ParameterResolvers
|
7
11
|
class Http < Resolver
|
8
12
|
NotResolved = Class.new(StandardError)
|
13
|
+
Misconfigured = Class.new(StandardError)
|
9
14
|
|
10
15
|
array_resolver
|
11
16
|
|
12
17
|
def initialize(_config, _stack_definition); end
|
13
18
|
|
14
|
-
def resolve(
|
15
|
-
|
16
|
-
|
19
|
+
def resolve(args)
|
20
|
+
usage unless args.is_a? Hash
|
21
|
+
url = args.fetch('url') { usage("'url' not provided") }
|
22
|
+
strategy = build_strategy(args.fetch('strategy') { usage("'strategy' not provided") })
|
23
|
+
http(url, strategy)
|
17
24
|
rescue Faraday::Error
|
18
25
|
raise NotResolved, "Unable to resolve HTTP parameters from #{url}"
|
19
26
|
end
|
20
27
|
|
21
28
|
private
|
22
29
|
|
23
|
-
def
|
30
|
+
def usage(message = 'Misconfigured HTTP parameter resolver')
|
31
|
+
raise Misconfigured, <<~MESSAGE
|
32
|
+
#{message}
|
33
|
+
|
34
|
+
Please configure according to the following pattern:
|
35
|
+
|
36
|
+
<my-parameter-name>:
|
37
|
+
http:
|
38
|
+
url: <my-http-url>
|
39
|
+
strategy: <response-parsing-strategy>
|
40
|
+
|
41
|
+
Where <response-parsing-strategy> is one of the supported strategies:
|
42
|
+
- one_per_line
|
43
|
+
MESSAGE
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_strategy(strategy)
|
47
|
+
class_name = "StackMaster::HttpParameterResolver::Strategy::"\
|
48
|
+
"#{strategy.classify}"
|
49
|
+
class_name.constantize.new
|
50
|
+
rescue NameError
|
51
|
+
usage("The strategy #{strategy.inspect} is not supported")
|
52
|
+
end
|
53
|
+
|
54
|
+
def http(url, strategy)
|
55
|
+
response = connection(url, strategy).get
|
56
|
+
strategy.parse(response)
|
57
|
+
end
|
58
|
+
|
59
|
+
def connection(url, strategy)
|
24
60
|
Faraday.new(
|
25
61
|
url: url,
|
26
62
|
params: {},
|
27
|
-
headers: { 'Accept' =>
|
63
|
+
headers: { 'Accept' => strategy.accept }
|
28
64
|
) do |connection|
|
29
65
|
connection.response :raise_error
|
30
66
|
connection.adapter :net_http
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stack_master-http_parameter_resolver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Envato
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: faraday
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,6 +105,7 @@ files:
|
|
91
105
|
- LICENSE.txt
|
92
106
|
- README.md
|
93
107
|
- lib/stack_master/http_parameter_resolver.rb
|
108
|
+
- lib/stack_master/http_parameter_resolver/strategy/one_per_line.rb
|
94
109
|
- lib/stack_master/http_parameter_resolver/version.rb
|
95
110
|
- lib/stack_master/parameter_resolvers/http.rb
|
96
111
|
homepage: https://github.com/envato/stack_master-http_parameter_resolver
|
@@ -100,8 +115,8 @@ metadata:
|
|
100
115
|
homepage_uri: https://github.com/envato/stack_master-http_parameter_resolver
|
101
116
|
bug_tracker_uri: https://github.com/envato/stack_master-http_parameter_resolver/issues
|
102
117
|
changelog_uri: https://github.com/envato/stack_master-http_parameter_resolver/blob/master/CHANGELOG.md
|
103
|
-
documentation_uri: https://www.rubydoc.info/gems/stack_master-http_parameter_resolver/0.
|
104
|
-
source_code_uri: https://github.com/envato/stack_master-http_parameter_resolver/tree/v0.
|
118
|
+
documentation_uri: https://www.rubydoc.info/gems/stack_master-http_parameter_resolver/0.2.0
|
119
|
+
source_code_uri: https://github.com/envato/stack_master-http_parameter_resolver/tree/v0.2.0
|
105
120
|
post_install_message:
|
106
121
|
rdoc_options: []
|
107
122
|
require_paths:
|
@@ -117,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
132
|
- !ruby/object:Gem::Version
|
118
133
|
version: '0'
|
119
134
|
requirements: []
|
120
|
-
rubygems_version: 3.1.
|
135
|
+
rubygems_version: 3.1.3
|
121
136
|
signing_key:
|
122
137
|
specification_version: 4
|
123
138
|
summary: Obtain stack parameters from HTTP calls.
|