Sha256: 541ab182967a526e4cc2deeb43b1da05c6618c9d895466de8edd92dee82764b3

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

#!/usr/bin/env ruby

require 'conjur-api'
require 'securerandom'

# deepcode ignore HardcodedCredential: This is demo code
username = "admin"

arguments = ARGV.dup

api_key = arguments.shift or raise "Usage: ./demo <admin-api-key>"

Conjur.configuration.appliance_url = "http://conjur"
Conjur.configuration.account = "cucumber"

api = Conjur::API.new_from_key username, api_key

policy = File.read("features/support/policy.yml")

puts "Loading policy 'root'"
policy_result = api.load_policy "root", policy
puts "Loaded: #{policy_result}"
puts

db_password = SecureRandom.hex(12)
puts "Populating variable 'db-password' = #{db_password.inspect}"
api.resource("cucumber:variable:db-password").add_value db_password
puts "Value added"
puts

puts "Creating host factory token for 'myapp'"
expiration = Time.now + 1.day
hf_token = api.resource("cucumber:host_factory:myapp").create_token expiration
puts "Created: #{hf_token.token}"
puts

puts "Creating new host 'host-01' with host factory"
host = Conjur::API.host_factory_create_host(hf_token, "host-01")
puts "Created: #{host}"
puts

puts "Logging in as #{host.id}"
host_api = Conjur::API.new_from_key "host/host-01", host.api_key
puts "Logged in"
puts


puts "Fetching db-password as #{host.id}"
value = host_api.resource("cucumber:variable:db-password").value
puts value
puts

puts "Done!"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
conjur-api-6.0.1.pre.252 example/demo.rb
conjur-api-6.0.1.pre.250 example/demo.rb