genome 0.1.0

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
+ SHA256:
3
+ metadata.gz: b6cc6d10ee7b5ba25627f3d129a6743478c18df27f21909a0ca8a753dbc91a94
4
+ data.tar.gz: d3254e10ad2679ab940d14a5d03e1644d0fbe2b73b9bfc002e26c6ea817126ad
5
+ SHA512:
6
+ metadata.gz: d60d317c8ab65fa464b903ec95ad115825061dbaf341736e9cf096690962a3c30ad79037b6f7454abfcf4dd86580d5bdf75e468e9f08772be85f2c25a20d6df6
7
+ data.tar.gz: 5e0078157a938c7e0838a4bf4abe8c41058e2d0d79cdfcff701c4955a32b87dd94173473c314f5b5db8eee0e245eba5b72ea40925323f2cd15379e93b47531ac
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea
11
+
12
+ /*.env
13
+
14
+ # rspec failure tracking
15
+ .rspec_status
16
+ tmp/
17
+
18
+ .rubocop-http*
19
+ .ruby-gemset
20
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.14.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at hypernova2002@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in genome.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 hypernova2002
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # Genome
2
+
3
+ A library for create and maintaining cloud formation stacks using a simple dsl. Remove all the complications of networking, security groups and iam roles for faster development and better security.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'genome'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install genome
20
+
21
+ ## Usage
22
+
23
+ ### Resources
24
+
25
+ For a quick start setting up a stack, you can use the built in resources. Simply create a stack class, which includes a resource and then build your stack. This recommended only for testing, as the resources may be updated, causing your stack to change.
26
+
27
+ ```ruby
28
+ require_relative 'lib/genome/resources/documentdb'
29
+ require_relative 'lib/genome/stack'
30
+
31
+ class TestStack
32
+ include Genome::Stack
33
+
34
+ stack_name :testing
35
+
36
+ resource Genome::Resources::DocumentDB
37
+
38
+ end
39
+
40
+ TestStack.build
41
+ ```
42
+
43
+ Alternatively, you can inherit a resource in order to configure the resource for your needs, without having to build from scratch. The following prevents a new vpc and subnets from being created, so you can configure DocumentDB to use your existing subnets.
44
+
45
+ ```ruby
46
+ require_relative 'lib/genome/resources/documentdb'
47
+ require_relative 'lib/genome/stack'
48
+
49
+ class MyResource < Genome::Resources::DocumentDB
50
+ disable_vpc
51
+ disable_subnets
52
+
53
+ subnet_ids [
54
+ 'subnet-1',
55
+ 'subnet-2',
56
+ 'subnet-3'
57
+ ]
58
+ end
59
+
60
+
61
+ class TestStack
62
+ include Genome::Stack
63
+
64
+ stack_name :testing
65
+
66
+ resource MyResource
67
+
68
+ end
69
+
70
+ TestStack.build
71
+ ```
72
+
73
+ For production environments we recommend that you configure your own resources, to ensure that templates never change. It's generally better to use existing resources for testing.
74
+
75
+ ### Templates
76
+
77
+ Templates define the core configuration needed to generate a basic AWS resource, such as an ec2_instance. Resources can configure a set of templates and define dependency chains for each template. The following creates a basic SQS Queue with a security group
78
+
79
+ ```ruby
80
+ require_relative '../resource'
81
+ require_relative '../core/templates/ec2_security_group'
82
+ require_relative '../core/templates/sqs_queue'
83
+
84
+ class SQSQueue
85
+ include Resource
86
+
87
+ template :SQSSecurityGroup, Genome::Core::Templates::EC2SecurityGroup,
88
+ GroupDescription: 'Security Group for SQS'
89
+
90
+ template :SQSQueue, Genome::Core::Templates::SQSQueue,
91
+ QueueName: 'default_queue',
92
+ DependsOn: [ :SQSSecurityGroup ]
93
+
94
+ end
95
+ ```
96
+
97
+ ## Development
98
+
99
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
100
+
101
+
102
+ ## Contributing
103
+
104
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hypernova2002/genome. 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.
105
+
106
+
107
+ ## License
108
+
109
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
110
+
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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'genome'
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(__FILE__)
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
data/genome.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'genome/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'genome'
8
+ spec.version = Genome::VERSION
9
+ spec.authors = ['hypernova2002']
10
+ spec.email = ['hypernova2002@gmail.com']
11
+
12
+ spec.summary = %q{A library for create and maintaining cloud formation stacks}
13
+ spec.description = %q{A library for create and maintaining cloud formation stacks}
14
+ spec.homepage = 'https://github.com/hypernova2002/genome'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
23
+ 'public gem pushes.'
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_dependency 'aws-sdk-cloudformation', '~> 1.8'
34
+ spec.add_dependency 'activesupport', '~> 5.2'
35
+
36
+ spec.add_development_dependency 'bundler', '~> 1.14'
37
+ # TODO: Remove foreman
38
+ spec.add_development_dependency 'foreman'
39
+ spec.add_development_dependency 'rake', '~> 10.0'
40
+ spec.add_development_dependency 'rspec', '~> 3.0'
41
+ end
@@ -0,0 +1,102 @@
1
+ require_relative 'config'
2
+ require_relative 'resource'
3
+
4
+ module Genome
5
+ module Builder
6
+ module_function
7
+
8
+ def self.template(resource)
9
+ resources = {}
10
+
11
+ resource.templates.each do |template_name, template|
12
+ parameters = evaluate_parameters(template[:parameters])
13
+
14
+ dependencies = template[:dependencies]
15
+
16
+ resource_template = template[:klass].new(template_name, parameters, dependencies)
17
+
18
+ resources.merge!(resource_template.to_h)
19
+ end
20
+
21
+ generate_document(resources: resources, description: resource.description)
22
+ end
23
+
24
+ def self.generate_document(metadata: {}, description: nil, resources: {}, parameters: {}, outputs: {})
25
+ {
26
+ AWSTemplateFormatVersion: Config.config[:AWSTemplateFormatVersion],
27
+ Description: [Config::DESCRIPTION_PREFIX, description].compact.join(''),
28
+ Metadata: metadata,
29
+ Resources: resources,
30
+ Parameters: parameters,
31
+ Outputs: outputs
32
+ }
33
+ end
34
+
35
+ def self.evaluate_parameters(parameters)
36
+ # TODO: convert classes and helper functions into appropriate parameters
37
+ processed_parameters = {}
38
+
39
+ parameters.each do |parameter_name, parameter_value|
40
+ processed_parameters[parameter_name] = evaluate_parameter_value(parameter_value)
41
+ end
42
+
43
+ processed_parameters
44
+ end
45
+
46
+ def self.evaluate_parameter_value(parameter_value)
47
+ case parameter_value
48
+ when Array
49
+ parameter_value.map do |single_parameter_value|
50
+ evaluate_parameter_value(single_parameter_value)
51
+ end
52
+ when Genome::Reference
53
+ { Ref: parameter_value.reference_name }
54
+ else
55
+ parameter_value
56
+ end
57
+ end
58
+
59
+ # def generate_template
60
+ # resources_config = {}
61
+
62
+ # resources = generate_resources
63
+
64
+ # templates.each do |build_name, config|
65
+ # params = evaluate_params(config[:params], resources)
66
+
67
+ # resources[build_name].set_properties(params)
68
+
69
+ # resources_config.merge!(resources[build_name].config)
70
+ # end
71
+
72
+ # {
73
+ # AWSTemplateFormatVersion: '2010-09-09',
74
+ # Metadata: {},
75
+ # Resources: resources_config,
76
+ # Parameters: generate_parameters,
77
+ # Outputs: generate_outputs
78
+ # }
79
+ # end
80
+
81
+ # def generate_parameters
82
+ # Hash[parameters.map do |parameter_name, config|
83
+ # [parameter_name, config[:klass].new(config[:params]).config]
84
+ # end]
85
+ # end
86
+
87
+ # def generate_resources
88
+ # Hash[templates.map do |build_name, config|
89
+ # [build_name, config[:klass].new(build_name)]
90
+ # end]
91
+ # end
92
+
93
+ # def generate_outputs
94
+ # Hash[outputs.map do |output_name, klass|
95
+ # [output_name, klass.new.config]
96
+ # end]
97
+ # end
98
+
99
+ # def klass
100
+ # end
101
+ end
102
+ end
@@ -0,0 +1,25 @@
1
+ module Genome
2
+ module Config
3
+ module_function
4
+
5
+ DESCRIPTION_PREFIX = 'Maintained by Genome: '.freeze
6
+
7
+ def self.config
8
+ @@configuration ||= default_config
9
+ end
10
+
11
+ def self.configure
12
+ @@configuration ||= default_config
13
+
14
+ yield @@configuration if block_given?
15
+
16
+ @@configuration
17
+ end
18
+
19
+ def self.default_config
20
+ {
21
+ AWSTemplateFormatVersion: '2010-09-09'
22
+ }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ require 'active_support'
2
+ require 'active_support/concern'
3
+ require 'active_support/core_ext'
4
+
5
+ require_relative 'property_config'
6
+ require_relative '../../error'
7
+
8
+ module Genome
9
+ module Core
10
+ module Helpers
11
+ module Property
12
+ extend ActiveSupport::Concern
13
+
14
+ included do
15
+ class_attribute :property_configs, default: {}
16
+ end
17
+
18
+ module ClassMethods
19
+ def property(property_name, property_options = {})
20
+ raise Error::DuplicateProperty, "Property already defined '#{property_name}'" if self.property_configs.key?(property_name)
21
+
22
+ property_configs[property_name] = PropertyConfig.new(property_options)
23
+ end
24
+
25
+ def valid_property?(property_name, property_value)
26
+ property_configs[property_name].valid?(property_value)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ module Genome
2
+ module Core
3
+ module Helpers
4
+ class PropertyConfig
5
+ attr_reader :settable, :nullable
6
+
7
+ def initialize(options = {})
8
+ @settable = options[:settable]
9
+ @nullable = options[:nullable]
10
+ end
11
+
12
+
13
+ def valid?(property_value)
14
+ return false if !nullable && property_value == nil
15
+
16
+ true
17
+ end
18
+
19
+ def to_h
20
+ {
21
+ settable: settable,
22
+ nullable: nullable
23
+ }
24
+ end
25
+
26
+ alias :settable? :settable
27
+ alias :nullable? :nullable
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,45 @@
1
+ require 'active_support/concern'
2
+
3
+ module Genome
4
+ module Core
5
+ module Helpers
6
+ module Template
7
+ extend ActiveSupport::Concern
8
+
9
+ attr_reader :template_name, :parameters, :dependencies
10
+
11
+ def initialize(template_name, template_parameters, dependencies)
12
+ @template_name = template_name
13
+ @parameters = {}
14
+ @dependencies = dependencies || []
15
+
16
+ template_parameters.each do |parameter_name, parameter_value|
17
+ if property_configs.key?(parameter_name)
18
+ @parameters[parameter_name] = parameter_value
19
+ end
20
+ end
21
+ end
22
+
23
+ def to_h
24
+ {
25
+ template_name => {
26
+ Type: self.class.aws_template,
27
+ Properties: parameters,
28
+ DependsOn: dependencies
29
+ }
30
+ }
31
+ end
32
+
33
+ module ClassMethods
34
+ def aws_template(aws_template_value = nil)
35
+ if aws_template_value
36
+ @aws_template = aws_template_value
37
+ else
38
+ @aws_template
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,19 @@
1
+ require 'active_support/concern'
2
+
3
+ require_relative '../helpers/template'
4
+ require_relative '../helpers/property'
5
+
6
+ module Genome
7
+ module Core
8
+ module Templates
9
+ module Base
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ include Helpers::Property
14
+ include Helpers::Template
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'base'
2
+
3
+ module Genome
4
+ module Core
5
+ module Templates
6
+ class DocumentDBCluster
7
+ include Base
8
+
9
+ aws_template 'AWS::DocDB::DBCluster'
10
+
11
+ property :AvailabilityZones
12
+ property :BackupRetentionPeriod
13
+ property :DBClusterIdentifier
14
+ property :DBClusterParameterGroupName
15
+ property :DBSubnetGroupName
16
+ property :EngineVersion
17
+ property :KmsKeyId
18
+ property :MasterUsername
19
+ property :MasterUserPassword
20
+ property :Port
21
+ property :PreferredBackupWindow
22
+ property :PreferredMaintenanceWindow
23
+ property :SnapshotIdentifier
24
+ property :StorageEncrypted
25
+ property :Tags
26
+ property :VpcSecurityGroupIds
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'base'
2
+
3
+ module Genome
4
+ module Core
5
+ module Templates
6
+ class DocumentDBInstance
7
+ include Base
8
+
9
+ aws_template 'AWS::DocDB::DBInstance'
10
+
11
+ property :AutoMinorVersionUpgrade
12
+ property :AvailabilityZone
13
+ property :DBClusterIdentifier
14
+ property :DBInstanceClass
15
+ property :DBInstanceIdentifier
16
+ property :PreferredMaintenanceWindow
17
+ property :Tags
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'base'
2
+
3
+ module Genome
4
+ module Core
5
+ module Templates
6
+ class DocumentDBParameterGroup
7
+ include Base
8
+
9
+ aws_template 'AWS::DocDB::DBClusterParameterGroup'
10
+
11
+ property :Description
12
+ property :Family
13
+ property :Name
14
+ property :Parameters
15
+ property :Tags
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'base'
2
+
3
+ module Genome
4
+ module Core
5
+ module Templates
6
+ class DocumentDBSubnetGroup
7
+ include Base
8
+
9
+ aws_template 'AWS::DocDB::DBSubnetGroup'
10
+
11
+ property :DBSubnetGroupDescription
12
+ property :DBSubnetGroupName
13
+ property :SubnetIds
14
+ property :Tags
15
+ end
16
+ end
17
+ end
18
+ end