scalingo 3.0.0.beta.2 → 3.0.0.beta.3
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/CHANGELOG.md +11 -0
- data/README.md +4 -14
- data/lib/scalingo/api/client.rb +38 -10
- data/lib/scalingo/api/endpoint.rb +12 -2
- data/lib/scalingo/api/response.rb +7 -1
- data/lib/scalingo/auth/keys.rb +4 -4
- data/lib/scalingo/auth/scm_integrations.rb +4 -4
- data/lib/scalingo/auth/tokens.rb +6 -6
- data/lib/scalingo/auth/two_factor_auth.rb +4 -4
- data/lib/scalingo/auth/user.rb +2 -2
- data/lib/scalingo/bearer_token.rb +15 -0
- data/lib/scalingo/billing/profile.rb +3 -3
- data/lib/scalingo/client.rb +26 -113
- data/lib/scalingo/configuration.rb +7 -36
- data/lib/scalingo/core_client.rb +106 -0
- data/lib/scalingo/regional/addons.rb +21 -8
- data/lib/scalingo/regional/apps.rb +8 -8
- data/lib/scalingo/regional/collaborators.rb +4 -4
- data/lib/scalingo/regional/containers.rb +4 -4
- data/lib/scalingo/regional/deployments.rb +3 -3
- data/lib/scalingo/regional/domains.rb +5 -5
- data/lib/scalingo/regional/environment.rb +6 -6
- data/lib/scalingo/regional/events.rb +4 -4
- data/lib/scalingo/regional/logs.rb +2 -2
- data/lib/scalingo/regional/metrics.rb +2 -2
- data/lib/scalingo/regional/notifiers.rb +7 -7
- data/lib/scalingo/regional/operations.rb +1 -1
- data/lib/scalingo/regional/scm_repo_links.rb +8 -8
- data/lib/scalingo/token_holder.rb +31 -0
- data/lib/scalingo/version.rb +1 -1
- data/samples/regional/addons/token-200.json +49 -0
- data/samples/regional/addons/token-404.json +24 -0
- data/scalingo.gemspec +1 -1
- data/spec/scalingo/api/client_spec.rb +58 -11
- data/spec/scalingo/api/endpoint_spec.rb +3 -2
- data/spec/scalingo/api/response_spec.rb +16 -16
- data/spec/scalingo/auth_spec.rb +1 -1
- data/spec/scalingo/billing_spec.rb +11 -0
- data/spec/scalingo/configuration_spec.rb +32 -30
- data/spec/scalingo/regional/addons_spec.rb +16 -0
- data/spec/scalingo/regional_spec.rb +1 -1
- metadata +8 -2
@@ -6,20 +6,17 @@ module Scalingo
|
|
6
6
|
class Configuration
|
7
7
|
ATTRIBUTES = [
|
8
8
|
# URL to the authentication API
|
9
|
-
:auth,
|
9
|
+
# :auth,
|
10
10
|
|
11
11
|
# URL to the billing API
|
12
|
-
:billing,
|
12
|
+
# :billing,
|
13
13
|
|
14
14
|
# List of regions under the form {"region_id": root_url}
|
15
|
-
:regions,
|
15
|
+
# :regions,
|
16
16
|
|
17
17
|
# Default region. Must match a key in `regions`
|
18
18
|
:default_region,
|
19
19
|
|
20
|
-
# Wether to use https or http
|
21
|
-
:https,
|
22
|
-
|
23
20
|
# Configure the User Agent header
|
24
21
|
:user_agent,
|
25
22
|
|
@@ -36,20 +33,16 @@ module Scalingo
|
|
36
33
|
|
37
34
|
# These headers will be added to every request. Individual methods may override them.
|
38
35
|
# This should be a hash or a callable object that returns a hash.
|
39
|
-
:additional_headers
|
36
|
+
:additional_headers,
|
37
|
+
|
38
|
+
# Specify an adapter for faraday. Leave nil for the default one (Net::HTTP)
|
39
|
+
:faraday_adapter,
|
40
40
|
]
|
41
41
|
|
42
42
|
ATTRIBUTES.each { |attr| attr_accessor(attr) }
|
43
43
|
|
44
44
|
def self.default
|
45
45
|
new(
|
46
|
-
auth: "https://auth.scalingo.com/v1",
|
47
|
-
billing: "https://cashmachine.scalingo.com",
|
48
|
-
regions: {
|
49
|
-
agora_fr1: "https://api.agora-fr1.scalingo.com/v1",
|
50
|
-
osc_fr1: "https://api.osc-fr1.scalingo.com/v1",
|
51
|
-
osc_secnum_fr1: "https://api.osc-secnum-fr1.scalingo.com/v1"
|
52
|
-
},
|
53
46
|
default_region: :osc_fr1,
|
54
47
|
user_agent: "Scalingo Ruby Client v#{Scalingo::VERSION}",
|
55
48
|
exchanged_token_validity: 1.hour,
|
@@ -64,28 +57,6 @@ module Scalingo
|
|
64
57
|
public_send("#{name}=", attributes.fetch(name, parent&.public_send(name)))
|
65
58
|
end
|
66
59
|
end
|
67
|
-
|
68
|
-
def regions=(input)
|
69
|
-
if input.is_a?(OpenStruct)
|
70
|
-
@regions = input
|
71
|
-
return
|
72
|
-
end
|
73
|
-
|
74
|
-
if input.is_a?(Hash)
|
75
|
-
@regions = OpenStruct.new(input)
|
76
|
-
return
|
77
|
-
end
|
78
|
-
|
79
|
-
raise ArgumentError, "wrong type for argument"
|
80
|
-
end
|
81
|
-
|
82
|
-
def default_region=(input)
|
83
|
-
input = input.to_sym
|
84
|
-
|
85
|
-
raise ArgumentError, "No regions named `#{input}`" unless regions.respond_to?(input)
|
86
|
-
|
87
|
-
@default_region = input
|
88
|
-
end
|
89
60
|
end
|
90
61
|
|
91
62
|
def self.config
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
require "faraday"
|
3
|
+
require "faraday_middleware"
|
4
|
+
require "scalingo/token_holder"
|
5
|
+
require "scalingo/errors"
|
6
|
+
|
7
|
+
module Scalingo
|
8
|
+
class CoreClient
|
9
|
+
extend Forwardable
|
10
|
+
include TokenHolder
|
11
|
+
|
12
|
+
attr_reader :config
|
13
|
+
|
14
|
+
def initialize(attributes = {})
|
15
|
+
@config = Configuration.new(attributes, Scalingo.config)
|
16
|
+
end
|
17
|
+
|
18
|
+
def inspect
|
19
|
+
str = %(<#{self.class}:0x#{object_id.to_s(16)} version:"#{Scalingo::VERSION}" authenticated:)
|
20
|
+
|
21
|
+
str << if token.present?
|
22
|
+
(token.expired? ? "expired" : "true")
|
23
|
+
else
|
24
|
+
"false"
|
25
|
+
end
|
26
|
+
|
27
|
+
str << ">"
|
28
|
+
str
|
29
|
+
end
|
30
|
+
|
31
|
+
## Sub-clients accessors
|
32
|
+
def auth
|
33
|
+
raise NotImplementedError
|
34
|
+
end
|
35
|
+
|
36
|
+
def billing
|
37
|
+
raise NotImplementedError
|
38
|
+
end
|
39
|
+
|
40
|
+
def region(name = nil)
|
41
|
+
public_send(name || config.default_region)
|
42
|
+
end
|
43
|
+
|
44
|
+
## Authentication helpers / Token management
|
45
|
+
def authenticate_with(access_token: nil, bearer_token: nil, expires_at: nil)
|
46
|
+
if !access_token && !bearer_token
|
47
|
+
raise ArgumentError, "You must supply one of `access_token` or `bearer_token`"
|
48
|
+
end
|
49
|
+
|
50
|
+
if access_token && bearer_token
|
51
|
+
raise ArgumentError, "You cannot supply both `access_token` and `bearer_token`"
|
52
|
+
end
|
53
|
+
|
54
|
+
if expires_at && !bearer_token
|
55
|
+
raise ArgumentError, "`expires_at` can only be used with `bearer_token`. `access_token` have a 1 hour expiration."
|
56
|
+
end
|
57
|
+
|
58
|
+
if access_token
|
59
|
+
expiration = Time.now + config.exchanged_token_validity
|
60
|
+
response = auth.tokens.exchange(access_token)
|
61
|
+
|
62
|
+
if response.successful?
|
63
|
+
self.token = BearerToken.new(
|
64
|
+
response.data[:token],
|
65
|
+
expires_at: expiration,
|
66
|
+
raise_on_expired: config.raise_on_expired_token,
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
return response.successful?
|
71
|
+
end
|
72
|
+
|
73
|
+
if bearer_token
|
74
|
+
authenticate_with_bearer_token(
|
75
|
+
bearer_token,
|
76
|
+
expires_at: expires_at,
|
77
|
+
raise_on_expired_token: config.raise_on_expired_token,
|
78
|
+
)
|
79
|
+
|
80
|
+
true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
## Delegations
|
85
|
+
def_delegator :auth, :keys
|
86
|
+
def_delegator :auth, :scm_integrations
|
87
|
+
def_delegator :auth, :tokens
|
88
|
+
def_delegator :auth, :two_factor_auth
|
89
|
+
def_delegator :auth, :tfa
|
90
|
+
def_delegator :auth, :user
|
91
|
+
|
92
|
+
def_delegator :region, :addons
|
93
|
+
def_delegator :region, :apps
|
94
|
+
def_delegator :region, :collaborators
|
95
|
+
def_delegator :region, :containers
|
96
|
+
def_delegator :region, :deployments
|
97
|
+
def_delegator :region, :domains
|
98
|
+
def_delegator :region, :environment
|
99
|
+
def_delegator :region, :events
|
100
|
+
def_delegator :region, :logs
|
101
|
+
def_delegator :region, :metrics
|
102
|
+
def_delegator :region, :notifiers
|
103
|
+
def_delegator :region, :operations
|
104
|
+
def_delegator :region, :scm_repo_links
|
105
|
+
end
|
106
|
+
end
|
@@ -12,7 +12,7 @@ module Scalingo
|
|
12
12
|
&block
|
13
13
|
)
|
14
14
|
|
15
|
-
unpack(
|
15
|
+
unpack(:addons) { response }
|
16
16
|
end
|
17
17
|
|
18
18
|
def find(app_id, addon_id, headers = nil, &block)
|
@@ -25,7 +25,7 @@ module Scalingo
|
|
25
25
|
&block
|
26
26
|
)
|
27
27
|
|
28
|
-
unpack(
|
28
|
+
unpack(:addon) { response }
|
29
29
|
end
|
30
30
|
|
31
31
|
def provision(app_id, payload = {}, headers = nil, &block)
|
@@ -38,7 +38,7 @@ module Scalingo
|
|
38
38
|
&block
|
39
39
|
)
|
40
40
|
|
41
|
-
unpack(
|
41
|
+
unpack(:addon) { response }
|
42
42
|
end
|
43
43
|
|
44
44
|
def update(app_id, addon_id, payload = {}, headers = nil, &block)
|
@@ -51,7 +51,7 @@ module Scalingo
|
|
51
51
|
&block
|
52
52
|
)
|
53
53
|
|
54
|
-
unpack(
|
54
|
+
unpack(:addon) { response }
|
55
55
|
end
|
56
56
|
|
57
57
|
def destroy(app_id, addon_id, headers = nil, &block)
|
@@ -64,7 +64,7 @@ module Scalingo
|
|
64
64
|
&block
|
65
65
|
)
|
66
66
|
|
67
|
-
unpack
|
67
|
+
unpack { response }
|
68
68
|
end
|
69
69
|
|
70
70
|
def sso(app_id, addon_id, headers = nil, &block)
|
@@ -77,7 +77,20 @@ module Scalingo
|
|
77
77
|
&block
|
78
78
|
)
|
79
79
|
|
80
|
-
unpack(
|
80
|
+
unpack(:addon) { response }
|
81
|
+
end
|
82
|
+
|
83
|
+
def token(app_id, addon_id, headers = nil, &block)
|
84
|
+
data = nil
|
85
|
+
|
86
|
+
response = connection.post(
|
87
|
+
"apps/#{app_id}/addons/#{addon_id}/token",
|
88
|
+
data,
|
89
|
+
headers,
|
90
|
+
&block
|
91
|
+
)
|
92
|
+
|
93
|
+
unpack(:addon) { response }
|
81
94
|
end
|
82
95
|
|
83
96
|
def categories(headers = nil, &block)
|
@@ -90,7 +103,7 @@ module Scalingo
|
|
90
103
|
&block
|
91
104
|
)
|
92
105
|
|
93
|
-
unpack(
|
106
|
+
unpack(:addon_categories) { response }
|
94
107
|
end
|
95
108
|
|
96
109
|
def providers(headers = nil, &block)
|
@@ -103,7 +116,7 @@ module Scalingo
|
|
103
116
|
&block
|
104
117
|
)
|
105
118
|
|
106
|
-
unpack(
|
119
|
+
unpack(:addon_providers) { response }
|
107
120
|
end
|
108
121
|
end
|
109
122
|
end
|
@@ -12,7 +12,7 @@ module Scalingo
|
|
12
12
|
&block
|
13
13
|
)
|
14
14
|
|
15
|
-
unpack(
|
15
|
+
unpack(:apps) { response }
|
16
16
|
end
|
17
17
|
|
18
18
|
def find(id, headers = nil, &block)
|
@@ -25,7 +25,7 @@ module Scalingo
|
|
25
25
|
&block
|
26
26
|
)
|
27
27
|
|
28
|
-
unpack(
|
28
|
+
unpack(:app) { response }
|
29
29
|
end
|
30
30
|
|
31
31
|
def create(payload = {}, headers = nil, &block)
|
@@ -44,7 +44,7 @@ module Scalingo
|
|
44
44
|
&block
|
45
45
|
)
|
46
46
|
|
47
|
-
unpack(
|
47
|
+
unpack(:app) { response }
|
48
48
|
end
|
49
49
|
|
50
50
|
def update(id, payload = {}, headers = nil, &block)
|
@@ -57,7 +57,7 @@ module Scalingo
|
|
57
57
|
&block
|
58
58
|
)
|
59
59
|
|
60
|
-
unpack(
|
60
|
+
unpack(:app) { response }
|
61
61
|
end
|
62
62
|
|
63
63
|
def logs_url(id, headers = nil, &block)
|
@@ -70,7 +70,7 @@ module Scalingo
|
|
70
70
|
&block
|
71
71
|
)
|
72
72
|
|
73
|
-
unpack(
|
73
|
+
unpack(:logs_url) { response }
|
74
74
|
end
|
75
75
|
|
76
76
|
def destroy(id, payload = {}, headers = nil, &block)
|
@@ -81,7 +81,7 @@ module Scalingo
|
|
81
81
|
&block
|
82
82
|
)
|
83
83
|
|
84
|
-
unpack
|
84
|
+
unpack { response }
|
85
85
|
end
|
86
86
|
|
87
87
|
def rename(id, payload = {}, headers = nil, &block)
|
@@ -92,7 +92,7 @@ module Scalingo
|
|
92
92
|
&block
|
93
93
|
)
|
94
94
|
|
95
|
-
unpack(
|
95
|
+
unpack(:app) { response }
|
96
96
|
end
|
97
97
|
|
98
98
|
def transfer(id, payload = {}, headers = nil, &block)
|
@@ -103,7 +103,7 @@ module Scalingo
|
|
103
103
|
&block
|
104
104
|
)
|
105
105
|
|
106
|
-
unpack(
|
106
|
+
unpack(:app) { response }
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
@@ -12,7 +12,7 @@ module Scalingo
|
|
12
12
|
&block
|
13
13
|
)
|
14
14
|
|
15
|
-
unpack(
|
15
|
+
unpack(:collaborators) { response }
|
16
16
|
end
|
17
17
|
|
18
18
|
def destroy(app_id, collaborator_id, headers = nil, &block)
|
@@ -25,7 +25,7 @@ module Scalingo
|
|
25
25
|
&block
|
26
26
|
)
|
27
27
|
|
28
|
-
unpack
|
28
|
+
unpack { response }
|
29
29
|
end
|
30
30
|
|
31
31
|
def invite(app_id, payload = {}, headers = nil, &block)
|
@@ -38,7 +38,7 @@ module Scalingo
|
|
38
38
|
&block
|
39
39
|
)
|
40
40
|
|
41
|
-
unpack(
|
41
|
+
unpack(:collaborator) { response }
|
42
42
|
end
|
43
43
|
|
44
44
|
def accept(token, headers = nil, &block)
|
@@ -51,7 +51,7 @@ module Scalingo
|
|
51
51
|
&block
|
52
52
|
)
|
53
53
|
|
54
|
-
unpack
|
54
|
+
unpack { response }
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -12,7 +12,7 @@ module Scalingo
|
|
12
12
|
&block
|
13
13
|
)
|
14
14
|
|
15
|
-
unpack(
|
15
|
+
unpack(:containers) { response }
|
16
16
|
end
|
17
17
|
|
18
18
|
def scale(app_id, formation, headers = nil, &block)
|
@@ -25,7 +25,7 @@ module Scalingo
|
|
25
25
|
&block
|
26
26
|
)
|
27
27
|
|
28
|
-
unpack(
|
28
|
+
unpack(:containers) { response }
|
29
29
|
end
|
30
30
|
|
31
31
|
def restart(app_id, scope = [], headers = nil, &block)
|
@@ -38,7 +38,7 @@ module Scalingo
|
|
38
38
|
&block
|
39
39
|
)
|
40
40
|
|
41
|
-
unpack
|
41
|
+
unpack { response }
|
42
42
|
end
|
43
43
|
|
44
44
|
def sizes(headers = nil, &block)
|
@@ -51,7 +51,7 @@ module Scalingo
|
|
51
51
|
&block
|
52
52
|
)
|
53
53
|
|
54
|
-
unpack(
|
54
|
+
unpack(:container_sizes) { response }
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -12,7 +12,7 @@ module Scalingo
|
|
12
12
|
&block
|
13
13
|
)
|
14
14
|
|
15
|
-
unpack(
|
15
|
+
unpack(:deployments) { response }
|
16
16
|
end
|
17
17
|
|
18
18
|
def find(app_id, deployment_id, headers = nil, &block)
|
@@ -25,7 +25,7 @@ module Scalingo
|
|
25
25
|
&block
|
26
26
|
)
|
27
27
|
|
28
|
-
unpack(
|
28
|
+
unpack(:deployment) { response }
|
29
29
|
end
|
30
30
|
|
31
31
|
def logs(app_id, deployment_id, headers = nil, &block)
|
@@ -38,7 +38,7 @@ module Scalingo
|
|
38
38
|
&block
|
39
39
|
)
|
40
40
|
|
41
|
-
unpack(
|
41
|
+
unpack(:deployment) { response }
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -12,7 +12,7 @@ module Scalingo
|
|
12
12
|
&block
|
13
13
|
)
|
14
14
|
|
15
|
-
unpack(
|
15
|
+
unpack(:domains) { response }
|
16
16
|
end
|
17
17
|
|
18
18
|
def find(app_id, domain_id, headers = nil, &block)
|
@@ -25,7 +25,7 @@ module Scalingo
|
|
25
25
|
&block
|
26
26
|
)
|
27
27
|
|
28
|
-
unpack(
|
28
|
+
unpack(:domain) { response }
|
29
29
|
end
|
30
30
|
|
31
31
|
def create(app_id, payload = {}, headers = nil, &block)
|
@@ -38,7 +38,7 @@ module Scalingo
|
|
38
38
|
&block
|
39
39
|
)
|
40
40
|
|
41
|
-
unpack(
|
41
|
+
unpack(:domain) { response }
|
42
42
|
end
|
43
43
|
|
44
44
|
def update(app_id, domain_id, payload = {}, headers = nil, &block)
|
@@ -51,7 +51,7 @@ module Scalingo
|
|
51
51
|
&block
|
52
52
|
)
|
53
53
|
|
54
|
-
unpack(
|
54
|
+
unpack(:domain) { response }
|
55
55
|
end
|
56
56
|
|
57
57
|
def destroy(app_id, domain_id, headers = nil, &block)
|
@@ -64,7 +64,7 @@ module Scalingo
|
|
64
64
|
&block
|
65
65
|
)
|
66
66
|
|
67
|
-
unpack
|
67
|
+
unpack { response }
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|