cfoundry 0.6.1.rc4 → 0.7.0.rc1
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.
- data/lib/cfoundry/client.rb +1 -20
- data/lib/cfoundry/rest_client.rb +8 -5
- data/lib/cfoundry/v2/model.rb +11 -3
- data/lib/cfoundry/v2/model_magic.rb +0 -21
- data/lib/cfoundry/version.rb +1 -1
- data/spec/cfoundry/client_spec.rb +1 -7
- data/spec/cfoundry/rest_client_spec.rb +22 -4
- data/spec/cfoundry/v2/model_magic_spec.rb +7 -8
- data/spec/cfoundry/v2/model_spec.rb +89 -5
- data/spec/spec_helper.rb +0 -1
- metadata +3 -22
- data/lib/cfoundry/v1/app.rb +0 -363
- data/lib/cfoundry/v1/base.rb +0 -90
- data/lib/cfoundry/v1/client.rb +0 -193
- data/lib/cfoundry/v1/framework.rb +0 -21
- data/lib/cfoundry/v1/model.rb +0 -178
- data/lib/cfoundry/v1/model_magic.rb +0 -129
- data/lib/cfoundry/v1/runtime.rb +0 -24
- data/lib/cfoundry/v1/service.rb +0 -39
- data/lib/cfoundry/v1/service_instance.rb +0 -32
- data/lib/cfoundry/v1/service_plan.rb +0 -19
- data/lib/cfoundry/v1/user.rb +0 -22
- data/spec/cfoundry/v1/base_spec.rb +0 -96
- data/spec/cfoundry/v1/client_spec.rb +0 -17
- data/spec/cfoundry/v1/model_magic_spec.rb +0 -43
- data/spec/support/v1_fake_helper.rb +0 -144
data/lib/cfoundry/v1/base.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
require "multi_json"
|
2
|
-
require "tmpdir"
|
3
|
-
|
4
|
-
require "cfoundry/baseclient"
|
5
|
-
require "cfoundry/uaaclient"
|
6
|
-
|
7
|
-
require "cfoundry/errors"
|
8
|
-
|
9
|
-
module CFoundry::V1
|
10
|
-
class Base < CFoundry::BaseClient
|
11
|
-
include BaseClientMethods
|
12
|
-
|
13
|
-
def system_services
|
14
|
-
get("services", "v1", "offerings", :content => :json, :accept => :json)
|
15
|
-
end
|
16
|
-
|
17
|
-
def system_runtimes
|
18
|
-
get("info", "runtimes", :accept => :json)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Users
|
22
|
-
def create_user(payload)
|
23
|
-
# no JSON response
|
24
|
-
post("users", :content => :json, :payload => payload)
|
25
|
-
end
|
26
|
-
|
27
|
-
def create_token(payload, email)
|
28
|
-
post("users", email, "tokens", :content => :json, :accept => :json, :payload => payload)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Applications
|
32
|
-
def instances(name)
|
33
|
-
get("apps", name, "instances", :accept => :json)[:instances]
|
34
|
-
end
|
35
|
-
|
36
|
-
def crashes(name)
|
37
|
-
get("apps", name, "crashes", :accept => :json)[:crashes]
|
38
|
-
end
|
39
|
-
|
40
|
-
def files(name, instance, *path)
|
41
|
-
get("apps", name, "instances", instance, "files", *path)
|
42
|
-
end
|
43
|
-
alias :file :files
|
44
|
-
|
45
|
-
def stats(name)
|
46
|
-
get("apps", name, "stats", :accept => :json)
|
47
|
-
end
|
48
|
-
|
49
|
-
def resource_match(fingerprints)
|
50
|
-
post("resources", :content => :json, :accept => :json, :payload => fingerprints)
|
51
|
-
end
|
52
|
-
|
53
|
-
def upload_app(name, zipfile = nil, resources = [])
|
54
|
-
use_or_create_empty_zipfile(zipfile) do |zipfile|
|
55
|
-
payload = {
|
56
|
-
:_method => "put",
|
57
|
-
:resources => MultiJson.dump(resources),
|
58
|
-
:application =>
|
59
|
-
UploadIO.new(
|
60
|
-
if zipfile.is_a? File
|
61
|
-
zipfile
|
62
|
-
elsif zipfile.is_a? String
|
63
|
-
File.new(zipfile, "rb")
|
64
|
-
end,
|
65
|
-
"application/zip")
|
66
|
-
}
|
67
|
-
|
68
|
-
post("apps", name, "application", :payload => payload)
|
69
|
-
end
|
70
|
-
rescue EOFError
|
71
|
-
retry
|
72
|
-
end
|
73
|
-
|
74
|
-
private
|
75
|
-
|
76
|
-
def use_or_create_empty_zipfile(zipfile)
|
77
|
-
Dir.mktmpdir do |working_dir|
|
78
|
-
zip_path = "#{working_dir}/empty_zip.zip"
|
79
|
-
|
80
|
-
zipfile ||= Dir.mktmpdir do |zip_dir|
|
81
|
-
File.new("#{zip_dir}/.__empty_file", "wb").close
|
82
|
-
CFoundry::Zip.pack(zip_dir, zip_path)
|
83
|
-
zip_path
|
84
|
-
end
|
85
|
-
|
86
|
-
yield zipfile
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
data/lib/cfoundry/v1/client.rb
DELETED
@@ -1,193 +0,0 @@
|
|
1
|
-
require File.expand_path("../../concerns/login_helpers", __FILE__)
|
2
|
-
|
3
|
-
module CFoundry::V1
|
4
|
-
# The primary API entrypoint. Wraps a BaseClient to provide nicer return
|
5
|
-
# values. Initialize with the target and, optionally, an auth token. These
|
6
|
-
# are the only two internal states.
|
7
|
-
class Client
|
8
|
-
include ClientMethods, CFoundry::LoginHelpers
|
9
|
-
|
10
|
-
attr_reader :base
|
11
|
-
|
12
|
-
# Create a new Client for interfacing with the given target.
|
13
|
-
#
|
14
|
-
# A token may also be provided to skip the login step.
|
15
|
-
def initialize(target = "http://api.cloudfoundry.com", token = nil)
|
16
|
-
@base = Base.new(target, token)
|
17
|
-
end
|
18
|
-
|
19
|
-
def version
|
20
|
-
1
|
21
|
-
end
|
22
|
-
|
23
|
-
# The current target URL of the client.
|
24
|
-
def target
|
25
|
-
@base.target
|
26
|
-
end
|
27
|
-
|
28
|
-
# Current authentication token.
|
29
|
-
def token
|
30
|
-
@base.token
|
31
|
-
end
|
32
|
-
|
33
|
-
# Set the authentication token.
|
34
|
-
def token=(token)
|
35
|
-
@base.token = token
|
36
|
-
end
|
37
|
-
|
38
|
-
# Current proxy user. Usually nil.
|
39
|
-
def proxy
|
40
|
-
@base.proxy
|
41
|
-
end
|
42
|
-
|
43
|
-
# Set the proxy user for the client. Must be authorized as an
|
44
|
-
# administrator for this to have any effect.
|
45
|
-
def proxy=(email)
|
46
|
-
@base.proxy = email
|
47
|
-
end
|
48
|
-
|
49
|
-
# Is the client tracing API requests?
|
50
|
-
def trace
|
51
|
-
@base.trace
|
52
|
-
end
|
53
|
-
|
54
|
-
# Set the tracing flag; if true, API requests and responses will be
|
55
|
-
# printed out.
|
56
|
-
def trace=(bool)
|
57
|
-
@base.trace = bool
|
58
|
-
end
|
59
|
-
|
60
|
-
# The current log. See +log=+.
|
61
|
-
def log
|
62
|
-
@base.log
|
63
|
-
end
|
64
|
-
|
65
|
-
# Set the logging mode. Mode can be one of:
|
66
|
-
#
|
67
|
-
# [+String+] Name of a file to log the last 10 requests to.
|
68
|
-
# [+Array+] Array to append with log data (a Hash).
|
69
|
-
# [+IO+] An IO object to write to.
|
70
|
-
# [+false+] No logging.
|
71
|
-
def log=(mode)
|
72
|
-
@base.log = mode
|
73
|
-
end
|
74
|
-
|
75
|
-
# The currently authenticated user.
|
76
|
-
def current_user
|
77
|
-
if user = info[:user]
|
78
|
-
user(user)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def current_space
|
83
|
-
nil
|
84
|
-
end
|
85
|
-
|
86
|
-
def current_organization
|
87
|
-
nil
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
# Retrieve target metadata.
|
92
|
-
def info
|
93
|
-
@base.info
|
94
|
-
end
|
95
|
-
|
96
|
-
# Retrieve available services.
|
97
|
-
def services(options = {})
|
98
|
-
services = []
|
99
|
-
|
100
|
-
@base.system_services.each do |type, vendors|
|
101
|
-
vendors.each do |vendor, providers|
|
102
|
-
providers.each do |provider, properties|
|
103
|
-
properties.each do |_, meta|
|
104
|
-
meta[:supported_versions].each do |ver|
|
105
|
-
state = meta[:version_aliases].find { |k, v| v == ver }
|
106
|
-
|
107
|
-
services <<
|
108
|
-
Service.new(vendor.to_s, ver.to_s, meta[:description],
|
109
|
-
type.to_s, provider.to_s, state && state.first,
|
110
|
-
generate_plans(meta))
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
services
|
118
|
-
end
|
119
|
-
|
120
|
-
def generate_plans(meta)
|
121
|
-
names = meta[:plans]
|
122
|
-
descriptions = meta[:plan_descriptions]
|
123
|
-
default_name = meta[:default_plan]
|
124
|
-
names.map { |name|
|
125
|
-
description = descriptions[name.to_sym] if descriptions
|
126
|
-
is_default = name == default_name || names.length == 1
|
127
|
-
ServicePlan.new(name, description, is_default)
|
128
|
-
}
|
129
|
-
end
|
130
|
-
|
131
|
-
# Retrieve available runtimes.
|
132
|
-
def runtimes(options = {})
|
133
|
-
runtimes = []
|
134
|
-
|
135
|
-
@base.system_runtimes.each do |name, meta|
|
136
|
-
runtimes <<
|
137
|
-
Runtime.new(name.to_s, meta[:version], meta[:debug_modes])
|
138
|
-
end
|
139
|
-
|
140
|
-
runtimes
|
141
|
-
end
|
142
|
-
|
143
|
-
def runtime(name)
|
144
|
-
Runtime.new(name)
|
145
|
-
end
|
146
|
-
|
147
|
-
def runtime_by_name(name)
|
148
|
-
runtimes.find { |r| r.name == name }
|
149
|
-
end
|
150
|
-
|
151
|
-
# Retrieve available frameworks.
|
152
|
-
def frameworks(options = {})
|
153
|
-
fs = info[:frameworks]
|
154
|
-
return unless fs
|
155
|
-
|
156
|
-
frameworks = []
|
157
|
-
fs.each do |name, meta|
|
158
|
-
runtimes = meta[:runtimes].collect do |r|
|
159
|
-
Runtime.new(r[:name], r[:description])
|
160
|
-
end
|
161
|
-
|
162
|
-
frameworks <<
|
163
|
-
Framework.new(name.to_s, nil, runtimes, meta[:detection])
|
164
|
-
end
|
165
|
-
|
166
|
-
frameworks
|
167
|
-
end
|
168
|
-
|
169
|
-
def framework(name)
|
170
|
-
Framework.new(name)
|
171
|
-
end
|
172
|
-
|
173
|
-
def framework_by_name(name)
|
174
|
-
frameworks.find { |f| f.name == name }
|
175
|
-
end
|
176
|
-
|
177
|
-
# Create a user on the target and return a User object representing them.
|
178
|
-
def register(email, password)
|
179
|
-
@base.create_user(:email => email, :password => password)
|
180
|
-
user(email)
|
181
|
-
end
|
182
|
-
|
183
|
-
# Clear client token. No requests are made for this.
|
184
|
-
def logout
|
185
|
-
@base.token = nil
|
186
|
-
end
|
187
|
-
|
188
|
-
# Is an authentication token set on the client?
|
189
|
-
def logged_in?
|
190
|
-
!!@base.token
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module CFoundry::V1
|
2
|
-
class Framework
|
3
|
-
attr_accessor :name, :description, :runtimes, :detection
|
4
|
-
|
5
|
-
def initialize(name, description = nil, runtimes = [], detection = nil)
|
6
|
-
@name = name
|
7
|
-
@description = description
|
8
|
-
@runtimes = runtimes
|
9
|
-
@detection = detection
|
10
|
-
end
|
11
|
-
|
12
|
-
def eql?(other)
|
13
|
-
other.is_a?(self.class) && other.name == @name
|
14
|
-
end
|
15
|
-
alias :== :eql?
|
16
|
-
|
17
|
-
def apps
|
18
|
-
[] # not supported by v1
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/cfoundry/v1/model.rb
DELETED
@@ -1,178 +0,0 @@
|
|
1
|
-
require "multi_json"
|
2
|
-
|
3
|
-
require "cfoundry/v1/model_magic"
|
4
|
-
|
5
|
-
|
6
|
-
module CFoundry::V1
|
7
|
-
class Model
|
8
|
-
@@objects = {}
|
9
|
-
|
10
|
-
extend ModelMagic
|
11
|
-
|
12
|
-
class << self
|
13
|
-
attr_writer :object_name, :base_object_name
|
14
|
-
|
15
|
-
def object_name
|
16
|
-
@object_name ||=
|
17
|
-
name.split("::").last.gsub(
|
18
|
-
/([a-z])([A-Z])/,
|
19
|
-
'\1_\2').downcase.to_sym
|
20
|
-
end
|
21
|
-
|
22
|
-
def base_object_name
|
23
|
-
@base_object_name ||= object_name
|
24
|
-
end
|
25
|
-
|
26
|
-
def plural_object_name
|
27
|
-
"#{object_name}s"
|
28
|
-
end
|
29
|
-
|
30
|
-
def plural_base_object_name
|
31
|
-
"#{base_object_name}s"
|
32
|
-
end
|
33
|
-
|
34
|
-
def objects
|
35
|
-
@@objects
|
36
|
-
end
|
37
|
-
|
38
|
-
def inherited(klass)
|
39
|
-
@@objects[klass.object_name] = klass
|
40
|
-
super
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
attr_accessor :guid, :changes
|
45
|
-
|
46
|
-
def initialize(guid, client, manifest = nil)
|
47
|
-
@guid = guid
|
48
|
-
@client = client
|
49
|
-
@manifest = manifest
|
50
|
-
@changes = {}
|
51
|
-
end
|
52
|
-
|
53
|
-
def manifest
|
54
|
-
@manifest ||= @client.base.send(base_object_name, @guid)
|
55
|
-
end
|
56
|
-
|
57
|
-
def changed?
|
58
|
-
!@changes.empty?
|
59
|
-
end
|
60
|
-
|
61
|
-
def inspect
|
62
|
-
"\#<#{self.class.name} '#@guid'>"
|
63
|
-
end
|
64
|
-
|
65
|
-
def object_name
|
66
|
-
@object_name ||= self.class.object_name
|
67
|
-
end
|
68
|
-
|
69
|
-
def base_object_name
|
70
|
-
@base_object_name ||= self.class.base_object_name
|
71
|
-
end
|
72
|
-
|
73
|
-
def guid_name
|
74
|
-
self.class.guid_name
|
75
|
-
end
|
76
|
-
|
77
|
-
def invalidate!
|
78
|
-
@manifest = nil
|
79
|
-
@changes = {}
|
80
|
-
end
|
81
|
-
|
82
|
-
def create!
|
83
|
-
@manifest = @client.base.send(:"create_#{base_object_name}", write_manifest)
|
84
|
-
|
85
|
-
@guid = read_manifest[guid_name]
|
86
|
-
|
87
|
-
true
|
88
|
-
end
|
89
|
-
|
90
|
-
def update!
|
91
|
-
@client.base.send(:"update_#{base_object_name}", @guid, write_manifest)
|
92
|
-
|
93
|
-
true
|
94
|
-
end
|
95
|
-
|
96
|
-
def delete!
|
97
|
-
@client.base.send(:"delete_#{base_object_name}", @guid)
|
98
|
-
|
99
|
-
@guid = nil
|
100
|
-
|
101
|
-
true
|
102
|
-
end
|
103
|
-
|
104
|
-
def exists?
|
105
|
-
invalidate!
|
106
|
-
manifest
|
107
|
-
true
|
108
|
-
rescue CFoundry::NotFound
|
109
|
-
false
|
110
|
-
end
|
111
|
-
|
112
|
-
def read_manifest
|
113
|
-
read = {}
|
114
|
-
|
115
|
-
self.class.read_locations.each do |name, where|
|
116
|
-
found, val = find_path(manifest, where)
|
117
|
-
read[name] = val if found
|
118
|
-
end
|
119
|
-
|
120
|
-
self.class.write_locations.each do |name, where|
|
121
|
-
next if self.class.read_only_attributes.include? name
|
122
|
-
|
123
|
-
found, val = find_path(manifest, where)
|
124
|
-
read[name] = val if found
|
125
|
-
end
|
126
|
-
|
127
|
-
read[guid_name] = @guid
|
128
|
-
|
129
|
-
read
|
130
|
-
end
|
131
|
-
|
132
|
-
def find_path(hash, path)
|
133
|
-
return [false, nil] unless hash
|
134
|
-
|
135
|
-
first, *rest = path
|
136
|
-
return [false, nil] unless hash.key?(first)
|
137
|
-
|
138
|
-
here = hash[first]
|
139
|
-
|
140
|
-
if rest.empty?
|
141
|
-
[true, here]
|
142
|
-
else
|
143
|
-
find_path(here, rest)
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def write_manifest(body = read_manifest, onto = {})
|
148
|
-
onto[guid_name] = @guid if guid_name
|
149
|
-
|
150
|
-
self.class.write_locations.each do |name, where|
|
151
|
-
next if self.class.read_only_attributes.include? name
|
152
|
-
put(body[name], onto, where) if body.key?(name)
|
153
|
-
end
|
154
|
-
|
155
|
-
onto
|
156
|
-
end
|
157
|
-
|
158
|
-
def put(what, where, path)
|
159
|
-
if path.size == 1
|
160
|
-
where[path.last] = what
|
161
|
-
elsif name = path.first
|
162
|
-
where[name] ||= {}
|
163
|
-
put(what, where[name], path[1..-1])
|
164
|
-
end
|
165
|
-
|
166
|
-
nil
|
167
|
-
end
|
168
|
-
|
169
|
-
def eql?(other)
|
170
|
-
other.is_a?(self.class) && @guid == other.guid
|
171
|
-
end
|
172
|
-
alias :== :eql?
|
173
|
-
|
174
|
-
def hash
|
175
|
-
@guid.hash
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|