Skip to content

Commit 9f661d1

Browse files
Add ability to manage SSO resources (#66)
* Add new SSO resources and fields * Update gemspec * Fix rubocop complaints * Update tested ruby versions
1 parent 6deb31b commit 9f661d1

11 files changed

+56
-10
lines changed

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
sudo: false
22
language: ruby
33
rvm:
4-
- "2.0"
5-
- "2.1"
64
- "2.2"
7-
- jruby-9.0.5.0
5+
- "2.3"
6+
- "2.5"
7+
- "2.6"

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ begin
44
require 'aptible/tasks'
55
Aptible::Tasks.load_tasks
66
rescue LoadError
7-
$stderr.puts 'Skipping Aptible::Tasks initialization...'
7+
warn 'Skipping Aptible::Tasks initialization...'
88
end

aptible-auth.gemspec

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# encoding: utf-8
2+
23
lib = File.expand_path('../lib', __FILE__)
34
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
45

@@ -23,11 +24,11 @@ Gem::Specification.new do |spec|
2324
spec.add_dependency 'gem_config'
2425
spec.add_dependency 'oauth2-aptible', '~> 0.10.0'
2526

27+
spec.add_development_dependency 'aptible-tasks', '>= 0.6.0'
2628
spec.add_development_dependency 'bundler', '~> 1.3'
27-
spec.add_development_dependency 'aptible-tasks', '>= 0.2.0'
29+
spec.add_development_dependency 'pry'
2830
spec.add_development_dependency 'rake'
2931
spec.add_development_dependency 'rspec', '~> 3.0'
3032
spec.add_development_dependency 'rspec-its'
31-
spec.add_development_dependency 'pry'
3233
spec.add_development_dependency 'timecop', '~> 0.8.1'
3334
end

lib/aptible/auth/organization.rb

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class Organization < Resource
44
has_many :roles
55
has_many :users
66
has_many :invitations
7+
has_many :whitelist_memberships
78
belongs_to :security_officer
89

910
field :id
@@ -20,20 +21,34 @@ class Organization < Resource
2021
field :security_alert_email
2122
field :ops_alert_email
2223
field :security_officer_id
24+
field :enterprise
25+
field :sso_enforced
2326

2427
def privileged_roles
2528
roles.select(&:privileged?)
2629
end
2730

2831
def accounts
2932
return @accounts if @accounts
33+
3034
require 'aptible/api'
3135

3236
accounts = Aptible::Api::Account.all(token: token, headers: headers)
3337
@accounts = accounts.select do |account|
3438
(link = account.links[:organization]) && link.href == href
3539
end
3640
end
41+
42+
# SamlConfiguration is a dependent object that does not
43+
# have a link until created. So, we create the link for it
44+
# to allow HyperResource to successfully create the object.
45+
# Afterwords, we can directly manage the SamlConfiguration
46+
def create_saml_configuration!(params)
47+
HyperResource::Link.new(
48+
self,
49+
'href' => "#{href}/saml_configurations"
50+
).post(self.class.normalize_params(params))
51+
end
3752
end
3853
end
3954
end

lib/aptible/auth/resource.rb

+2
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ def root_url
2323
require 'aptible/auth/token'
2424
require 'aptible/auth/user'
2525
require 'aptible/auth/ssh_key'
26+
require 'aptible/auth/saml_configuration'
27+
require 'aptible/auth/whitelist_membership'
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Aptible
2+
module Auth
3+
class SamlConfiguration < Resource
4+
belongs_to :organization
5+
6+
field :id
7+
field :entity_id
8+
field :sign_in_url
9+
field :name_format
10+
field :certificate
11+
field :handle
12+
field :created_at, type: Time
13+
field :updated_at, type: Time
14+
end
15+
end
16+
end

lib/aptible/auth/token.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def signing_params_from_secret(secret)
144144
private_key = parse_private_key(secret)
145145
{
146146
private_key: private_key,
147-
algorithm: "RS#{key_length(private_key) / 2}"
147+
algorithm: "RS#{key_length(private_key) / 2}"
148148
}
149149
end
150150

lib/aptible/auth/user.rb

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Auth
33
class User < Resource
44
has_many :roles
55
has_many :ssh_keys
6+
has_many :whitelist_memberhips
67

78
field :id
89
field :name

lib/aptible/auth/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Aptible
22
module Auth
3-
VERSION = '1.0.1'.freeze
3+
VERSION = '1.1.0'.freeze
44
end
55
end
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Aptible
2+
module Auth
3+
class WhitelistMembership < Resource
4+
belongs_to :organization
5+
embeds_one :user
6+
7+
field :id
8+
field :created_at, type: Time
9+
end
10+
end
11+
end

spec/aptible/auth/token_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
end
8383

8484
describe '#authenticate_user' do
85-
let(:args) { %w([email protected] foobar) }
85+
let(:args) { %w[[email protected] foobar] }
8686

8787
before { oauth.stub_chain(:password, :get_token) { response } }
8888

@@ -116,7 +116,7 @@
116116
end
117117

118118
describe '#authenticate_client' do
119-
let(:args) { %w(id secret [email protected]) }
119+
let(:args) { %w[id secret [email protected]] }
120120

121121
before do
122122
subject.stub(:signing_params_from_secret) { { algorithm: 'foobar' } }

0 commit comments

Comments
 (0)