Module: Gzr::Role

Instance Method Summary collapse

Instance Method Details

#create_role(name, pset, mset) ⇒ Object



152
153
154
155
156
157
158
159
160
161
# File 'lib/gzr/modules/role.rb', line 152

def create_role(name,pset,mset)
  req = { name: name, permission_set_id: pset, model_set_id: mset }
  begin
    @sdk.create_role(req)&.to_attrs
  rescue LookerSDK::Error => e
    say_error "Unable to call create_role(#{JSON.pretty_generate(req)})"
    say_error e
    raise
  end
end

#delete_role(role_id) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gzr/modules/role.rb', line 69

def delete_role(role_id)
  begin
    @sdk.delete_role(role_id)
  rescue LookerSDK::NotFound => e
    say_error "role(#{role_id}) not found"
    say_error e
    raise
  rescue LookerSDK::Error => e
    say_error "Unable to delete_role(#{role_id})"
    say_error e
    say_error e.errors if e.errors
    raise
  end
end

#query_all_roles(fields = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gzr/modules/role.rb', line 26

def query_all_roles(fields=nil)
  req = Hash.new
  req[:fields] = fields if fields
  begin
    @sdk.all_roles(req).collect { |r| r.to_attrs }
  rescue LookerSDK::NotFound => e
    []
  rescue LookerSDK::Error => e
    say_error "Unable to get all_roles(#{JSON.pretty_generate(req)})"
    say_error e
    say_error e.errors if e.errors
    raise
  end
end

#query_role(role_id) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gzr/modules/role.rb', line 41

def query_role(role_id)
  begin
    @sdk.role(role_id).to_attrs
  rescue LookerSDK::NotFound => e
    say_error "role(#{role_id}) not found"
    say_error e
    raise
  rescue LookerSDK::Error => e
    say_error "Unable to get role(#{role_id})"
    say_error e
    say_error e.errors if e.errors
    raise
  end
end

#query_role_groups(role_id, fields = nil) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/gzr/modules/role.rb', line 84

def query_role_groups(role_id,fields=nil)
  req = Hash.new
  req[:fields] = fields if fields
  begin
    @sdk.role_groups(role_id, req).collect { |g| g.to_attrs }
  rescue LookerSDK::NotFound => e
    say_error "role_groups(#{role_id},#{JSON.pretty_generate(req)}) not found"
    say_error e
    raise
  rescue LookerSDK::Error => e
    say_error "Unable to get role_groups(#{role_id},#{JSON.pretty_generate(req)})"
    say_error e
    say_error e.errors if e.errors
    raise
  end
end

#query_role_users(role_id, fields = nil, direct_association_only = true) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/gzr/modules/role.rb', line 101

def query_role_users(role_id,fields=nil,direct_association_only=true)
  req = Hash.new
  req[:fields] = fields if fields
  req[:direct_association_only] = direct_association_only
  begin
    @sdk.role_users(role_id, req).collect { |u| u.to_attrs }
  rescue LookerSDK::NotFound => e
    say_error "role_users(#{role_id},#{JSON.pretty_generate(req)}) not found"
    say_error e
    say_error e.errors if e.errors
    raise
  rescue LookerSDK::Error => e
    say_error "Unable to get role_users(#{role_id},#{JSON.pretty_generate(req)})"
    say_error e
    say_error e.errors if e.errors
    raise
  end
end

#set_role_groups(role_id, groups = []) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/gzr/modules/role.rb', line 120

def set_role_groups(role_id,groups=[])
  begin
    @sdk.set_role_groups(role_id, groups)
  rescue LookerSDK::NotFound => e
    say_error "set_role_groups(#{role_id},#{JSON.pretty_generate(groups)}) not found"
    say_error e
    say_error e.errors if e.errors
    raise
  rescue LookerSDK::Error => e
    say_error "Unable to call set_role_groups(#{role_id},#{JSON.pretty_generate(groups)})"
    say_error e
    say_error e.errors if e.errors
    raise
  end
end

#set_role_users(role_id, users = []) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/gzr/modules/role.rb', line 136

def set_role_users(role_id,users=[])
  begin
    @sdk.set_role_users(role_id, users)
  rescue LookerSDK::NotFound => e
    say_error "set_role_users(#{role_id},#{JSON.pretty_generate(users)}) not found"
    say_error e
    say_error e.errors if e.errors
    raise
  rescue LookerSDK::Error => e
    say_error "Unable to call set_role_users(#{role_id},#{JSON.pretty_generate(users)})"
    say_error e
    say_error e.errors if e.errors
    raise
  end
end

#trim_role(data) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gzr/modules/role.rb', line 56

def trim_role(data)
  trimmed = data.select do |k,v|
    (keys_to_keep('create_role') + [:id]).include? k
  end
  trimmed[:permission_set] = data[:permission_set].select do |k,v|
    (keys_to_keep('create_permission_set') + [:id,:built_in,:all_access]).include? k
  end
  trimmed[:model_set] = data[:model_set].select do |k,v|
    (keys_to_keep('create_model_set') + [:id,:built_in,:all_access]).include? k
  end
  trimmed
end