cfoundry-IronFoundry 0.3.34

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.
@@ -0,0 +1,13 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class Organization < Model
5
+ attribute :name, :string
6
+ to_many :spaces
7
+ to_many :domains
8
+ to_many :users
9
+ to_many :managers, :as => :user
10
+ to_many :billing_managers, :as => :user
11
+ to_many :auditors, :as => :user
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class Route < Model
5
+ attribute :host, :string
6
+ to_one :domain
7
+ to_one :organization
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class Runtime < Model
5
+ attribute :name, :string
6
+ attribute :description, :string
7
+ to_many :apps
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class Service < Model
5
+ attribute :label, String
6
+ attribute :provider, String
7
+ attribute :url, :url
8
+ attribute :description, String
9
+ attribute :version, String
10
+ attribute :info_url, :url
11
+ attribute :acls, { "users" => [String], "wildcards" => [String] },
12
+ :default => nil
13
+ attribute :timeout, Integer, :default => nil
14
+ attribute :active, :boolean, :default => false
15
+ to_many :service_plans
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class ServiceAuthToken < Model
5
+ attribute :label, :string
6
+ attribute :provider, :string
7
+ attribute :token, :string
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class ServiceBinding < Model
5
+ to_one :app
6
+ to_one :service_instance
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class ServiceInstance < Model
5
+ attribute :name, :string
6
+ to_one :space
7
+ to_one :service_plan
8
+ to_many :service_bindings
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class ServicePlan < Model
5
+ attribute :name, :string
6
+ attribute :description, :string
7
+ to_one :service
8
+ to_many :service_instances
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class Space < Model
5
+ attribute :name, :string
6
+ to_one :organization
7
+ to_many :developers, :as => :user
8
+ to_many :managers, :as => :user
9
+ to_many :auditors, :as => :user
10
+ to_many :apps
11
+ to_many :domains
12
+ to_many :service_instances
13
+ end
14
+ end
@@ -0,0 +1,58 @@
1
+ require "cfoundry/v2/model"
2
+
3
+ module CFoundry::V2
4
+ class User < Model
5
+ to_many :spaces
6
+ to_many :organizations
7
+ to_many :managed_organizations, :as => :organization
8
+ to_many :billing_managed_organizations, :as => :organization
9
+ to_many :audited_organizations, :as => :organization
10
+ to_many :managed_spaces, :as => :space
11
+ to_many :audited_spaces, :as => :space
12
+ attribute :admin, :boolean
13
+ to_one :default_space, :as => :space
14
+
15
+ attribute :guid, :string # guid is explicitly set for users
16
+
17
+ def guid
18
+ @guid
19
+ end
20
+
21
+ def guid=(x)
22
+ @guid = x
23
+ super
24
+ end
25
+
26
+ alias :admin? :admin
27
+
28
+ def change_password!(new, old)
29
+ @client.base.uaa.change_password(@guid, new, old)
30
+ end
31
+
32
+ # optional metadata from UAA
33
+ attr_accessor :emails, :name
34
+
35
+ def email
36
+ return unless @emails && @emails.first
37
+ @emails.first[:value]
38
+ end
39
+
40
+ def given_name
41
+ return unless @name && @name[:givenName] != email
42
+ @name[:givenName]
43
+ end
44
+
45
+ def family_name
46
+ return unless @name && @name[:familyName] != email
47
+ @name[:familyName]
48
+ end
49
+
50
+ def full_name
51
+ if @name && @name[:fullName]
52
+ @name[:fullName]
53
+ elsif given_name && family_name
54
+ "#{given_name} #{family_name}"
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,4 @@
1
+ module CFoundry # :nodoc:
2
+ # CFoundry library version number.
3
+ VERSION = "0.3.34"
4
+ end
@@ -0,0 +1,56 @@
1
+ require "zip/zipfilesystem"
2
+
3
+ module CFoundry
4
+ # Generic Zpi API. Uses rubyzip underneath, but may be changed in the future
5
+ # to use system zip command if necessary.
6
+ module Zip
7
+ # Directory entries to exclude from packing.
8
+ PACK_EXCLUSION_GLOBS = ['..', '.', '*~', '#*#', '*.log']
9
+
10
+ module_function
11
+
12
+ # Get the entries in the zip file. Returns an array of the entire
13
+ # contents, recursively (not just top-level).
14
+ def entry_lines(file)
15
+ entries = []
16
+ ::Zip::ZipFile.foreach(file) do |zentry|
17
+ entries << zentry
18
+ end
19
+ entries
20
+ end
21
+
22
+ # Unpack a zip +file+ to directory +dest+.
23
+ def unpack(file, dest)
24
+ ::Zip::ZipFile.foreach(file) do |zentry|
25
+ epath = "#{dest}/#{zentry}"
26
+ dirname = File.dirname(epath)
27
+ FileUtils.mkdir_p(dirname) unless File.exists?(dirname)
28
+ zentry.extract(epath) unless File.exists?(epath)
29
+ end
30
+ end
31
+
32
+ # Determine what files in +dir+ to pack.
33
+ def files_to_pack(dir)
34
+ Dir.glob("#{dir}/**/*", File::FNM_DOTMATCH).select do |f|
35
+ File.exists?(f) &&
36
+ PACK_EXCLUSION_GLOBS.none? do |e|
37
+ File.fnmatch(e, File.basename(f))
38
+ end
39
+ end
40
+ end
41
+
42
+ # Package directory +dir+ as file +zipfile+.
43
+ def pack(dir, zipfile)
44
+ files = files_to_pack(dir)
45
+ return false if files.empty?
46
+
47
+ ::Zip::ZipFile.open(zipfile, true) do |zf|
48
+ files.each do |f|
49
+ zf.add(f.sub("#{dir}/",''), f)
50
+ end
51
+ end
52
+
53
+ true
54
+ end
55
+ end
56
+ end
data/spec/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler.require(:default, :development)
4
+
5
+ require 'rake/dsl_definition'
6
+ require 'rake'
7
+ require 'rspec'
8
+ require 'rspec/core/rake_task'
9
+
10
+ RSpec::Core::RakeTask.new do |t|
11
+ t.pattern = "**/*_spec.rb"
12
+ t.rspec_opts = ["--format", "documentation", "--colour"]
13
+ end
14
+
@@ -0,0 +1,206 @@
1
+ require "cfoundry"
2
+ require "./helpers"
3
+
4
+ RSpec.configure do |c|
5
+ c.include CFoundryHelpers
6
+ end
7
+
8
+ describe CFoundry::Client do
9
+ TARGET = ENV["CFOUNDRY_TEST_TARGET"] || "http://api.vcap.me"
10
+ USER = ENV["CFOUNDRY_TEST_USER"] || "dev@cloudfoundry.org"
11
+ PASSWORD = ENV["CFOUNDRY_TEST_PASSWORD"] || "test"
12
+
13
+ before(:all) do
14
+ @client = CFoundry::Client.new(TARGET)
15
+ @client.login(USER, PASSWORD)
16
+ end
17
+
18
+ describe :target do
19
+ it "returns the current API target" do
20
+ @client.target.should == TARGET
21
+ end
22
+ end
23
+
24
+ describe "metadata" do
25
+ describe :info do
26
+ it "returns the cloud meta-info" do
27
+ @client.info.should be_a(Hash)
28
+ end
29
+ end
30
+
31
+ describe :system_services do
32
+ it "returns the service vendors" do
33
+ @client.system_services.should be_a(Hash)
34
+ end
35
+
36
+ it "denies if not authenticated" do
37
+ without_auth do
38
+ proc {
39
+ @client.system_services
40
+ }.should raise_error(CFoundry::Denied)
41
+ end
42
+ end
43
+ end
44
+
45
+ describe :system_runtimes do
46
+ it "returns the supported runtime information" do
47
+ @client.system_runtimes.should be_a(Hash)
48
+ end
49
+
50
+ it "works if not authenticated" do
51
+ without_auth do
52
+ proc {
53
+ @client.system_runtimes
54
+ }.should_not raise_error(CFoundry::Denied)
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ describe :user do
61
+ it "creates a lazy User object" do
62
+ with_new_user do
63
+ @client.user(@user.email).should be_a(CFoundry::User)
64
+ end
65
+ end
66
+ end
67
+
68
+ describe :register do
69
+ it "registers an account and returns the User" do
70
+ email = random_user
71
+
72
+ user = @client.register(email, "test")
73
+
74
+ begin
75
+ @client.user(email).should satisfy(&:exists?)
76
+ ensure
77
+ user.delete!
78
+ end
79
+ end
80
+
81
+ it "fails if a user by that name already exists" do
82
+ proc {
83
+ @client.register(USER, PASSWORD)
84
+ }.should raise_error(CFoundry::Denied)
85
+ end
86
+ end
87
+
88
+ describe :login do
89
+ it "authenticates and sets the client token" do
90
+ client = CFoundry::Client.new(TARGET)
91
+ email = random_user
92
+ pass = random_str
93
+
94
+ client.register(email, pass)
95
+ begin
96
+ client.login(email, pass)
97
+ client.should satisfy(&:logged_in?)
98
+ ensure
99
+ @client.user(email).delete!
100
+ end
101
+ end
102
+
103
+ it "fails with invalid credentials" do
104
+ client = CFoundry::Client.new(TARGET)
105
+ email = random_user
106
+
107
+ client.register(email, "right")
108
+ begin
109
+ proc {
110
+ client.login(email, "wrong")
111
+ }.should raise_error(CFoundry::Denied)
112
+ ensure
113
+ @client.user(email).delete!
114
+ end
115
+ end
116
+ end
117
+
118
+ describe :logout do
119
+ it "clears the login token" do
120
+ client = CFoundry::Client.new(TARGET)
121
+ email = random_user
122
+ pass = random_str
123
+
124
+ client.register(email, pass)
125
+
126
+ begin
127
+ client.login(email, pass)
128
+ client.should satisfy(&:logged_in?)
129
+
130
+ client.logout
131
+ client.should_not satisfy(&:logged_in?)
132
+ ensure
133
+ @client.user(email).delete!
134
+ end
135
+ end
136
+ end
137
+
138
+ describe :app do
139
+ it "creates a lazy App object" do
140
+ @client.app("foo").should be_a(CFoundry::App)
141
+ @client.app("foo").name.should == "foo"
142
+ end
143
+ end
144
+
145
+ describe :apps do
146
+ it "returns an empty array if a user has no apps" do
147
+ with_new_user do
148
+ @client.apps.should == []
149
+ end
150
+ end
151
+
152
+ it "returns an array of App objects if a user has any" do
153
+ with_new_user do
154
+ name = random_str
155
+
156
+ new = @client.app(name)
157
+ new.total_instances = 1
158
+ new.urls = []
159
+ new.framework = "sinatra"
160
+ new.runtime = "ruby18"
161
+ new.memory = 64
162
+ new.create!
163
+
164
+ apps = @client.apps
165
+ apps.should be_a(Array)
166
+ apps.size.should == 1
167
+ apps.first.should be_a(CFoundry::App)
168
+ apps.first.name.should == name
169
+ end
170
+ end
171
+ end
172
+
173
+ describe :service do
174
+ it "creates a lazy Service object" do
175
+ @client.service("foo").should be_a(CFoundry::Service)
176
+ @client.service("foo").name.should == "foo"
177
+ end
178
+ end
179
+
180
+ describe :services do
181
+ it "returns an empty array if a user has no apps" do
182
+ with_new_user do
183
+ @client.services.should == []
184
+ end
185
+ end
186
+
187
+ it "returns an array of Service objects if a user has any" do
188
+ with_new_user do
189
+ name = random_str
190
+
191
+ new = @client.service(name)
192
+ new.type = "key-value"
193
+ new.vendor = "redis"
194
+ new.version = "2.2"
195
+ new.tier = "free"
196
+ new.create!
197
+
198
+ svcs = @client.services
199
+ svcs.should be_a(Array)
200
+ svcs.size.should == 1
201
+ svcs.first.should be_a(CFoundry::Service)
202
+ svcs.first.name.should == name
203
+ end
204
+ end
205
+ end
206
+ end