File: user.rb

package info (click to toggle)
ruby-fog-openstack 1.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,784 kB
  • sloc: ruby: 47,937; makefile: 5; sh: 4
file content (87 lines) | stat: -rw-r--r-- 2,121 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require 'fog/openstack/models/model'

module Fog
  module OpenStack
    class Identity
      class V3
        class User < Fog::OpenStack::Model
          identity :id

          attribute :default_project_id
          attribute :description
          attribute :domain_id
          attribute :email
          attribute :enabled
          attribute :name
          attribute :links
          attribute :password

          def to_s
            name
          end

          def groups
            requires :id
            service.list_user_groups(id).body['groups']
          end

          def projects
            requires :id
            service.list_user_projects(id).body['projects']
          end

          def application_credentials
            requires :id
            service.list_application_credentials(id).body['application_credentials']
          end

          def roles
            requires :id, :domain_id
            service.list_domain_user_roles(domain_id, id).body['roles']
          end

          def grant_role(role_id)
            requires :id, :domain_id
            service.grant_domain_user_role(domain_id, id, role_id)
          end

          def check_role(role_id)
            requires :id, :domain_id
            begin
              service.check_domain_user_role(domain_id, id, role_id)
            rescue Fog::OpenStack::Identity::NotFound
              return false
            end
            true
          end

          def revoke_role(role_id)
            requires :id, :domain_id
            service.revoke_domain_user_role(domain_id, id, role_id)
          end

          def destroy
            requires :id
            service.delete_user(id)
            true
          end

          def update(attr = nil)
            requires :id
            merge_attributes(
              service.update_user(id, attr || attributes).body['user']
            )
            self
          end

          def create
            merge_attributes(
              service.create_user(attributes).body['user']
            )
            self
          end
        end
      end
    end
  end
end