aws-spec-etl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +12 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +10 -0
- data/aws-spec-etl.gemspec +44 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/aws/spec/etl.rb +10 -0
- data/lib/aws/spec/etl/version.rb +7 -0
- data/lib/file_sieve.rb +33 -0
- data/lib/matches.rb +29 -0
- data/lib/matches_acl_owner.rb +7 -0
- data/lib/matches_aws_access_key_id.rb +7 -0
- data/lib/matches_aws_profile.rb +7 -0
- data/lib/matches_aws_secret_access_key.rb +7 -0
- data/lib/matches_aws_security_token.rb +7 -0
- data/lib/matches_aws_session_token.rb +7 -0
- data/lib/matches_aws_token_etl.rb +7 -0
- data/lib/matches_cloudfront.rb +7 -0
- data/lib/matches_context_line.rb +7 -0
- data/lib/matches_describe_line.rb +7 -0
- data/lib/matches_devint.rb +7 -0
- data/lib/matches_ft.rb +7 -0
- data/lib/matches_have_ebs.rb +7 -0
- data/lib/matches_image_id.rb +7 -0
- data/lib/matches_infradev.rb +7 -0
- data/lib/matches_instance_id.rb +7 -0
- data/lib/matches_int.rb +7 -0
- data/lib/matches_mfa_serial.rb +7 -0
- data/lib/matches_name.rb +7 -0
- data/lib/matches_network_interface_line.rb +7 -0
- data/lib/matches_output.rb +7 -0
- data/lib/matches_ppd.rb +7 -0
- data/lib/matches_private_dns_name_line.rb +7 -0
- data/lib/matches_private_ip_address_line.rb +7 -0
- data/lib/matches_prod_prod.rb +7 -0
- data/lib/matches_region.rb +7 -0
- data/lib/matches_require_line.rb +7 -0
- data/lib/matches_role_arn.rb +7 -0
- data/lib/matches_source_profile.rb +7 -0
- data/lib/matches_stg.rb +7 -0
- data/lib/self_heal.rb +35 -0
- data/lib/spec_rb_transformer.rb +197 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 80d4a7535b9423afbf053966c775605b30b4e257bef41c2b9e32cdabd0f9d8fc
|
4
|
+
data.tar.gz: abb69be71b6a04d22068a151ceeb1b08ef75e95da9e97da6e0f172bb7cc20ae7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1db8d8ff76d1fae969749d52f1eec206ed5485354b85915b512a95577a399c29407eb3430f983f94fb47c8e8077805e4dae1e77a79e615cf921dd10622292f00
|
7
|
+
data.tar.gz: b94d8f895dd385aa6246c79b711047daf0e8a68616beb1e51ced02bdf54029103aef3c129c085909f24f54036bba00ee90dccf0298391083dd0dc5e0d81dec71
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
|
8
|
+
## [0.1.0] - 04-12-2018
|
9
|
+
### Added
|
10
|
+
- Ability to parse, refactor and save awspec generate
|
11
|
+
- Gemspec file updated to enable push to Rubygems.org
|
12
|
+
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 Bradley.Atkins@bjss.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
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
aws-spec-etl (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (5.2.1)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (>= 0.7, < 2)
|
12
|
+
minitest (~> 5.1)
|
13
|
+
tzinfo (~> 1.1)
|
14
|
+
concurrent-ruby (1.1.3)
|
15
|
+
i18n (1.1.1)
|
16
|
+
concurrent-ruby (~> 1.0)
|
17
|
+
minitest (5.11.3)
|
18
|
+
rake (10.5.0)
|
19
|
+
thread_safe (0.3.6)
|
20
|
+
tzinfo (1.2.5)
|
21
|
+
thread_safe (~> 0.1)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
activesupport
|
28
|
+
aws-spec-etl!
|
29
|
+
bundler (~> 1.17)
|
30
|
+
minitest (~> 5.0)
|
31
|
+
rake (~> 10.0)
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
1.17.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Bradley Atkins
|
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,43 @@
|
|
1
|
+
# Aws::Spec::Etl
|
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/aws/spec/etl`. 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 'aws-spec-etl'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install aws-spec-etl
|
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. Then, run `rake test` to run the tests. 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]/aws-spec-etl. 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.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Aws::Spec::Etl project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/aws-spec-etl/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('..' + File::SEPARATOR + 'lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'aws/spec/etl/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'aws-spec-etl'
|
9
|
+
spec.version = Aws::Spec::Etl::VERSION
|
10
|
+
spec.authors = ['Bradley Atkins']
|
11
|
+
spec.email = ['Bradley.Atkins@bjss.com']
|
12
|
+
|
13
|
+
spec.summary = 'Refactor tests generated by awspec generate'
|
14
|
+
spec.description = 'Refactor tests generated by awspec generate tool '\
|
15
|
+
'in order to make them more generic. i.e. remove '\
|
16
|
+
'hard coded references to resources or swap for regex'
|
17
|
+
spec.homepage = 'https://github.com/museadmin/aws-spec-etl'
|
18
|
+
spec.license = 'MIT'
|
19
|
+
|
20
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
21
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
22
|
+
if spec.respond_to?(:metadata)
|
23
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
24
|
+
spec.metadata['source_code_uri'] = 'https://github.com/museadmin/aws-spec-etl'
|
25
|
+
spec.metadata['changelog_uri'] = 'https://github.com/museadmin/blob/master/CHANGELOG.md'
|
26
|
+
else
|
27
|
+
raise 'RubyGems 2.0 or newer is required to protect against '\
|
28
|
+
'public gem pushes.'
|
29
|
+
end
|
30
|
+
|
31
|
+
# Specify which files should be added to the gem when it is released.
|
32
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
33
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
34
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
35
|
+
end
|
36
|
+
spec.bindir = 'exe'
|
37
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
|
+
spec.require_paths = ['lib']
|
39
|
+
|
40
|
+
spec.add_development_dependency 'activesupport'
|
41
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
42
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
43
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
44
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "aws/spec/etl"
|
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
data/lib/aws/spec/etl.rb
ADDED
data/lib/file_sieve.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Traverse a directory tree looking for files with a specific extension
|
4
|
+
class FileSieve
|
5
|
+
attr_reader :found_files
|
6
|
+
|
7
|
+
def initialize(directory, extension)
|
8
|
+
@found_files = []
|
9
|
+
@extension = extension
|
10
|
+
@search_directory = directory
|
11
|
+
sieve(directory)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Recursively search the directory tree for files with @extension
|
15
|
+
def sieve(directory)
|
16
|
+
de_dot(Dir.entries(directory)).each { |file|
|
17
|
+
search = File.absolute_path(directory + File::SEPARATOR + file)
|
18
|
+
if File.directory?(search)
|
19
|
+
sieve(search)
|
20
|
+
elsif file.match?(@extension)
|
21
|
+
@found_files.push(search)
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Clean away . and .. from the directory list
|
27
|
+
def de_dot(list)
|
28
|
+
list.delete('.')
|
29
|
+
list.delete('..')
|
30
|
+
list
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/matches.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'matches_acl_owner'
|
2
|
+
require_relative 'matches_aws_access_key_id'
|
3
|
+
require_relative 'matches_aws_secret_access_key'
|
4
|
+
require_relative 'matches_aws_session_token'
|
5
|
+
require_relative 'matches_aws_security_token'
|
6
|
+
require_relative 'matches_aws_token_etl'
|
7
|
+
require_relative 'matches_aws_profile'
|
8
|
+
require_relative 'matches_context_line'
|
9
|
+
require_relative 'matches_cloudfront'
|
10
|
+
require_relative 'matches_describe_line'
|
11
|
+
require_relative 'matches_devint'
|
12
|
+
require_relative 'matches_ft'
|
13
|
+
require_relative 'matches_have_ebs'
|
14
|
+
require_relative 'matches_infradev'
|
15
|
+
require_relative 'matches_int'
|
16
|
+
require_relative 'matches_instance_id'
|
17
|
+
require_relative 'matches_image_id'
|
18
|
+
require_relative 'matches_mfa_serial'
|
19
|
+
require_relative 'matches_network_interface_line'
|
20
|
+
require_relative 'matches_output'
|
21
|
+
require_relative 'matches_ppd'
|
22
|
+
require_relative 'matches_private_dns_name_line'
|
23
|
+
require_relative 'matches_private_ip_address_line'
|
24
|
+
require_relative 'matches_prod_prod'
|
25
|
+
require_relative 'matches_region'
|
26
|
+
require_relative 'matches_require_line'
|
27
|
+
require_relative 'matches_role_arn'
|
28
|
+
require_relative 'matches_source_profile'
|
29
|
+
require_relative 'matches_stg'
|
data/lib/matches_ft.rb
ADDED
data/lib/matches_int.rb
ADDED
data/lib/matches_name.rb
ADDED
data/lib/matches_ppd.rb
ADDED
data/lib/matches_stg.rb
ADDED
data/lib/self_heal.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'awspec'
|
2
|
+
|
3
|
+
module SelfHeal
|
4
|
+
|
5
|
+
'''this function takes a previously captured EC2 instance name and chacks it against the current
|
6
|
+
inventory. If the resource is found or can be pattern matched to a matching one with a dynamic element updated
|
7
|
+
the function returns the resource name, otherwise its false'''
|
8
|
+
|
9
|
+
def dynamic_resource(item)
|
10
|
+
unless ec2(item).exists?
|
11
|
+
resource = Aws::EC2::Resource.new(region: 'eu-west-2')
|
12
|
+
capture_group = item.match(/([a-z]+-)([a-z|0-9]+)(\..+)/)
|
13
|
+
|
14
|
+
if capture_group
|
15
|
+
network_item = capture_group[1]
|
16
|
+
environment = capture_group[3]
|
17
|
+
|
18
|
+
resource.instances.each do | i |
|
19
|
+
i.tags.each do | tag |
|
20
|
+
if tag.key == 'Name'
|
21
|
+
name = tag.value
|
22
|
+
regex = /\b#{Regexp.quote(network_item)}[0-9|a-z]+#{Regexp.quote(environment)}\b/
|
23
|
+
if name.match(regex) #unless
|
24
|
+
return name
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
item
|
32
|
+
end
|
33
|
+
module_function :dynamic_resource
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,197 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'file_sieve'
|
4
|
+
require_relative 'matches'
|
5
|
+
require 'active_support'
|
6
|
+
require 'active_support/core_ext'
|
7
|
+
|
8
|
+
# Transform a generated spec.rb file for running
|
9
|
+
class SpecRbTransformer
|
10
|
+
|
11
|
+
TEST_EXTENSION = '_spec.rb'
|
12
|
+
REMOVALS = %w(blddev- bldinf- default)
|
13
|
+
ENVIRONMENTS = %w(non_prod prod)
|
14
|
+
|
15
|
+
def initialize(search_directory, target_root_directory)
|
16
|
+
@target_root_directory = File.absolute_path(target_root_directory) + File::SEPARATOR
|
17
|
+
@sieve = FileSieve.new(search_directory, TEST_EXTENSION)
|
18
|
+
@tag = ''
|
19
|
+
@described = false
|
20
|
+
end
|
21
|
+
|
22
|
+
def transform
|
23
|
+
@sieve.found_files.each {|file|
|
24
|
+
parse_environment_tag_from_test_file(file)
|
25
|
+
basename = File.basename(file)
|
26
|
+
type = parse_object_type_from_file_name(basename)
|
27
|
+
account = parse_account_from_context_line(file)
|
28
|
+
target_file = setup_generator_output(type, account, basename)
|
29
|
+
|
30
|
+
File.delete(target_file) if File.exist?(target_file)
|
31
|
+
@describe = false
|
32
|
+
|
33
|
+
File.open(target_file, 'w') do |wr|
|
34
|
+
File.foreach(file) do |line|
|
35
|
+
line = transform_line(line)
|
36
|
+
wr.write(line)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
clean_end_of_file(target_file)
|
41
|
+
REMOVALS.each {|pattern| delete_test_block(pattern, target_file)}
|
42
|
+
|
43
|
+
File.delete(target_file) unless @described
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
# Sort out indentation of last end statement
|
48
|
+
def clean_end_of_file(file)
|
49
|
+
lines = File.readlines(file)
|
50
|
+
(lines.length - 1).step(0, -1) do |i|
|
51
|
+
if lines[i] == " end\n"
|
52
|
+
lines[i] = "end\n"
|
53
|
+
break
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
File.open(file, 'w') do |f|
|
58
|
+
lines.each do |line|
|
59
|
+
f.write(line)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Create the context description
|
65
|
+
def construct_test_context(basename)
|
66
|
+
vpc = basename.split('_')[2]
|
67
|
+
partition = basename.split('_')[0].to_s.upcase
|
68
|
+
partition + ' Tests on ' + vpc
|
69
|
+
end
|
70
|
+
|
71
|
+
# Delete an entire test block if the description matches the pattern
|
72
|
+
def delete_test_block(pattern, file)
|
73
|
+
lines = File.readlines(file)
|
74
|
+
remove = false
|
75
|
+
File.delete(file)
|
76
|
+
File.open(file, 'w') do |f|
|
77
|
+
lines.each do |line|
|
78
|
+
remove = true if line.include?('describe ') && line.include?(pattern)
|
79
|
+
if remove
|
80
|
+
remove = false if line.include?(' end')
|
81
|
+
next
|
82
|
+
end
|
83
|
+
f.write(line)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Insert the dynamic_resource call
|
89
|
+
def insert_dynamic_resource(line)
|
90
|
+
line.insert(line.index('(') + 1, 'dynamic_resource(')
|
91
|
+
line.insert(line.index(')'), ')')
|
92
|
+
line
|
93
|
+
end
|
94
|
+
|
95
|
+
# Insert any tags
|
96
|
+
def insert_environment_tag(line)
|
97
|
+
line = line.slice(0, line.index(' do'))
|
98
|
+
line + @tag + ' do' + "\n"
|
99
|
+
end
|
100
|
+
|
101
|
+
# Parse the account (prod / non_prod) from the context line of a test
|
102
|
+
def parse_account_from_context_line(file)
|
103
|
+
File.readlines(file).each do |line|
|
104
|
+
ENVIRONMENTS.each {|env| return env if line.include?(env)}
|
105
|
+
end
|
106
|
+
raise(RuntimeError, 'Failed to find account from context line in file (' + file + ')')
|
107
|
+
end
|
108
|
+
|
109
|
+
# What environment referenced in file
|
110
|
+
def parse_environment_tag_from_test_file(file)
|
111
|
+
File.foreach(file) do |line|
|
112
|
+
if line.include?('describe')
|
113
|
+
set_environment_tag(line)
|
114
|
+
return
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# Parse the object type from the file name
|
120
|
+
def parse_object_type_from_file_name(file)
|
121
|
+
file[0, file.index('_on')]
|
122
|
+
end
|
123
|
+
|
124
|
+
# Change private dns line
|
125
|
+
def replace_ip_with_regex_in_line(line)
|
126
|
+
|
127
|
+
first = line.slice(0, line.index('{') + 1)
|
128
|
+
last = line.slice(line.index('.'), line.length)
|
129
|
+
.gsub(/\./, '\.')
|
130
|
+
.tr("'", '/')
|
131
|
+
first + ' should match /ip-[\d]{1,3}-[\d]{1,3}-[\d]{1,3}-[\d]{1,3}' + last
|
132
|
+
end
|
133
|
+
|
134
|
+
# Change private ip line
|
135
|
+
def replace_private_ip_with_regex(line)
|
136
|
+
line = line.slice(0, line.index('{') + 1)
|
137
|
+
line + ' should match /[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}/ }' + "\n"
|
138
|
+
end
|
139
|
+
|
140
|
+
# Set the class tag var
|
141
|
+
def set_environment_tag(line)
|
142
|
+
case line
|
143
|
+
when MatchesInt
|
144
|
+
@tag = ', int: true'
|
145
|
+
when MatchesDevint
|
146
|
+
@tag = ', devint: true'
|
147
|
+
when MatchesFt
|
148
|
+
@tag = ', ft: true'
|
149
|
+
when MatchesInfradev
|
150
|
+
@tag = ', infradev: true'
|
151
|
+
when MatchesPpd
|
152
|
+
@tag = ', ppd: true'
|
153
|
+
when MatchesStg
|
154
|
+
@tag = ', stg: true'
|
155
|
+
else
|
156
|
+
@tag = ''
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# Set the output file for a generator and create sub dir if not set
|
161
|
+
def setup_generator_output(type, account, file)
|
162
|
+
directory = @target_root_directory + "#{type}_tests_#{account}"
|
163
|
+
FileUtils.mkdir_p directory unless Dir.exists?(directory)
|
164
|
+
File.absolute_path(directory) + File::SEPARATOR + file
|
165
|
+
end
|
166
|
+
|
167
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
168
|
+
def transform_line(line)
|
169
|
+
line = ' ' + line
|
170
|
+
case line
|
171
|
+
when MatchesAclOwner
|
172
|
+
line = ''
|
173
|
+
when MatchesContextLine
|
174
|
+
line.lstrip!
|
175
|
+
line = insert_environment_tag(line)
|
176
|
+
when MatchesDescribeLine
|
177
|
+
line = insert_dynamic_resource(line)
|
178
|
+
@described = true
|
179
|
+
when MatchesHaveEbs
|
180
|
+
return ''
|
181
|
+
# Uncomment to ignore :image_id and :instance_id
|
182
|
+
# when MatchesImageId
|
183
|
+
# return ''
|
184
|
+
# when MatchesInstanceId
|
185
|
+
# return ''
|
186
|
+
when MatchesNetworkInterfaceLine
|
187
|
+
return ''
|
188
|
+
when MatchesPrivateDnsNameLine
|
189
|
+
line = replace_ip_with_regex_in_line(line)
|
190
|
+
when MatchesPrivateIpAddressLine
|
191
|
+
line = replace_private_ip_with_regex(line)
|
192
|
+
when MatchesRequireLine
|
193
|
+
line = line.strip! + "\n"
|
194
|
+
end
|
195
|
+
line
|
196
|
+
end
|
197
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws-spec-etl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bradley Atkins
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.17'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.17'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Refactor tests generated by awspec generate tool in order to make them
|
70
|
+
more generic. i.e. remove hard coded references to resources or swap for regex
|
71
|
+
email:
|
72
|
+
- Bradley.Atkins@bjss.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CHANGELOG.md
|
80
|
+
- CODE_OF_CONDUCT.md
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- aws-spec-etl.gemspec
|
87
|
+
- bin/console
|
88
|
+
- bin/setup
|
89
|
+
- lib/aws/spec/etl.rb
|
90
|
+
- lib/aws/spec/etl/version.rb
|
91
|
+
- lib/file_sieve.rb
|
92
|
+
- lib/matches.rb
|
93
|
+
- lib/matches_acl_owner.rb
|
94
|
+
- lib/matches_aws_access_key_id.rb
|
95
|
+
- lib/matches_aws_profile.rb
|
96
|
+
- lib/matches_aws_secret_access_key.rb
|
97
|
+
- lib/matches_aws_security_token.rb
|
98
|
+
- lib/matches_aws_session_token.rb
|
99
|
+
- lib/matches_aws_token_etl.rb
|
100
|
+
- lib/matches_cloudfront.rb
|
101
|
+
- lib/matches_context_line.rb
|
102
|
+
- lib/matches_describe_line.rb
|
103
|
+
- lib/matches_devint.rb
|
104
|
+
- lib/matches_ft.rb
|
105
|
+
- lib/matches_have_ebs.rb
|
106
|
+
- lib/matches_image_id.rb
|
107
|
+
- lib/matches_infradev.rb
|
108
|
+
- lib/matches_instance_id.rb
|
109
|
+
- lib/matches_int.rb
|
110
|
+
- lib/matches_mfa_serial.rb
|
111
|
+
- lib/matches_name.rb
|
112
|
+
- lib/matches_network_interface_line.rb
|
113
|
+
- lib/matches_output.rb
|
114
|
+
- lib/matches_ppd.rb
|
115
|
+
- lib/matches_private_dns_name_line.rb
|
116
|
+
- lib/matches_private_ip_address_line.rb
|
117
|
+
- lib/matches_prod_prod.rb
|
118
|
+
- lib/matches_region.rb
|
119
|
+
- lib/matches_require_line.rb
|
120
|
+
- lib/matches_role_arn.rb
|
121
|
+
- lib/matches_source_profile.rb
|
122
|
+
- lib/matches_stg.rb
|
123
|
+
- lib/self_heal.rb
|
124
|
+
- lib/spec_rb_transformer.rb
|
125
|
+
homepage: https://github.com/museadmin/aws-spec-etl
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata:
|
129
|
+
homepage_uri: https://github.com/museadmin/aws-spec-etl
|
130
|
+
source_code_uri: https://github.com/museadmin/aws-spec-etl
|
131
|
+
changelog_uri: https://github.com/museadmin/blob/master/CHANGELOG.md
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 2.7.8
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: Refactor tests generated by awspec generate
|
152
|
+
test_files: []
|