Class: ConsulACLPolicyClient

Inherits:
PuppetX::Consul::ACLBase::BaseClient
  • Object
show all
Defined in:
lib/puppet/provider/consul_policy/default.rb

Instance Method Summary collapse

Instance Method Details

#create_body(policy) ⇒ Object



191
192
193
194
195
196
197
198
199
# File 'lib/puppet/provider/consul_policy/default.rb', line 191

def create_body(policy)
  body = {}
  body.store('Name', policy.name)
  body.store('Description', policy.description)
  body.store('Datacenters', policy.datacenters)
  body.store('Rules', policy.rules)

  body
end

#create_policy(policy, tries) ⇒ Object



170
171
172
173
174
175
176
177
178
179
# File 'lib/puppet/provider/consul_policy/default.rb', line 170

def create_policy(policy, tries)
  body = create_body(policy)

  begin
    response = put('/policy', body, tries)
    policy.id = response['ID']
  rescue StandardError => e
    Puppet.warning("Unable to create policy #{policy.name}: #{e.message}")
  end
end

#delete_policy(id) ⇒ Object



201
202
203
# File 'lib/puppet/provider/consul_policy/default.rb', line 201

def delete_policy(id)
  delete('/policy/' + id)
end

#get_all_policies(max_tries) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/puppet/provider/consul_policy/default.rb', line 143

def get_all_policies(max_tries)
  begin
    response = get('/policies', max_tries)
  rescue StandardError => e
    Puppet.warning("Cannot retrieve ACL token list: #{e.message}")
    response = {}
  end

  collection = []
  response.each do |item|
    collection.push(ConsulPolicy.new(item['ID'], item['Name'], item['Description'], item['Datacenters'], nil))
  end

  collection
end

#get_policy_rules(policy_id, max_tries) ⇒ Object



159
160
161
162
163
164
165
166
167
168
# File 'lib/puppet/provider/consul_policy/default.rb', line 159

def get_policy_rules(policy_id, max_tries)
  begin
    response = get('/policy/' + policy_id, max_tries)
  rescue StandardError => e
    Puppet.warning("Cannot retrieve ACL #{id}: #{e.message}")
    return ''
  end

  response['Rules']
end

#update_policy(policy) ⇒ Object



181
182
183
184
185
186
187
188
189
# File 'lib/puppet/provider/consul_policy/default.rb', line 181

def update_policy(policy)
  body = create_body(policy)

  begin
    put('/policy/' + policy.id, body)
  rescue StandardError => e
    Puppet.warning("Unable to update policy #{policy.name} (ID: #{policy.id}): #{e.message}")
  end
end