Module: PuppetX::EnterpriseModules::Oracle::GrantProperty::ClassMethods

Defined in:
lib/puppet_x/enterprisemodules/oracle/grant_property.rb

Overview

Docs

Instance Method Summary collapse

Instance Method Details

#admin_optionObject



90
91
92
# File 'lib/puppet_x/enterprisemodules/oracle/grant_property.rb', line 90

def admin_option
  admin ? 'YES' : 'NO'
end

#common_optionObject



94
95
96
# File 'lib/puppet_x/enterprisemodules/oracle/grant_property.rb', line 94

def common_option
  common ? 'YES' : 'NO'
end

#granted_rolesObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/puppet_x/enterprisemodules/oracle/grant_property.rb', line 142

def granted_roles
  #
  # For older Oracle versions we must hack arround the common option. So
  # when the Oracle version does not support containers, and we are a common
  # grant, we return use a query that returns an empty result.
  #
  no_container_query = if common
                         "select * from dual where dummy='ORA'"
                       else
                         "select distinct grantee, granted_role as privilege from dba_role_privs where admin_option = '#{admin_option}'"
                       end
  query = for_version(
    :'11' => no_container_query,
    /12\.1.*/ => no_container_query,
    :default => "select distinct grantee, granted_role as privilege from dba_role_privs where admin_option = '#{admin_option}' and common = '#{common_option}'"
  )
  sql_on_all_primary_database_sids query
end

#grantee_columnObject

Proxy to the type class. So we only have to specify it once for all grant related properties in a type



82
83
84
# File 'lib/puppet_x/enterprisemodules/oracle/grant_property.rb', line 82

def grantee_column
  to_s.split('::')[0..-2].reduce(Kernel) { |root, new| root.const_get(new) }.grantee_column
end

#privilegesObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/puppet_x/enterprisemodules/oracle/grant_property.rb', line 98

def privileges
  #
  # For older Oracle versions we must hack arround the common option. So
  # when the Oracle version does not support containers, and we are a common
  # grant, we return use a query that returns an empty result.
  #
  no_container_query = if common
                         "select * from dual where dummy='ORA'"
                       else
                         %(select *
                             from (select distinct grantee
                                                 , privilege
                                                 , admin_option
                                     from dba_sys_privs
                                    union
                                   select username as grantee
                                        , 'SYSDBA' as privilege
                                        , 'NO' as admin_option
                                     from v$pwfile_users
                                    where sysdba = 'TRUE')
                            where admin_option = '#{admin_option}')
                       end
  query = for_version(
    :'11' => no_container_query,
    /12\.1.*/ => no_container_query,
    :default => %(select *
                    from (select distinct grantee
                                        , privilege
                                        , admin_option
                                        , common
                            from dba_sys_privs
                           union
                          select username as grantee
                               , 'SYSDBA' as privilege
                               , 'NO' as admin_option
                               , common
                            from v$pwfile_users
                           where sysdba = 'TRUE')
                   where admin_option = '#{admin_option}'
                     and common = '#{common_option}')
  )
  sql_on_all_primary_database_sids query
end

#rights_for_grantee(grantee, sid) ⇒ Object



86
87
88
# File 'lib/puppet_x/enterprisemodules/oracle/grant_property.rb', line 86

def rights_for_grantee(grantee, sid)
  @all_rights.select { |r| r['GRANTEE'] == grantee && r['SID'] == sid }.collect { |u| u['PRIVILEGE'] }
end

#translate_to_resource(raw_resource) ⇒ Object



71
72
73
74
75
76
# File 'lib/puppet_x/enterprisemodules/oracle/grant_property.rb', line 71

def translate_to_resource(raw_resource)
  @all_rights ||= privileges + granted_roles
  grantee     = raw_resource.column_data(grantee_column).upcase
  sid         = raw_resource.column_data('SID')
  rights_for_grantee(grantee, sid)
end