cloulu 0.0.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/{cloulu → cl} +0 -0
- data/lib/cc_api_stub/applications.rb +53 -0
- data/lib/cc_api_stub/domains.rb +16 -0
- data/lib/cc_api_stub/frameworks.rb +22 -0
- data/lib/cc_api_stub/helper.rb +131 -0
- data/lib/cc_api_stub/login.rb +21 -0
- data/lib/cc_api_stub/organization_users.rb +21 -0
- data/lib/cc_api_stub/organizations.rb +70 -0
- data/lib/cc_api_stub/routes.rb +26 -0
- data/lib/cc_api_stub/runtimes.rb +22 -0
- data/lib/cc_api_stub/service_bindings.rb +22 -0
- data/lib/cc_api_stub/service_instances.rb +22 -0
- data/lib/cc_api_stub/services.rb +25 -0
- data/lib/cc_api_stub/spaces.rb +49 -0
- data/lib/cc_api_stub/users.rb +84 -0
- data/lib/cc_api_stub.rb +17 -0
- data/lib/cfoundry/auth_token.rb +63 -0
- data/lib/cfoundry/baseclient.rb +201 -0
- data/lib/cfoundry/chatty_hash.rb +46 -0
- data/lib/cfoundry/client.rb +46 -0
- data/lib/cfoundry/concerns/login_helpers.rb +13 -0
- data/lib/cfoundry/errors.rb +160 -0
- data/lib/cfoundry/rest_client.rb +299 -0
- data/lib/cfoundry/test_support.rb +3 -0
- data/lib/cfoundry/trace_helpers.rb +40 -0
- data/lib/cfoundry/uaaclient.rb +112 -0
- data/lib/cfoundry/upload_helpers.rb +187 -0
- data/lib/cfoundry/v1/app.rb +363 -0
- data/lib/cfoundry/v1/base.rb +72 -0
- data/lib/cfoundry/v1/client.rb +193 -0
- data/lib/cfoundry/v1/framework.rb +21 -0
- data/lib/cfoundry/v1/model.rb +178 -0
- data/lib/cfoundry/v1/model_magic.rb +129 -0
- data/lib/cfoundry/v1/runtime.rb +24 -0
- data/lib/cfoundry/v1/service.rb +39 -0
- data/lib/cfoundry/v1/service_instance.rb +32 -0
- data/lib/cfoundry/v1/service_plan.rb +19 -0
- data/lib/cfoundry/v1/user.rb +22 -0
- data/lib/cfoundry/v2/app.rb +392 -0
- data/lib/cfoundry/v2/base.rb +83 -0
- data/lib/cfoundry/v2/client.rb +138 -0
- data/lib/cfoundry/v2/domain.rb +11 -0
- data/lib/cfoundry/v2/framework.rb +14 -0
- data/lib/cfoundry/v2/model.rb +148 -0
- data/lib/cfoundry/v2/model_magic.rb +449 -0
- data/lib/cfoundry/v2/organization.rb +16 -0
- data/lib/cfoundry/v2/route.rb +15 -0
- data/lib/cfoundry/v2/runtime.rb +12 -0
- data/lib/cfoundry/v2/service.rb +19 -0
- data/lib/cfoundry/v2/service_auth_token.rb +9 -0
- data/lib/cfoundry/v2/service_binding.rb +10 -0
- data/lib/cfoundry/v2/service_instance.rb +14 -0
- data/lib/cfoundry/v2/service_plan.rb +12 -0
- data/lib/cfoundry/v2/space.rb +18 -0
- data/lib/cfoundry/v2/user.rb +64 -0
- data/lib/cfoundry/validator.rb +39 -0
- data/lib/cfoundry/version.rb +4 -0
- data/lib/cfoundry/zip.rb +56 -0
- data/lib/cfoundry.rb +2 -0
- data/lib/manifests-vmc-plugin/errors.rb +21 -0
- data/lib/manifests-vmc-plugin/loader/builder.rb +34 -0
- data/lib/manifests-vmc-plugin/loader/normalizer.rb +149 -0
- data/lib/manifests-vmc-plugin/loader/resolver.rb +79 -0
- data/lib/manifests-vmc-plugin/loader.rb +31 -0
- data/lib/manifests-vmc-plugin/plugin.rb +145 -0
- data/lib/manifests-vmc-plugin/version.rb +3 -0
- data/lib/manifests-vmc-plugin.rb +313 -0
- data/lib/mothership/base.rb +99 -0
- data/lib/mothership/callbacks.rb +85 -0
- data/lib/mothership/command.rb +146 -0
- data/lib/mothership/errors.rb +38 -0
- data/lib/mothership/help/commands.rb +53 -0
- data/lib/mothership/help/printer.rb +170 -0
- data/lib/mothership/help.rb +64 -0
- data/lib/mothership/inputs.rb +189 -0
- data/lib/mothership/parser.rb +182 -0
- data/lib/mothership/version.rb +3 -0
- data/lib/mothership.rb +64 -0
- data/lib/tunnel-vmc-plugin/plugin.rb +178 -0
- data/lib/tunnel-vmc-plugin/tunnel.rb +308 -0
- data/lib/tunnel-vmc-plugin/version.rb +3 -0
- data/lib/uaa/http.rb +168 -0
- data/lib/uaa/misc.rb +121 -0
- data/lib/uaa/scim.rb +292 -0
- data/lib/uaa/token_coder.rb +196 -0
- data/lib/uaa/token_issuer.rb +255 -0
- data/lib/uaa/util.rb +235 -0
- data/lib/uaa/version.rb +19 -0
- data/lib/uaa.rb +18 -0
- data/lib/vmc/cli/app/app.rb +45 -0
- data/lib/vmc/cli/app/apps.rb +99 -0
- data/lib/vmc/cli/app/base.rb +90 -0
- data/lib/vmc/cli/app/crashes.rb +42 -0
- data/lib/vmc/cli/app/delete.rb +95 -0
- data/lib/vmc/cli/app/deprecated.rb +11 -0
- data/lib/vmc/cli/app/env.rb +78 -0
- data/lib/vmc/cli/app/files.rb +137 -0
- data/lib/vmc/cli/app/health.rb +26 -0
- data/lib/vmc/cli/app/instances.rb +53 -0
- data/lib/vmc/cli/app/logs.rb +76 -0
- data/lib/vmc/cli/app/push/create.rb +165 -0
- data/lib/vmc/cli/app/push/interactions.rb +94 -0
- data/lib/vmc/cli/app/push/sync.rb +64 -0
- data/lib/vmc/cli/app/push.rb +109 -0
- data/lib/vmc/cli/app/rename.rb +35 -0
- data/lib/vmc/cli/app/restart.rb +20 -0
- data/lib/vmc/cli/app/scale.rb +71 -0
- data/lib/vmc/cli/app/start.rb +143 -0
- data/lib/vmc/cli/app/stats.rb +67 -0
- data/lib/vmc/cli/app/stop.rb +27 -0
- data/lib/vmc/cli/help.rb +11 -0
- data/lib/vmc/cli/interactive.rb +105 -0
- data/lib/vmc/cli/route/base.rb +12 -0
- data/lib/vmc/cli/route/map.rb +82 -0
- data/lib/vmc/cli/route/routes.rb +25 -0
- data/lib/vmc/cli/route/unmap.rb +94 -0
- data/lib/vmc/cli/service/base.rb +8 -0
- data/lib/vmc/cli/service/bind.rb +44 -0
- data/lib/vmc/cli/service/create.rb +126 -0
- data/lib/vmc/cli/service/delete.rb +86 -0
- data/lib/vmc/cli/service/rename.rb +35 -0
- data/lib/vmc/cli/service/service.rb +42 -0
- data/lib/vmc/cli/service/services.rb +114 -0
- data/lib/vmc/cli/service/unbind.rb +38 -0
- data/lib/vmc/cli/start/base.rb +94 -0
- data/lib/vmc/cli/start/colors.rb +13 -0
- data/lib/vmc/cli/start/info.rb +126 -0
- data/lib/vmc/cli/start/login.rb +97 -0
- data/lib/vmc/cli/start/logout.rb +17 -0
- data/lib/vmc/cli/start/target.rb +60 -0
- data/lib/vmc/cli/start/target_interactions.rb +37 -0
- data/lib/vmc/cli/start/targets.rb +16 -0
- data/lib/vmc/cli/user/base.rb +29 -0
- data/lib/vmc/cli/user/create.rb +39 -0
- data/lib/vmc/cli/user/delete.rb +27 -0
- data/lib/vmc/cli/user/passwd.rb +50 -0
- data/lib/vmc/cli/user/register.rb +42 -0
- data/lib/vmc/cli/user/users.rb +32 -0
- data/lib/vmc/cli/v2_check_cli.rb +16 -0
- data/lib/vmc/cli.rb +474 -0
- data/lib/vmc/constants.rb +13 -0
- data/lib/vmc/detect.rb +129 -0
- data/lib/vmc/errors.rb +19 -0
- data/lib/vmc/plugin.rb +56 -0
- data/lib/vmc/spacing.rb +89 -0
- data/lib/vmc/spec_helper.rb +1 -0
- data/lib/vmc/test_support.rb +6 -0
- data/lib/vmc/version.rb +3 -0
- data/lib/vmc.rb +8 -0
- data/vendor/errors/v1.yml +189 -0
- data/vendor/errors/v2.yml +360 -0
- metadata +303 -190
data/bin/{cloulu → cl}
RENAMED
File without changes
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module CcApiStub
|
2
|
+
module Applications
|
3
|
+
extend Helper
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def succeed_to_load(options={})
|
7
|
+
response_body = Helper.load_fixtures(options.delete(:fixture) || "fake_cc_#{object_name}", options)
|
8
|
+
stub_get(object_endpoint, {}, response(200, response_body))
|
9
|
+
end
|
10
|
+
|
11
|
+
def succeed_to_create
|
12
|
+
response_body = Helper.load_fixtures("fake_cc_created_application")
|
13
|
+
stub_post(%r{/v2/apps$}, nil, response(201, response_body))
|
14
|
+
end
|
15
|
+
|
16
|
+
def succeed_to_update(options={})
|
17
|
+
response_body = Helper.load_fixtures(:fake_cc_application, options)
|
18
|
+
stub_put(object_endpoint, nil, response(200, response_body))
|
19
|
+
end
|
20
|
+
|
21
|
+
def succeed_to_map_route
|
22
|
+
stub_put(%r{/v2/apps/[^/]+/routes/[^/]+$}, {}, response(201, {}))
|
23
|
+
end
|
24
|
+
|
25
|
+
def succeed_to_load_stats
|
26
|
+
response_body = Helper.load_fixtures("fake_cc_stats")
|
27
|
+
stub_get(%r{/v2/apps/[^/]+/stats$}, {}, response(200, response_body))
|
28
|
+
end
|
29
|
+
|
30
|
+
def summary_fixture
|
31
|
+
Helper.load_fixtures("fake_cc_application_summary")
|
32
|
+
end
|
33
|
+
|
34
|
+
def succeed_to_load_summary(options={})
|
35
|
+
response = summary_fixture
|
36
|
+
response["state"] = options[:state] if options.has_key?(:state)
|
37
|
+
response["routes"] = options[:routes] if options.has_key?(:routes)
|
38
|
+
stub_get(%r{/v2/apps/[^/]+/summary$}, {}, response(200, response))
|
39
|
+
end
|
40
|
+
|
41
|
+
def succeed_to_load_service_bindings
|
42
|
+
response_body = Helper.load_fixtures("fake_cc_service_bindings")
|
43
|
+
stub_get(%r{/v2/apps/[^/]+/service_bindings/?(?:\?.+)?$}, {}, response(200, response_body))
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def object_endpoint
|
49
|
+
%r{/v2/apps/[^/]+$}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module CcApiStub
|
2
|
+
module Domains
|
3
|
+
extend Helper
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def succeed_to_create
|
7
|
+
response_body = Helper.load_fixtures("fake_cc_created_domain")
|
8
|
+
stub_post(%r{/v2/domains/?(\?.+)?$}, {}, response(201, response_body))
|
9
|
+
end
|
10
|
+
|
11
|
+
def succeed_to_delete
|
12
|
+
stub_delete(%r{/v2/domains/[^/\?]+$}, {}, response(200))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CcApiStub
|
2
|
+
module Frameworks
|
3
|
+
extend Helper
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def succeed_to_load
|
7
|
+
response_body = Helper.load_fixtures("fake_cc_frameworks")
|
8
|
+
stub_get(collection_endpoint, {}, response(200, response_body))
|
9
|
+
end
|
10
|
+
|
11
|
+
def fail_to_load
|
12
|
+
stub_get(collection_endpoint, {}, response(500))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def collection_endpoint
|
18
|
+
%r{/v2/frameworks\?inline-relations-depth=1$}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module CcApiStub
|
4
|
+
module Helper
|
5
|
+
class << self
|
6
|
+
def response(code, body=nil)
|
7
|
+
{
|
8
|
+
:status => code,
|
9
|
+
:headers => {},
|
10
|
+
:body => body.nil? ? "--garbage--" : body.to_json
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def fail_request(method = :any, code = 500, response_body = {}, path = /#{CcApiStub::Helper.host}/)
|
15
|
+
WebMock::API.stub_request(method, path).to_return(response(code, response_body))
|
16
|
+
end
|
17
|
+
|
18
|
+
def host=(host)
|
19
|
+
@@host = host
|
20
|
+
end
|
21
|
+
|
22
|
+
def host
|
23
|
+
@@host or raise 'No host set'
|
24
|
+
end
|
25
|
+
|
26
|
+
def fail_with_error(method, error_attributes=nil)
|
27
|
+
WebMock::API.
|
28
|
+
stub_request(method, /#{CcApiStub::Helper.host}/).
|
29
|
+
to_return(response(400, error_attributes))
|
30
|
+
end
|
31
|
+
|
32
|
+
def load_fixtures(fixtures_name, options = {})
|
33
|
+
path = File.join(File.dirname(__FILE__), "..", "..", "spec/fixtures/#{fixtures_name.to_s}.json")
|
34
|
+
JSON.parse(File.read(path)).tap do |fixture|
|
35
|
+
fixture["entity"].merge!(options.stringify_keys) if options.any?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def stub_get(*args)
|
41
|
+
stub_request(:get, *args)
|
42
|
+
end
|
43
|
+
|
44
|
+
def stub_post(*args)
|
45
|
+
stub_request(:post, *args)
|
46
|
+
end
|
47
|
+
|
48
|
+
def stub_put(*args)
|
49
|
+
stub_request(:put, *args)
|
50
|
+
end
|
51
|
+
|
52
|
+
def stub_delete(*args)
|
53
|
+
stub_request(:delete, *args)
|
54
|
+
end
|
55
|
+
|
56
|
+
def stub_request(method, path, params = nil, response = nil)
|
57
|
+
stub = WebMock::API.stub_request(method, path)
|
58
|
+
stub.to_return(response) if response
|
59
|
+
stub.with(params) if params
|
60
|
+
stub
|
61
|
+
end
|
62
|
+
|
63
|
+
def object_name
|
64
|
+
name.demodulize.underscore.singularize
|
65
|
+
end
|
66
|
+
|
67
|
+
def find_fixture(fixture_name)
|
68
|
+
begin
|
69
|
+
Helper.load_fixtures("fake_#{fixture_name}")
|
70
|
+
rescue
|
71
|
+
Helper.load_fixtures("fake_organization_#{fixture_name}")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def object_class
|
76
|
+
begin
|
77
|
+
object_name.camelcase.constantize
|
78
|
+
rescue
|
79
|
+
"Organization::#{object_name.camelcase}".constantize
|
80
|
+
rescue
|
81
|
+
"User::#{object_name.camelcase}".constantize
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def response(code, body=nil)
|
86
|
+
CcApiStub::Helper.response(code, body)
|
87
|
+
end
|
88
|
+
|
89
|
+
def succeed_to_load(options={})
|
90
|
+
response_body = CcApiStub::Helper.load_fixtures(options.delete(:fixture) || "fake_cc_#{object_name}", options)
|
91
|
+
stub_get(object_endpoint, {}, response(200, response_body))
|
92
|
+
end
|
93
|
+
|
94
|
+
def fail_to_load
|
95
|
+
stub_get(object_endpoint, {}, response(500))
|
96
|
+
end
|
97
|
+
|
98
|
+
def succeed_to_load_many(options={})
|
99
|
+
response_body = CcApiStub::Helper.load_fixtures(options.delete(:fixture) || "fake_#{object_name.pluralize}", options)
|
100
|
+
stub_get(collection_endpoint, {}, response(200, response_body))
|
101
|
+
end
|
102
|
+
|
103
|
+
def succeed_to_load_empty(options = {})
|
104
|
+
root = options[:root] || object_name.pluralize
|
105
|
+
stub_get(collection_endpoint, {}, response(200, {root => [], "pagination" => {}}))
|
106
|
+
end
|
107
|
+
|
108
|
+
def fail_to_load_many
|
109
|
+
stub_get(collection_endpoint, {}, response(500))
|
110
|
+
end
|
111
|
+
|
112
|
+
def succeed_to_create
|
113
|
+
response_body = {object_name.to_sym => {:id => "#{object_name.gsub("_", "-")}-id-1"}}
|
114
|
+
stub_post(collection_endpoint, {}, response(201, response_body))
|
115
|
+
end
|
116
|
+
|
117
|
+
def succeed_to_update(attributes = {})
|
118
|
+
stub_put(object_endpoint, nil, response(200, {}))
|
119
|
+
end
|
120
|
+
|
121
|
+
def succeed_to_delete
|
122
|
+
stub_delete(object_endpoint, nil, response(200))
|
123
|
+
end
|
124
|
+
|
125
|
+
alias_method :succeed_to_leave, :succeed_to_delete
|
126
|
+
|
127
|
+
def fixture_prefix
|
128
|
+
"_cc"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CcApiStub
|
2
|
+
module Login
|
3
|
+
class << self
|
4
|
+
def succeeds_to_find_uaa(domain="http://some-other-random-domain.com:8181")
|
5
|
+
WebMock::API.stub_request(:get, "#{domain}/info").
|
6
|
+
to_return(
|
7
|
+
:status => 200,
|
8
|
+
:body => "{\"authorization_endpoint\":\"https://uaa.localhost\"}"
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
def succeeds_to_login_as_admin
|
13
|
+
WebMock::API.stub_request(:post, %r{uaa.localhost/oauth/authorize}).
|
14
|
+
to_return(
|
15
|
+
:status => 302,
|
16
|
+
:headers => {"Location" => "https://uaa.localhost/redirect/vmc#access_token=sre-admin-access-token&token_type=bearer"}
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CcApiStub
|
2
|
+
module OrganizationUsers
|
3
|
+
extend Helper
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def succeed_to_delete
|
7
|
+
stub_delete(object_endpoint, {}, response(200, ""))
|
8
|
+
end
|
9
|
+
|
10
|
+
def fail_to_delete
|
11
|
+
stub_delete(object_endpoint, {}, response(500))
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def object_endpoint
|
17
|
+
%r{/v2/organizations/[^/]+/users/[^/]+$}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module CcApiStub
|
2
|
+
module Organizations
|
3
|
+
extend Helper
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def succeed_to_create
|
7
|
+
response_body = Helper.load_fixtures("fake_cc_created_organization")
|
8
|
+
stub_post(collection_endpoint, {}, response(201, response_body))
|
9
|
+
end
|
10
|
+
|
11
|
+
def summary_fixture
|
12
|
+
Helper.load_fixtures("fake_cc_organization_summary")
|
13
|
+
end
|
14
|
+
|
15
|
+
def fail_to_find(org_id)
|
16
|
+
stub_get(%r{/v2/organizations/#{org_id}}, {}, response(404, {:code => 30003, :description => "The organization could not be found"}))
|
17
|
+
end
|
18
|
+
|
19
|
+
def succeed_to_load_summary(options={})
|
20
|
+
response_body = summary_fixture
|
21
|
+
response_body["spaces"] = [] if options[:no_spaces]
|
22
|
+
stub_get(%r{/v2/organizations/[^/]+/summary$}, {}, response(200, response_body))
|
23
|
+
end
|
24
|
+
|
25
|
+
def succeed_to_search(name)
|
26
|
+
response_body = Helper.load_fixtures("fake_cc_organization_search")
|
27
|
+
stub_get(%r{/v2/organizations\?inline-relations-depth=1&q=name:#{name}$}, {}, response(200, response_body))
|
28
|
+
end
|
29
|
+
|
30
|
+
def succeed_to_search_none
|
31
|
+
response_body = Helper.load_fixtures("fake_cc_empty_search")
|
32
|
+
stub_get(%r{/v2/organizations\?inline-relations-depth=1&q=name:.*$}, {}, response(200, response_body))
|
33
|
+
end
|
34
|
+
|
35
|
+
def domains_fixture
|
36
|
+
Helper.load_fixtures("fake_cc_organization_domains")
|
37
|
+
end
|
38
|
+
|
39
|
+
def domain_fixture_hash
|
40
|
+
MultiJson.load(domains_fixture["resources"].first.to_json, :symbolize_keys => true)
|
41
|
+
end
|
42
|
+
|
43
|
+
def succeed_to_load_domains
|
44
|
+
stub_get(%r{/v2/organizations/[^/]+/domains\?inline-relations-depth=1}, {}, response(200, domains_fixture))
|
45
|
+
end
|
46
|
+
|
47
|
+
def users_fixture
|
48
|
+
Helper.load_fixtures("fake_cc_organization_users")
|
49
|
+
end
|
50
|
+
|
51
|
+
def user_fixture_hash
|
52
|
+
MultiJson.load(users_fixture["resources"].first.to_json, :symbolize_keys => true)
|
53
|
+
end
|
54
|
+
|
55
|
+
def succeed_to_load_users
|
56
|
+
stub_get(%r{/v2/organizations/[^\/]+/users\?inline-relations-depth=1}, {}, response(200, users_fixture))
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def object_endpoint
|
62
|
+
%r{/v2/organizations/[^/]+$}
|
63
|
+
end
|
64
|
+
|
65
|
+
def collection_endpoint
|
66
|
+
%r{/v2/organizations\/?(\?.+)?$}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module CcApiStub
|
2
|
+
module Routes
|
3
|
+
extend Helper
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def succeed_to_load_none
|
7
|
+
stub_get(collection_endpoint, {}, response(200, {:resources => []}))
|
8
|
+
end
|
9
|
+
|
10
|
+
def succeed_to_create
|
11
|
+
response_body = Helper.load_fixtures("fake_cc_created_route")
|
12
|
+
stub_post(collection_endpoint, {}, response(201, response_body))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def collection_endpoint
|
18
|
+
%r{/v2/routes/?.*$}
|
19
|
+
end
|
20
|
+
|
21
|
+
def object_endpoint
|
22
|
+
%r{/v2/routes/[^/]+$}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CcApiStub
|
2
|
+
module Runtimes
|
3
|
+
extend Helper
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def succeed_to_load
|
7
|
+
response_body = Helper.load_fixtures("fake_cc_runtimes")
|
8
|
+
stub_get(collection_endpoint, {}, response(200, response_body))
|
9
|
+
end
|
10
|
+
|
11
|
+
def fail_to_load
|
12
|
+
stub_get(collection_endpoint, {}, response(500))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def collection_endpoint
|
18
|
+
%r{/v2/runtimes\?inline-relations-depth=1$}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CcApiStub
|
2
|
+
module ServiceBindings
|
3
|
+
extend Helper
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def succeed_to_create
|
7
|
+
response_body = Helper.load_fixtures("fake_cc_service_binding")
|
8
|
+
stub_post(collection_endpoint, {}, response(201, response_body))
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def object_endpoint
|
14
|
+
%r{/v2/service_bindings/[^/]+$}
|
15
|
+
end
|
16
|
+
|
17
|
+
def collection_endpoint
|
18
|
+
%r{/v2/service_bindings$}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CcApiStub
|
2
|
+
module ServiceInstances
|
3
|
+
extend Helper
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def succeed_to_create
|
7
|
+
response_body = Helper.load_fixtures("fake_cc_created_service_instance")
|
8
|
+
stub_post(collection_endpoint, {}, response(201, response_body))
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def object_endpoint
|
14
|
+
%r{/v2/service_instances/[^/]+$}
|
15
|
+
end
|
16
|
+
|
17
|
+
def collection_endpoint
|
18
|
+
%r{/v2/service_instances$}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CcApiStub
|
2
|
+
module Services
|
3
|
+
extend Helper
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def succeed_to_load
|
7
|
+
stub_get(collection_endpoint, {}, response(200, services_fixture))
|
8
|
+
end
|
9
|
+
|
10
|
+
def service_fixture_hash
|
11
|
+
MultiJson.load(services_fixture["resources"].first.to_json, :symbolize_keys => true)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def collection_endpoint
|
17
|
+
%r{/v2/services\?inline-relations-depth=1}
|
18
|
+
end
|
19
|
+
|
20
|
+
def services_fixture
|
21
|
+
Helper.load_fixtures("fake_cc_service_types")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module CcApiStub
|
2
|
+
module Spaces
|
3
|
+
extend Helper
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def succeed_to_load(options={})
|
7
|
+
response_body = Helper.load_fixtures(options.delete(:fixture) || "fake_cc_#{object_name}", options)
|
8
|
+
stub_get(object_endpoint, {}, response(200, response_body))
|
9
|
+
end
|
10
|
+
|
11
|
+
def succeed_to_create
|
12
|
+
response_body = Helper.load_fixtures("fake_cc_created_space")
|
13
|
+
stub_post(collection_endpoint, {}, response(201, response_body))
|
14
|
+
end
|
15
|
+
|
16
|
+
def summary_fixture
|
17
|
+
Helper.load_fixtures("fake_cc_space_summary")
|
18
|
+
end
|
19
|
+
|
20
|
+
def succeed_to_load_summary(options={})
|
21
|
+
response_body = summary_fixture
|
22
|
+
response_body["services"] = [] if options.delete(:no_services)
|
23
|
+
stub_get(%r{/v2/spaces/[^/]+/summary$}, {}, response(200, response_body))
|
24
|
+
end
|
25
|
+
|
26
|
+
def space_fixture_hash
|
27
|
+
{
|
28
|
+
:metadata => {
|
29
|
+
:guid => "space-id-1",
|
30
|
+
:url => "/v2/spaces/space-id-1"
|
31
|
+
},
|
32
|
+
:entity => {
|
33
|
+
:name => "space-name-1"
|
34
|
+
}
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def collection_endpoint
|
41
|
+
%r{/v2/spaces$}
|
42
|
+
end
|
43
|
+
|
44
|
+
def object_endpoint
|
45
|
+
%r{/v2/spaces/[^/]+$}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module CcApiStub
|
2
|
+
module Users
|
3
|
+
extend Helper
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def succeed_to_load(options={})
|
7
|
+
response_body = Helper.load_fixtures(options[:fixture] || "fake_cc_user")
|
8
|
+
response_body["metadata"]["guid"] = options[:id] || "user-id-1"
|
9
|
+
|
10
|
+
if options[:no_organizations]
|
11
|
+
response_body["entity"]["organizations"] = []
|
12
|
+
else
|
13
|
+
def space(space_id) {"metadata" => { "guid" => space_id }, "entity" => {}} end
|
14
|
+
|
15
|
+
organization = response_body["entity"]["organizations"].first
|
16
|
+
organization["metadata"]["guid"] = options[:organization_id] || "organization-id-1"
|
17
|
+
organization["entity"]["spaces"] = [] if options[:no_spaces]
|
18
|
+
|
19
|
+
permissions = options[:permissions] || [:organization_manager]
|
20
|
+
|
21
|
+
response_body["entity"]["managed_organizations"] << organization if permissions.include?(:organization_manager)
|
22
|
+
response_body["entity"]["billing_managed_organizations"] << organization if permissions.include?(:organization_billing_manager)
|
23
|
+
response_body["entity"]["audited_organizations"] << organization if permissions.include?(:organization_auditor)
|
24
|
+
|
25
|
+
unless options[:no_spaces]
|
26
|
+
space = space("space-id-1")
|
27
|
+
response_body["entity"]["spaces"] << space if permissions.include?(:space_developer)
|
28
|
+
response_body["entity"]["managed_spaces"] << space if permissions.include?(:space_manager)
|
29
|
+
response_body["entity"]["audited_spaces"] << space if permissions.include?(:space_auditor)
|
30
|
+
|
31
|
+
space2 = space("space-id-2")
|
32
|
+
response_body["entity"]["spaces"] << space2 if permissions.include?(:space2_developer)
|
33
|
+
response_body["entity"]["managed_spaces"] << space2 if permissions.include?(:space2_manager)
|
34
|
+
response_body["entity"]["audited_spaces"] << space2 if permissions.include?(:space2_auditor)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
stub_get(%r{/v2/users/[^/]+\?inline-relations-depth=2$}, {}, response(200, response_body))
|
39
|
+
end
|
40
|
+
|
41
|
+
def fail_to_find
|
42
|
+
stub_get(object_endpoint, {}, response(404, {:code => 20003, :description => "The user could not be found"}))
|
43
|
+
end
|
44
|
+
|
45
|
+
def succeed_to_create
|
46
|
+
response_body = Helper.load_fixtures("fake_cc_created_user")
|
47
|
+
stub_post(collection_endpoint, {}, response(201, response_body))
|
48
|
+
end
|
49
|
+
|
50
|
+
def fail_to_create
|
51
|
+
CcApiStub::Helper.fail_request(:post, 500, {}, /users/)
|
52
|
+
end
|
53
|
+
|
54
|
+
def succeed_to_replace_permissions
|
55
|
+
stub_put(object_endpoint, {}, response(200, ""))
|
56
|
+
end
|
57
|
+
|
58
|
+
def fail_to_replace_permissions
|
59
|
+
stub_put(object_endpoint, {}, response(500))
|
60
|
+
end
|
61
|
+
|
62
|
+
def organizations_fixture
|
63
|
+
Helper.load_fixtures("fake_cc_user")["entity"]["organizations"]
|
64
|
+
end
|
65
|
+
|
66
|
+
def organization_fixture_hash(options={})
|
67
|
+
fixture = organizations_fixture.first
|
68
|
+
fixture["entity"].delete("spaces") if options[:no_spaces]
|
69
|
+
fixture["entity"].delete("managers") if options[:no_managers]
|
70
|
+
MultiJson.load(fixture.to_json, :symbolize_keys => true)
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def collection_endpoint
|
76
|
+
%r{/v2/users$}
|
77
|
+
end
|
78
|
+
|
79
|
+
def object_endpoint
|
80
|
+
%r{/v2/users/[^/]+$}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/cc_api_stub.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "cc_api_stub/helper"
|
2
|
+
require "cc_api_stub/organizations"
|
3
|
+
require "cc_api_stub/login"
|
4
|
+
require "cc_api_stub/applications"
|
5
|
+
require "cc_api_stub/domains"
|
6
|
+
require "cc_api_stub/frameworks"
|
7
|
+
require "cc_api_stub/organization_users"
|
8
|
+
require "cc_api_stub/routes"
|
9
|
+
require "cc_api_stub/runtimes"
|
10
|
+
require "cc_api_stub/service_bindings"
|
11
|
+
require "cc_api_stub/service_instances"
|
12
|
+
require "cc_api_stub/services"
|
13
|
+
require "cc_api_stub/spaces"
|
14
|
+
require "cc_api_stub/users"
|
15
|
+
|
16
|
+
module CcApiStub
|
17
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module CFoundry
|
2
|
+
class AuthToken
|
3
|
+
class << self
|
4
|
+
def from_uaa_token_info(token_info)
|
5
|
+
new(
|
6
|
+
token_info.auth_header,
|
7
|
+
token_info.info[:refresh_token]
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
def from_hash(hash)
|
12
|
+
new(
|
13
|
+
hash[:token],
|
14
|
+
hash[:refresh_token]
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(auth_header, refresh_token = nil)
|
20
|
+
@auth_header = auth_header
|
21
|
+
@refresh_token = refresh_token
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_accessor :auth_header
|
25
|
+
attr_reader :refresh_token
|
26
|
+
|
27
|
+
def to_hash
|
28
|
+
{
|
29
|
+
:token => auth_header,
|
30
|
+
:refresh_token => @refresh_token
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
JSON_HASH = /\{.*?\}/.freeze
|
35
|
+
|
36
|
+
# TODO: rename to #data
|
37
|
+
def token_data
|
38
|
+
return @token_data if @token_data
|
39
|
+
return {} unless @auth_header
|
40
|
+
|
41
|
+
json_hashes = Base64.decode64(@auth_header.split(" ", 2).last)
|
42
|
+
data_json = json_hashes.sub(JSON_HASH, "")[JSON_HASH]
|
43
|
+
return {} unless data_json
|
44
|
+
|
45
|
+
@token_data = MultiJson.load data_json, :symbolize_keys => true
|
46
|
+
rescue MultiJson::DecodeError
|
47
|
+
{}
|
48
|
+
end
|
49
|
+
|
50
|
+
def auth_header=(auth_header)
|
51
|
+
@token_data = nil
|
52
|
+
@auth_header = auth_header
|
53
|
+
end
|
54
|
+
|
55
|
+
def expiration
|
56
|
+
Time.at(token_data[:exp])
|
57
|
+
end
|
58
|
+
|
59
|
+
def expires_soon?
|
60
|
+
(expiration.to_i - Time.now.to_i) < 60
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|