Sha256: ba6f6db162925974572533a349e46e1e9d6baeb4a32c023f27fd767c1aed09f9

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

require 'conjur/command'

class Conjur::Command::Layers < Conjur::Command
  self.prefix = :layer
  
  # Form an account:kind:hostid from the host argument
  # Or interpret a fully-qualified role id
  def self.require_hostid_arg(args)
    hostid = require_arg(args, 'host')
    if hostid.index(':') == 0
      hostid = [ Conjur::Core::API.conjur_account, 'host', hostid ].join(':')
    end
    hostid
  end

  desc "Provision a layer by creating backing resources in an IaaS / PaaS system"
  arg_name "layer"
  command :provision do |c|
    c.desc "Provisioner to use (aws)"
    c.arg_name "provisioner"
    c.flag [ :provisioner ]

    c.desc "Variable holding a credential used to connect to the provisioner"
    c.arg_name "variableid"
    c.flag [ :credential ]
    
    c.action do |global_options, options, args|
      id = require_arg(args, 'layer')
      provisioner = options[:provisioner] or exit_now!("Missing argument: provisioner")
      credential = options[:credential] or exit_now!("Missing argument: credential")
      raise "Supported provisioners: aws" unless provisioner == "aws"
      
      require "conjur/provisioner/layer/aws"
      
      layer = api.layer(id)
      class << layer
        include Conjur::Provisioner::Layer::AWS
      end
      layer.aws_credentialid = credential
      layer.provision
    end
  end

  desc "Add a host to an layer"
  arg_name "layer host"
  command :"hosts:add" do |c|
    c.action do |global_options, options, args|
      id = require_arg(args, 'layer')
      hostid = require_hostid_arg(args)
      
      api.layer(id).add_host hostid
    end
  end

  desc "Remove a host from an layer"
  arg_name "layer host"
  command :"hosts:remove" do |c|
    c.action do |global_options, options, args|
      id = require_arg(args, 'layer')
      hostid = require_hostid_arg(args)
      
      api.layer(id).remove_host hostid
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
conjur-asset-layer-api-0.4.0 lib/conjur/command/layers.rb