Module: Scooter::HttpDispatchers::Rbac::V1

Includes:
DirectoryService
Included in:
Scooter::HttpDispatchers::Rbac
Defined in:
lib/scooter/httpdispatchers/rbac/v1/v1.rb,
lib/scooter/httpdispatchers/rbac/v1/directory_service.rb

Overview

Methods here are generally representative of endpoints, and depending on the method, return either a Faraday response object or some sort of instance of the object created/modified.

Defined Under Namespace

Modules: DirectoryService

Instance Method Summary collapse

Methods included from DirectoryService

#attach_ds_to_rbac, #ds_default_settings, #test_attach_ds_to_rbac

Instance Method Details

#acquire_token(login, password, lifetime = nil) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/scooter/httpdispatchers/rbac/v1/v1.rb', line 101

def acquire_token(, password, lifetime=nil)
  set_rbac_path
  response = @connection.post "v1/auth/token" do |request|
    creds= {}
    creds[:login] = 
    creds[:password] = password
    creds[:lifetime] = lifetime if lifetime
    request.body = creds
  end
  response.env.body['token']
end

#create_local_user(options) ⇒ Object



14
15
16
17
18
19
# File 'lib/scooter/httpdispatchers/rbac/v1/v1.rb', line 14

def create_local_user(options)
  set_rbac_path
  @connection.post 'v1/users' do |request|
    request.body = options
  end
end

#create_password_reset_token(uuid) ⇒ Object

The ParseJson middleware throws an exception because this returns json headers while simply returning a token. In order to avoid this middleware throwing an error, we catch the exception and parse the ParsingError object for a token in the error message.



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/scooter/httpdispatchers/rbac/v1/v1.rb', line 47

def create_password_reset_token(uuid)
  set_rbac_path
  begin
    token = @connection.post("v1/users/#{uuid}/password/reset").env.body
  rescue Faraday::ParsingError => error
    # Use a regex to parse the token from the ParsingError object
    regex = /\'(.+)\'/
    token = regex.match(error.message)[1]
  end
  token
end

#create_role(options) ⇒ Object



82
83
84
85
86
87
# File 'lib/scooter/httpdispatchers/rbac/v1/v1.rb', line 82

def create_role(options)
  set_rbac_path
  @connection.post('v1/roles') do |request|
    request.body = options
  end
end

#delete_local_user(user_id) ⇒ Object



28
29
30
31
# File 'lib/scooter/httpdispatchers/rbac/v1/v1.rb', line 28

def delete_local_user(user_id)
  set_rbac_path
  @connection.delete "v1/users/#{user_id}"
end

#delete_role(role_id) ⇒ Object



96
97
98
99
# File 'lib/scooter/httpdispatchers/rbac/v1/v1.rb', line 96

def delete_role(role_id)
  set_rbac_path
  @connection.delete("v1/roles/#{role_id}")
end

#get_current_user_dataObject



38
39
40
41
# File 'lib/scooter/httpdispatchers/rbac/v1/v1.rb', line 38

def get_current_user_data
  set_rbac_path
  @connection.get('v1/users/current').env.body
end

#get_list_of_groupsObject



64
65
66
67
# File 'lib/scooter/httpdispatchers/rbac/v1/v1.rb', line 64

def get_list_of_groups
  set_rbac_path
  @connection.get('v1/groups').env.body
end

#get_list_of_rolesObject



77
78
79
80
# File 'lib/scooter/httpdispatchers/rbac/v1/v1.rb', line 77

def get_list_of_roles
  set_rbac_path
  @connection.get('v1/roles').env.body
end

#get_list_of_usersObject



59
60
61
62
# File 'lib/scooter/httpdispatchers/rbac/v1/v1.rb', line 59

def get_list_of_users
  set_rbac_path
  @connection.get('v1/users').env.body
end

#get_single_user_data(uuid) ⇒ Object



33
34
35
36
# File 'lib/scooter/httpdispatchers/rbac/v1/v1.rb', line 33

def get_single_user_data(uuid)
  set_rbac_path
  @connection.get("v1/users/#{uuid}").env.body
end

#import_ldap_group(group_name, role_ids = []) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/scooter/httpdispatchers/rbac/v1/v1.rb', line 69

def import_ldap_group(group_name, role_ids=[])
  set_rbac_path
  @connection.post('v1/groups') do |request|
    request.body = {'login' => group_name,
                    'role_ids' => role_ids}
  end
end

#replace_role(role) ⇒ Object



89
90
91
92
93
94
# File 'lib/scooter/httpdispatchers/rbac/v1/v1.rb', line 89

def replace_role(role)
  set_rbac_path
  @connection.put("v1/roles/#{role['id']}") do |request|
    request.body = role
  end
end

#update_local_user(update_hash) ⇒ Object



21
22
23
24
25
26
# File 'lib/scooter/httpdispatchers/rbac/v1/v1.rb', line 21

def update_local_user(update_hash)
  set_rbac_path
  @connection.put "v1/users/#{update_hash['id']}" do |request|
    request.body = update_hash
  end
end