Class: Conjur::Environment

Inherits:
RestClient::Resource
  • Object
show all
Includes:
ActsAsAsset
Defined in:
lib/conjur/environment.rb

Instance Method Summary collapse

Instance Method Details

#add_variable(name, variableid) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/conjur/environment.rb', line 5

def add_variable(name, variableid)
  log do |logger|
    logger << "Adding variable #{name} = #{variableid} to environment #{id}"
  end
  invalidate do
    RestClient::Resource.new(self['variables'].url, options).post(name: name, variableid: variableid) 
  end
end

#remove_variable(name) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/conjur/environment.rb', line 14

def remove_variable(name)
  log do |logger|
    logger << "Removing variable #{name} from enviroment #{id}"
  end
  invalidate do
    RestClient::Resource.new(self["variables/#{fully_escape name}"].url, self.options).delete
  end
end

#variable(name) ⇒ Object

Raises:

  • (ArgumentError)


23
24
25
26
27
# File 'lib/conjur/environment.rb', line 23

def variable(name)
  variableid = attributes['variables'][name]
  raise ArgumentError, "No variable '#{name}' for environment '#{id}'" unless variableid
  Conjur::Variable.new(Conjur::Core::API.host, self.options)["variables/#{fully_escape variableid}"]
end

#variablesObject



29
30
31
32
33
34
35
36
# File 'lib/conjur/environment.rb', line 29

def variables
  {}.tap do |result|
    attributes['variables'].inject(result) do |memo,v|
      memo[v[0]] = Conjur::Variable.new(Conjur::Core::API.host, self.options)["variables/#{fully_escape v[1]}"]
      memo
    end
  end
end