puppet_ec2_enc 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 66de548d7b6c1341448ca7ef411fba0eb1db1838
4
+ data.tar.gz: acc3e3b4f17963c6905e17182d7762144166a330
5
+ SHA512:
6
+ metadata.gz: 304633b6109bbaf756d036e989dfc65be71991ff9c5b68674faedb8467065fee2b57a8067231e2fee3528b2d5a3ad4f4fd7d81a4cc2e70385f42ff24f5784fd2
7
+ data.tar.gz: 98f1a016479a9bc587a8df55cad1a72445799a6f05ed09b54acbfa588327a444b73052a1d729d6659424f8dcbd165c90d4c72635f9154dd252f7c66cae5b97a7
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in puppet_ec2_enc.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # PuppetEc2Enc
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/puppet_ec2_enc`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'puppet_ec2_enc'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install puppet_ec2_enc
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/puppet_ec2_enc.
36
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "puppet_ec2_enc"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'puppet_ec2_enc'
4
+
5
+ puts PuppetEc2Enc.generate
@@ -0,0 +1,27 @@
1
+ require 'aws-sdk'
2
+
3
+ module PuppetEc2Enc
4
+ class EC2Tags
5
+ attr_accessor :instance_id, :region, :ec2
6
+
7
+ def initialize(opts = {})
8
+ @instance_id = opts[:instance_id] if opts[:instance_id]
9
+ @region = opts[:region] if opts[:region]
10
+ @ec2 = Aws::EC2::Resource.new(region: @region)
11
+ end
12
+
13
+ def tags
14
+ tags = {}
15
+ instance.tags.each do |tag|
16
+ tags[tag[:key]] = tag[:value]
17
+ end
18
+ tags
19
+ end
20
+
21
+ private
22
+
23
+ def instance
24
+ ec2.instance(instance_id)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ require 'yaml'
2
+
3
+ module PuppetEc2Enc
4
+ class ENC
5
+ attr_accessor :role, :environment
6
+
7
+ def initialize(opts = {})
8
+ @role = opts[:role] || nil
9
+ @environment = opts[:environment] || nil
10
+ end
11
+
12
+ def output
13
+ classes = []
14
+ classes << "role::#{role}" if role
15
+ { 'classes' => classes, 'environment' => environment }.to_yaml
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ require 'net/http'
2
+
3
+ module PuppetEc2Enc
4
+ class Metadata
5
+ METAURL = 'http://169.254.169.254/latest/meta-data'
6
+ REGION_REGEX = %r(\A(?:us|eu|ap|sa|ca){1}-(?:east|west|southeast|central|south|northeast){1}-[0-9])
7
+
8
+ def self.instance_id
9
+ request('instance-id')
10
+ end
11
+
12
+ def self.instance_type
13
+ request('instance-type')
14
+ end
15
+
16
+ def self.availability_zone
17
+ request('placement/availability-zone')
18
+ end
19
+
20
+ def self.region
21
+ az = availability_zone
22
+ az[REGION_REGEX]
23
+ end
24
+
25
+ private
26
+
27
+ def self.request(category)
28
+ uri = URI.parse("#{METAURL}/#{category}")
29
+ response = Net::HTTP.get_response(uri)
30
+
31
+ case response
32
+ when Net::HTTPSuccess then
33
+ response.body
34
+ else
35
+ nil
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module PuppetEc2Enc
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,17 @@
1
+ require "puppet_ec2_enc/version"
2
+ require "puppet_ec2_enc/metadata"
3
+ require "puppet_ec2_enc/ec2tags"
4
+ require "puppet_ec2_enc/enc"
5
+
6
+ module PuppetEc2Enc
7
+ def self.generate
8
+ instance_id = PuppetEc2Enc::Metadata.instance_id
9
+ region = PuppetEc2Enc::Metadata.region
10
+ ec2tags = PuppetEc2Enc::EC2Tags.new(instance_id: instance_id, region: region)
11
+ tags = ec2tags.tags
12
+ role = tags.fetch('puppet_role')
13
+ environment = tags.fetch('puppet_env')
14
+ enc = PuppetEc2Enc::ENC.new(role: role, environment: environment)
15
+ enc.output
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'puppet_ec2_enc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "puppet_ec2_enc"
8
+ spec.version = PuppetEc2Enc::VERSION
9
+ spec.authors = ["Eric Olsen"]
10
+ spec.email = ["eric@ericolsen.net"]
11
+
12
+ spec.summary = %q{ENC for Standalone Puppet Nodes Running on EC2}
13
+ spec.description = %q{ENC for Standalone Puppet Nodes Running on EC2}
14
+ spec.homepage = "https://github.com/eoly/puppet_ec2_enc"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.11"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+
32
+ spec.add_runtime_dependency "json_pure", '~> 2'
33
+ spec.add_runtime_dependency "aws-sdk", '~> 2'
34
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet_ec2_enc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Eric Olsen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json_pure
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aws-sdk
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2'
69
+ description: ENC for Standalone Puppet Nodes Running on EC2
70
+ email:
71
+ - eric@ericolsen.net
72
+ executables:
73
+ - puppet_ec2_enc.rb
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - exe/puppet_ec2_enc.rb
84
+ - lib/puppet_ec2_enc.rb
85
+ - lib/puppet_ec2_enc/ec2tags.rb
86
+ - lib/puppet_ec2_enc/enc.rb
87
+ - lib/puppet_ec2_enc/metadata.rb
88
+ - lib/puppet_ec2_enc/version.rb
89
+ - puppet_ec2_enc.gemspec
90
+ homepage: https://github.com/eoly/puppet_ec2_enc
91
+ licenses: []
92
+ metadata:
93
+ allowed_push_host: https://rubygems.org
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.5.1
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: ENC for Standalone Puppet Nodes Running on EC2
114
+ test_files: []