aptible-auth 0.6.0 → 0.7.0
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/lib/aptible/auth/organization.rb +6 -17
- data/lib/aptible/auth/role.rb +35 -0
- data/lib/aptible/auth/user.rb +2 -1
- data/lib/aptible/auth/version.rb +1 -1
- data/spec/aptible/auth/organization_spec.rb +9 -9
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae72a74b0226dafa4fd0fcdc42c052a922ec1f2c
|
4
|
+
data.tar.gz: 0195bdaece29eb5dc31dc7f855f5fef1922e6386
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc732dcfb0a6c3927464588ebfc0d7da06dba4fc61c94394637b168e58afed8f506b7ef1212ef6a4bbbf615d17fe1714eae6dc000a87d57b853e9a8649101411
|
7
|
+
data.tar.gz: 9e98569ee07825b3eb1f786a79df29635e378ac51830843812680d633395a1e05bc7486023ef60b9c30c679728fd4e36bfbb6287694d599bb863ff9083016324
|
@@ -5,6 +5,8 @@ module Aptible
|
|
5
5
|
class Organization < Resource
|
6
6
|
has_many :roles
|
7
7
|
has_many :users
|
8
|
+
belongs_to :security_officer
|
9
|
+
belongs_to :billing_contact
|
8
10
|
|
9
11
|
field :id
|
10
12
|
field :name
|
@@ -21,6 +23,10 @@ module Aptible
|
|
21
23
|
field :stripe_subscription_id
|
22
24
|
field :stripe_subscription_status
|
23
25
|
field :plan
|
26
|
+
field :security_alert_email
|
27
|
+
field :ops_alert_email
|
28
|
+
field :security_officer_id
|
29
|
+
field :billing_contact_id
|
24
30
|
|
25
31
|
def stripe_customer
|
26
32
|
return nil if stripe_customer_id.nil?
|
@@ -41,23 +47,6 @@ module Aptible
|
|
41
47
|
!!stripe_subscription_id
|
42
48
|
end
|
43
49
|
|
44
|
-
def billing_contact
|
45
|
-
return nil unless stripe_customer
|
46
|
-
return nil unless stripe_customer.metadata['billing_contact']
|
47
|
-
|
48
|
-
@billing_contact ||= User.find_by_url(
|
49
|
-
stripe_customer.metadata['billing_contact'], token: token
|
50
|
-
)
|
51
|
-
end
|
52
|
-
|
53
|
-
def security_officer
|
54
|
-
# REVIEW: Examine underlying data model for a less arbitrary solution
|
55
|
-
security_officers_role = roles.find do |role|
|
56
|
-
role.name == 'Security Officers'
|
57
|
-
end
|
58
|
-
security_officers_role.users.first if security_officers_role
|
59
|
-
end
|
60
|
-
|
61
50
|
def accounts
|
62
51
|
require 'aptible/api'
|
63
52
|
|
data/lib/aptible/auth/role.rb
CHANGED
@@ -14,6 +14,41 @@ module Aptible
|
|
14
14
|
def users
|
15
15
|
@users ||= memberships.map(&:user).uniq
|
16
16
|
end
|
17
|
+
|
18
|
+
def set_account_permissions(account, scopes)
|
19
|
+
account_permissions = account_permissions(account)
|
20
|
+
existing_permissions = account_permissions.select do |permission|
|
21
|
+
permission.destroy unless scopes.include? permission.scope
|
22
|
+
return scopes.include? permission.scope
|
23
|
+
end
|
24
|
+
|
25
|
+
new_scopes = scopes - existing_permissions.map(&:scope)
|
26
|
+
add_account_scopes(account, new_scopes)
|
27
|
+
end
|
28
|
+
|
29
|
+
def account_permissions(account)
|
30
|
+
account.permissions.select do |permission|
|
31
|
+
(link = permission.links[:role]) && link.href == href
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_account_scopes(account, scopes)
|
36
|
+
scopes.each { |scope| add_account_scope(account, scope) }
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_account_scope(account, scope)
|
40
|
+
account.create_permission!(scope: scope, role: href)
|
41
|
+
end
|
42
|
+
|
43
|
+
def permissions
|
44
|
+
require 'aptible/api'
|
45
|
+
|
46
|
+
permissions = Aptible::Api::Permission.all(token: token,
|
47
|
+
headers: headers)
|
48
|
+
permissions.select do |permission|
|
49
|
+
(link = permission.links[:role]) && link.href == href
|
50
|
+
end
|
51
|
+
end
|
17
52
|
end
|
18
53
|
end
|
19
54
|
end
|
data/lib/aptible/auth/user.rb
CHANGED
@@ -9,6 +9,7 @@ module Aptible
|
|
9
9
|
field :username
|
10
10
|
field :verified, type: Aptible::Resource::Boolean
|
11
11
|
field :public_key_fingerprint
|
12
|
+
field :ssh_public_key
|
12
13
|
field :created_at, type: Time
|
13
14
|
field :updated_at, type: Time
|
14
15
|
|
@@ -48,7 +49,7 @@ module Aptible
|
|
48
49
|
|
49
50
|
# rubocop:disable PredicateName
|
50
51
|
def is_billing_contact?(organization)
|
51
|
-
organization.
|
52
|
+
organization.billing_contact_id && organization.billing_contact_id == id
|
52
53
|
end
|
53
54
|
|
54
55
|
def has_role?(role)
|
data/lib/aptible/auth/version.rb
CHANGED
@@ -2,20 +2,20 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Aptible::Auth::Organization do
|
4
4
|
describe '#security_officer' do
|
5
|
-
let(:role) { double 'Aptible::Auth::Role' }
|
6
5
|
let(:user) { double 'Aptible::Auth::User' }
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
it 'should return the first member of the security officers role' do
|
12
|
-
subject.stub(:roles) { [role] }
|
7
|
+
it 'should return the security officer' do
|
8
|
+
subject.stub(:security_officer) { user }
|
13
9
|
expect(subject.security_officer).to eq user
|
14
10
|
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#billing_contact' do
|
14
|
+
let(:user) { double 'Aptible::Auth::User' }
|
15
15
|
|
16
|
-
it 'should return
|
17
|
-
subject.stub(:
|
18
|
-
expect(subject.
|
16
|
+
it 'should return the security officer' do
|
17
|
+
subject.stub(:billing_contact) { user }
|
18
|
+
expect(subject.billing_contact).to eq user
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aptible-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Macreery
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aptible-resource
|
@@ -205,3 +205,4 @@ test_files:
|
|
205
205
|
- spec/aptible/auth_spec.rb
|
206
206
|
- spec/shared/set_env.rb
|
207
207
|
- spec/spec_helper.rb
|
208
|
+
has_rdoc:
|