amigrind-core 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: af04f632152f78b552eadcf8575c144adb5f26b9
4
+ data.tar.gz: d098501ef78767532a7384aec87b237240a16443
5
+ SHA512:
6
+ metadata.gz: dd264f5fb8c31c752f864f0a7a3463717d39eb6cd214e5be305f4591362f0e856426d5ecdc0d3b77d1bd73593a1e6c6e2bc14f1c429016f2edeebbb39b0421b5
7
+ data.tar.gz: 6c00a92387755f24867aba04af4d67edfc969910ba3a5712539bbba745293d0fdf4ab5a36fb042f5d5f452a090a30bf1fbaaee62fdebe196c9a17562b9ae69b9
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,72 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Exclude:
4
+ - "data/db/migrations/*"
5
+ - "**/bin/*"
6
+ - "**/*.gemspec"
7
+ - '**/Gemfile'
8
+ - '**/Rakefile'
9
+ - '**/Capfile'
10
+ - '**/Guardfile'
11
+ - '**/Podfile'
12
+ - '**/Thorfile'
13
+ - '**/Vagrantfile'
14
+ - '**/Berksfile'
15
+ - '**/Cheffile'
16
+ - '**/Vagabondfile'
17
+ DisplayCopNames: true
18
+ DisplayStyleGuide: true
19
+
20
+ Metrics/AbcSize:
21
+ Max: 25
22
+
23
+ Metrics/ClassLength:
24
+ Max: 300
25
+
26
+ Metrics/CyclomaticComplexity:
27
+ Max: 15
28
+
29
+ Metrics/LineLength:
30
+ Max: 100
31
+
32
+ Metrics/MethodLength:
33
+ Max: 60
34
+
35
+ Metrics/PerceivedComplexity:
36
+ Max: 15
37
+
38
+ Style/AlignParameters:
39
+ Enabled: false
40
+
41
+ Style/DefWithParentheses:
42
+ Enabled: false
43
+
44
+ Style/DoubleNegation:
45
+ Enabled: false
46
+
47
+ Style/EmptyLines:
48
+ Enabled: false
49
+
50
+ Style/MethodCallParentheses:
51
+ Enabled: false
52
+
53
+ Style/MultilineBlockChain:
54
+ Enabled: false
55
+
56
+ Style/MultilineOperationIndentation:
57
+ Enabled: false
58
+
59
+ Style/SelfAssignment:
60
+ Enabled: false
61
+
62
+ Style/SignalException:
63
+ Enabled: false
64
+
65
+ Style/SpaceBeforeFirstArg:
66
+ Enabled: false
67
+
68
+ Style/SpaceInsideBrackets:
69
+ Enabled: false
70
+
71
+ Style/StringLiterals:
72
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at ed@edropple.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in amigrind-core.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # Amigrind::Core #
2
+ Check the [Amigrind](https://github.com/eropple/amigrind) documentation for more details.
3
+
4
+ ## Contributing ##
5
+ Bug reports and pull requests are welcome on GitHub at https://github.com/eropple/amigrind-client. Please be advised that this project operates under the conventions of [gitflow-avh](https://github.com/petervanderdoes/gitflow-avh), which you can install on OS X via `brew install git-flow-avh`.
6
+
7
+ This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
8
+
9
+ ## License ##
10
+ Copyright 2016 Ed Ropple (ed+amigrind@edropple.com)
11
+
12
+ Licensed under the Apache License, Version 2.0 (the "License");
13
+ you may not use this file except in compliance with the License.
14
+ You may obtain a copy of the License at
15
+
16
+ http://www.apache.org/licenses/LICENSE-2.0
17
+
18
+ Unless required by applicable law or agreed to in writing, software
19
+ distributed under the License is distributed on an "AS IS" BASIS,
20
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ See the License for the specific language governing permissions and
22
+ limitations under the License.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'amigrind/core/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "amigrind-core"
8
+ spec.version = Amigrind::Core::VERSION
9
+ spec.authors = ["Ed Ropple"]
10
+ spec.email = ["ed@edropple.com"]
11
+
12
+ spec.summary = "Core logic for Amigrind."
13
+ spec.homepage = "https://github.com/eropple/amigrind"
14
+ spec.license = "Apache 2.0"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "bin"
18
+ spec.executables = [ 'amigrind-lookup' ]
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_runtime_dependency "pry"
25
+
26
+ spec.add_runtime_dependency 'ice_nine', '~> 0.11.2'
27
+ spec.add_runtime_dependency 'aws-sdk', '~> 2.2.31'
28
+ end
@@ -0,0 +1,23 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require 'amigrind/core'
7
+
8
+ blueprint_name = ARGV[0]
9
+ channel_name = ARGV[1]
10
+ steps_back = ARGV[2]
11
+
12
+ if blueprint_name.nil? || channel_name.nil?
13
+ $stderr.puts "usage: amigrind-lookup BLUEPRINT_NAME CHANNEL_NAME [STEPS_BACK]"
14
+ Kernel.exit 1
15
+ end
16
+
17
+ steps_back = (steps_back || 0).to_i
18
+
19
+ image =
20
+ Amigrind::Core::Client.new(nil, nil) \
21
+ .get_image_by_channel(name: blueprint_name, channel: channel_name, steps_back: steps_back)
22
+
23
+ puts JSON.pretty_generate(name: image.name, ami: image.id)
@@ -0,0 +1,83 @@
1
+ require 'aws-sdk'
2
+
3
+ module Amigrind
4
+ module Core
5
+ class Client
6
+ # IDEA: future enhancement - maybe have an optional caching server that
7
+ # Amigrind clients can hit for quicker responses? because this is
8
+ # pretty slow when it has to hit the API for read requests.
9
+ attr_reader :region
10
+ attr_reader :credentials
11
+
12
+ def initialize(region, credentials)
13
+ raise "'region' must be a String or nil." unless region.is_a?(String) || region.nil?
14
+ raise "'credentials' (#{credentials}) must be nil or an Aws::CredentialProvider." \
15
+ unless credentials.class.ancestors.include?(Aws::CredentialProvider) || credentials.nil?
16
+
17
+ @region = region
18
+ @credentials = credentials
19
+
20
+ ec2_opts = { region: region, credentials: credentials }.delete_if { |k, v| v.nil? }
21
+
22
+ @ec2 = Aws::EC2::Client.new(ec2_opts)
23
+ @ec2_rsrc = Aws::EC2::Resource.new(client: @ec2)
24
+ end
25
+
26
+ def get_image_by_id(name:, id:)
27
+ raise "'name' must be a String." unless name.is_a?(String)
28
+ raise "'id' must be a Fixnum." unless id.is_a?(Fixnum)
29
+
30
+ find_images_for_tags(
31
+ Amigrind::Core::AMIGRIND_NAME_TAG => name,
32
+ Amigrind::Core::AMIGRIND_ID_TAG => id.to_s
33
+ ).first
34
+ end
35
+
36
+ def get_image_by_channel(name:, channel:, steps_back: 0)
37
+ raise "'name' must be a String." unless name.is_a?(String)
38
+ raise "'channel' must be a String or Symbol." \
39
+ unless channel.is_a?(Symbol) || channel.is_a?(String)
40
+ raise "'steps_back' must be a Fixnum." unless steps_back.is_a?(Fixnum)
41
+
42
+ channel = channel.to_sym
43
+
44
+ tags = {
45
+ Amigrind::Core::AMIGRIND_NAME_TAG => name
46
+ }
47
+
48
+ if channel != :latest
49
+ channel_tag =
50
+ Amigrind::Core::AMIGRIND_CHANNEL_TAG % { channel_name: channel }
51
+ tags[channel_tag] = 1
52
+ end
53
+
54
+ images = find_images_for_tags(tags.delete_if { |_, v| v.nil? })
55
+ images.sort { |a, b| a.creation_date <=> b.creation_date }.reverse[steps_back]
56
+ end
57
+
58
+ def get_images(name:)
59
+ raise "'name' must be a String." unless name.is_a?(String)
60
+
61
+ find_images_for_tags(
62
+ Amigrind::Core::AMIGRIND_NAME_TAG => name
63
+ )
64
+ end
65
+
66
+ private
67
+
68
+ def find_images_for_tags(tags)
69
+ raise "tags must be a Hash." unless tags.is_a?(Hash)
70
+
71
+ @ec2_rsrc.images(
72
+ filters:
73
+ [{ name: 'image-type', values: [ 'machine' ] }] +
74
+ tags.map do |name, values|
75
+ {
76
+ name: "tag:#{name}",
77
+ values: [ values ].flatten.map { |i| i.to_s }
78
+ }
79
+ end).map(&:itself)
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,72 @@
1
+ require "logger"
2
+
3
+ module Amigrind
4
+ module Core
5
+ # Miscellaneous logging stuff.
6
+ module Logging
7
+ # @return [Logger] the application logger
8
+ def self.logger
9
+ @logger
10
+ end
11
+
12
+ @logger = Logger.new($stderr)
13
+ @logger.level = (ENV['AMIGRIND_DEBUG'] == '1') ? Logger::DEBUG : Logger::INFO
14
+
15
+ # Sets the log level of the logger assigned to Amigrind. Must be one of:
16
+ #
17
+ # - `:debug`
18
+ # - `:info`
19
+ # - `:warn`
20
+ # - `:error`
21
+ #
22
+ # @param name [Symbol] log level by name - one of `:debug`, `:info`, `:warn`, or `:error`
23
+ def self.log_level(name)
24
+ @logger.level =
25
+ case name
26
+ when :debug
27
+ Logger::DEBUG
28
+ when :info
29
+ Logger::INFO
30
+ when :warn
31
+ Logger::WARN
32
+ when :error
33
+ Logger::ERROR
34
+ else
35
+ raise "Invalid log level: #{name}"
36
+ end
37
+ end
38
+
39
+ # Helper methods to be mixed into classes that must perform logging. (So, most of them.)
40
+ module Mixin
41
+ # Returns the logger used by {Amigrind::Core::Logging}.
42
+ def logger
43
+ Amigrind::Core::Logging.logger
44
+ end
45
+
46
+ # Records a log with debug priority.
47
+ # @param msg [String] the message to record to the logger
48
+ def debug_log(msg)
49
+ Amigrind::Core::Logging.logger.debug msg
50
+ end
51
+
52
+ # Records a log with info priority.
53
+ # @param msg [String] the message to record to theimpo logger
54
+ def info_log(msg)
55
+ Amigrind::Core::Logging.logger.info msg
56
+ end
57
+
58
+ # Records a log with warn priority.
59
+ # @param msg [String] the message to record to the logger
60
+ def warn_log(msg)
61
+ Amigrind::Core::Logging.logger.warn msg
62
+ end
63
+
64
+ # Records a log with error priority.
65
+ # @param msg [String] the message to record to the logger
66
+ def error_log(msg)
67
+ Amigrind::Core::Logging.logger.error msg
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ module Amigrind
2
+ module Core
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ require 'amigrind/core/version'
2
+ require 'amigrind/core/logging'
3
+
4
+ require 'aws-sdk'
5
+ require 'json'
6
+
7
+ # Pre-include
8
+ module Amigrind
9
+ module Core
10
+ end
11
+ end
12
+
13
+ Dir["#{__dir__}/**/*.rb"].each { |f| require_relative f }
14
+
15
+ # Post-include
16
+ module Amigrind
17
+ module Core
18
+ AMIGRIND_NAME_TAG = 'amigrind:Blueprint'.freeze
19
+ AMIGRIND_ID_TAG = 'amigrind:Id'.freeze
20
+ AMIGRIND_CHANNEL_TAG = 'amigrind:channel:%{channel_name}'.freeze
21
+ AMIGRIND_PARENT_NAME_TAG = 'amigrind:ParentBlueprint'.freeze
22
+ AMIGRIND_PARENT_ID_TAG = 'amigrind:ParentId'.freeze
23
+
24
+ BLUEPRINT_NAME_REGEX = /[a-z0-9_\.]{2,24}/
25
+
26
+ VPC_REGEX = /vpc-[0-9a-f]{8}/
27
+ SUBNET_REGEX = /subnet-[0-9a-f]{8}/
28
+ AMI_REGEX = /ami-[0-9a-f]{8}/
29
+ SG_REGEX = /sg-[0-9a-f]{8}/
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amigrind-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Ed Ropple
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-07 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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ice_nine
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.11.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.11.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: aws-sdk
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.2.31
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.2.31
97
+ description:
98
+ email:
99
+ - ed@edropple.com
100
+ executables:
101
+ - amigrind-lookup
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".travis.yml"
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - amigrind-core.gemspec
115
+ - bin/amigrind-lookup
116
+ - lib/amigrind/core.rb
117
+ - lib/amigrind/core/client.rb
118
+ - lib/amigrind/core/logging.rb
119
+ - lib/amigrind/core/version.rb
120
+ homepage: https://github.com/eropple/amigrind
121
+ licenses:
122
+ - Apache 2.0
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.5.1
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Core logic for Amigrind.
144
+ test_files: []
145
+ has_rdoc: