0.0
No commit activity in last 3 years
No release in over 3 years
Common library for Knife AWS plugins
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
>= 11.16.2
>= 0
>= 0

Runtime

>= 0
>= 0
 Project Readme

Knife::AwsBase travis ci status

Library for common properties used by knife aws plugins (e.g. knife-ec2, knife-s3, knife-elb and knife-cfn).

This module was developed as there was duplicate of xxx_base modules in the gems listed above, with all the modules having the same parameter code. Some modu;es

Installation

Add this line to your application's Gemfile:

gem 'knife-aws-base'

If you're not using Bundler or are using gemspec in Bundler, then add to your .gemspec:

spec.add_dependency "knife-aws-base"

And then execute:

$ bundle

Or install it yourself as:

$ gem install knife-aws-base

Usage

  • Include AwsBase in your plugin and set up your connection (required: override abstract 'connection' method).

The example below sets up an AWS::ELB connection, and iterates through a list of ELBs in the run method:

require 'chef/knife'
require 'chef/knife/aws_base'

class Chef
  class Knife
    class MypluginTest
      include AwsBase

      def connection
        @connection ||= begin
          connection = Fog::AWS::ELB.new(
            :aws_access_key_id => Chef::Config[:knife][:aws_access_key_id],
            :aws_secret_access_key => Chef::Config[:knife][:aws_secret_access_key],
            :region => locate_config_value(:region)
          )
        end
      end

      def run
        validate!

        connection.load_balancers.each do |elb|
          ui.info("Found load balancer with ID #{elb.id.to_s}")
        end
      end

    end
  end
end

Now execute your plugin:

bundle exec knife myplugin test -h

AwsBase makes the following options / configs available:

  • --aws-credential-file FILE - File containing AWS credentials as used by aws cmdline tools
  • --aws-access-key-id ID
  • --aws-secret-access-key SECRET
  • --region

The following methods are available:

  • locate_config_value(key) - returns the value from the config object (mixlib-config - e.g. command line parameters as per above) / knife configuration
  • msg_pair(label,value) - puts label/value. color can be provided as a 3rd parameter (e.g. msg_pair("INFO","complete",:green)
  • validate! - checks that valid / sufficient authentication configuration is available (credential file or access key id + secret access key).

Contributing

  1. Fork it ( http://github.com/brettcave/knife-aws-base/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request