soltius-ci 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +104 -0
- data/LICENSE.md +7 -0
- data/README.md +1 -0
- data/Rakefile +8 -0
- data/VERSION +1 -0
- data/bin/console +7 -0
- data/bin/setup +8 -0
- data/ext/Makefile.erb +16 -0
- data/ext/extconf.rb +56 -0
- data/ext/libhcl.go +45 -0
- data/lib/soltius/ci.rb +6 -0
- data/lib/soltius/ci/version.rb +5 -0
- data/lib/soltius/terraform/actions.rb +17 -0
- data/lib/soltius/terraform/rake_tasks.rb +9 -0
- data/lib/soltius/terraform_module/rake_tasks.rb +70 -0
- data/lib/soltius/terraform_module/spec_helper_contract.rb +8 -0
- data/lib/soltius/terraform_module/spec_helper_integration.rb +32 -0
- data/lib/soltius/utils/array.rb +19 -0
- data/lib/soltius/utils/aws.rb +45 -0
- data/lib/soltius/utils/hcl.rb +80 -0
- data/soltius-ci.gemspec +36 -0
- metadata +210 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0a6e58c68b68ceeafeb40f8050185b349e8c4aba
|
4
|
+
data.tar.gz: 2c62047398227fab9b5da519d4e2a3d52ad445cc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d1cd8ddab87b1db431887f90c4f7201bebca3a4b69c03716f825fef15e638691f5076bfa5ae3ce0af8df12cb992fb9f24b85d9958c496daccd052c26cd350dc0
|
7
|
+
data.tar.gz: 7d472ad46df0e5d449510cbb1735a7b420da1201deb3135a9d952ae0c70a1980f93c217ea76ebcbe2e3e86afbd2dbf70ce7c64d784e1e2d9f68247f9a6db8bcb
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Bundler
|
2
|
+
**/.bundle/
|
3
|
+
**/coverage/
|
4
|
+
**/doc/
|
5
|
+
**/pkg/
|
6
|
+
**/spec/reports/
|
7
|
+
**/tmp/
|
8
|
+
**/*.gem
|
9
|
+
vendor/
|
10
|
+
|
11
|
+
# RSpec failure tracking
|
12
|
+
.rspec_status
|
13
|
+
spec/rspec.xml
|
14
|
+
|
15
|
+
# Go
|
16
|
+
**/Makefile
|
17
|
+
**/*.so
|
18
|
+
**/*.h
|
19
|
+
|
20
|
+
# Ruby
|
21
|
+
ext/use_json2hcl.rb
|
22
|
+
|
23
|
+
# General
|
24
|
+
**/.DS_Store
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
soltius-ci (0.0.1)
|
5
|
+
aws-sdk
|
6
|
+
awsecrets (~> 1.13)
|
7
|
+
awspec (~> 0.85.2)
|
8
|
+
ffi (~> 1.9)
|
9
|
+
rake-terraform (~> 0.2.2)
|
10
|
+
rspec-json_expectations (~> 2.1)
|
11
|
+
rspec_junit_formatter (~> 0.3)
|
12
|
+
|
13
|
+
GEM
|
14
|
+
remote: https://rubygems.org/
|
15
|
+
specs:
|
16
|
+
activesupport (4.2.9)
|
17
|
+
i18n (~> 0.7)
|
18
|
+
minitest (~> 5.1)
|
19
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
20
|
+
tzinfo (~> 1.1)
|
21
|
+
aws-sdk (2.10.47)
|
22
|
+
aws-sdk-resources (= 2.10.47)
|
23
|
+
aws-sdk-core (2.10.47)
|
24
|
+
aws-sigv4 (~> 1.0)
|
25
|
+
jmespath (~> 1.0)
|
26
|
+
aws-sdk-resources (2.10.47)
|
27
|
+
aws-sdk-core (= 2.10.47)
|
28
|
+
aws-sigv4 (1.0.2)
|
29
|
+
aws_config (0.1.0)
|
30
|
+
awsecrets (1.13.0)
|
31
|
+
aws-sdk (>= 2, < 4)
|
32
|
+
aws_config (~> 0.1.0)
|
33
|
+
awspec (0.85.2)
|
34
|
+
activesupport (~> 4.0)
|
35
|
+
aws-sdk (>= 2.2, < 2.11)
|
36
|
+
awsecrets (~> 1.12)
|
37
|
+
rspec (~> 3.0)
|
38
|
+
rspec-its
|
39
|
+
term-ansicolor
|
40
|
+
thor
|
41
|
+
coderay (1.1.2)
|
42
|
+
diff-lcs (1.3)
|
43
|
+
dotenv (2.0.2)
|
44
|
+
ffi (1.9.18)
|
45
|
+
highline (1.7.8)
|
46
|
+
i18n (0.8.6)
|
47
|
+
iniparse (1.4.4)
|
48
|
+
jmespath (1.3.1)
|
49
|
+
map (6.6.0)
|
50
|
+
method_source (0.8.2)
|
51
|
+
minitest (5.10.3)
|
52
|
+
pry (0.10.4)
|
53
|
+
coderay (~> 1.1.0)
|
54
|
+
method_source (~> 0.8.1)
|
55
|
+
slop (~> 3.4)
|
56
|
+
rake (12.1.0)
|
57
|
+
rake-terraform (0.2.2)
|
58
|
+
dotenv (~> 2.0.0)
|
59
|
+
highline (~> 1.7)
|
60
|
+
iniparse (~> 1.3)
|
61
|
+
map (~> 6.5)
|
62
|
+
rake (~> 12.0)
|
63
|
+
wannabe_bool (~> 0.3.0)
|
64
|
+
rspec (3.6.0)
|
65
|
+
rspec-core (~> 3.6.0)
|
66
|
+
rspec-expectations (~> 3.6.0)
|
67
|
+
rspec-mocks (~> 3.6.0)
|
68
|
+
rspec-core (3.6.0)
|
69
|
+
rspec-support (~> 3.6.0)
|
70
|
+
rspec-expectations (3.6.0)
|
71
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
72
|
+
rspec-support (~> 3.6.0)
|
73
|
+
rspec-its (1.2.0)
|
74
|
+
rspec-core (>= 3.0.0)
|
75
|
+
rspec-expectations (>= 3.0.0)
|
76
|
+
rspec-json_expectations (2.1.0)
|
77
|
+
rspec-mocks (3.6.0)
|
78
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
79
|
+
rspec-support (~> 3.6.0)
|
80
|
+
rspec-support (3.6.0)
|
81
|
+
rspec_junit_formatter (0.3.0)
|
82
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
83
|
+
slop (3.6.0)
|
84
|
+
term-ansicolor (1.6.0)
|
85
|
+
tins (~> 1.0)
|
86
|
+
thor (0.20.0)
|
87
|
+
thread_safe (0.3.6)
|
88
|
+
tins (1.15.0)
|
89
|
+
tzinfo (1.2.3)
|
90
|
+
thread_safe (~> 0.1)
|
91
|
+
wannabe_bool (0.3.0)
|
92
|
+
|
93
|
+
PLATFORMS
|
94
|
+
ruby
|
95
|
+
|
96
|
+
DEPENDENCIES
|
97
|
+
bundler (~> 1.16.a)
|
98
|
+
pry (~> 0.10)
|
99
|
+
rake (~> 12.0)
|
100
|
+
rspec (~> 3.0)
|
101
|
+
soltius-ci!
|
102
|
+
|
103
|
+
BUNDLED WITH
|
104
|
+
1.16.0.pre.2
|
data/LICENSE.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2017 Soltius New Zealand Ltd.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# gem-soltius-ci
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v0.0.1
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/ext/Makefile.erb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
.PHONY: build clean install
|
2
|
+
|
3
|
+
export DIR = $(shell pwd)
|
4
|
+
|
5
|
+
clean:
|
6
|
+
install:
|
7
|
+
|
8
|
+
build:
|
9
|
+
<% if !find_go.nil? && !find_make.nil? %>
|
10
|
+
<%= "\t" %>go get -v -d ./...
|
11
|
+
<%= "\t" %>go build -buildmode=c-shared -o libhcl.so libhcl.go
|
12
|
+
<% elsif !find_docker.nil? %>
|
13
|
+
<%= "\t" %>docker run --rm -v $(DIR):/go/libhcl -w /go/libhcl golang:1.8 make gobuild
|
14
|
+
<% elsif !find_json2hcl.nil? %>
|
15
|
+
<%= "\t" %>echo "<%= find_json2hcl %>" > json2hcl.rb
|
16
|
+
<% end %>
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
def which(cmd)
|
2
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
3
|
+
exe = File.join(path, cmd)
|
4
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
5
|
+
end
|
6
|
+
return nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def check_for(what)
|
10
|
+
$stdout.print("checking for #{what}... ")
|
11
|
+
$stdout.flush
|
12
|
+
|
13
|
+
result = which(what)
|
14
|
+
|
15
|
+
$stdout.puts(result.nil? ? 'no' : 'yes')
|
16
|
+
$stdout.flush
|
17
|
+
|
18
|
+
result
|
19
|
+
end
|
20
|
+
|
21
|
+
find_docker = check_for 'docker'
|
22
|
+
find_go = check_for 'go'
|
23
|
+
find_make = check_for 'make'
|
24
|
+
find_json2hcl = check_for 'json2hcl'
|
25
|
+
|
26
|
+
if find_json2hcl.nil? && find_docker.nil? && (find_go.nil? || find_make.nil?)
|
27
|
+
abort('Unable to build HCL parser using Docker or native GO, or to find executable "json2hcl". Aborting')
|
28
|
+
end
|
29
|
+
|
30
|
+
require 'erb'
|
31
|
+
template = ERB.new(File.read(File.expand_path('Makefile.erb', __dir__)), nil, '<>')
|
32
|
+
makefile = File.expand_path('Makefile', __dir__)
|
33
|
+
$makefile_created = true
|
34
|
+
|
35
|
+
File.write(makefile, template.result())
|
36
|
+
|
37
|
+
# unless find_go.nil? || find_make.nil?
|
38
|
+
# puts 'Building libhcl using local Go Compiler'
|
39
|
+
# open(makefile, 'a') { |f| f << "build: gobuild\n" }
|
40
|
+
# exit(0)
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# unless find_docker.nil?
|
44
|
+
# puts 'Building libhcl using Docker "golang:1.8"'
|
45
|
+
# open(makefile, 'a') { |f| f << "build: dockerbuild\n" }
|
46
|
+
# exit(0)
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# unless find_json2hcl.nil?
|
50
|
+
# puts "Using #{find_json2hcl} as the HCL parser"
|
51
|
+
# File.write(File.join(__dir__, 'json2hcl.rb'), find_json2hcl)
|
52
|
+
# open(makefile, 'a') { |f| f << "build: json2hclbuild\n" }
|
53
|
+
# exit(0)
|
54
|
+
# end
|
55
|
+
|
56
|
+
# abort('Unable to build HCL parser using Docker or native GO, or to find executable "json2hcl". Aborting')
|
data/ext/libhcl.go
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
package main
|
2
|
+
|
3
|
+
import (
|
4
|
+
"fmt"
|
5
|
+
"io/ioutil"
|
6
|
+
"encoding/json"
|
7
|
+
"github.com/hashicorp/hcl"
|
8
|
+
)
|
9
|
+
|
10
|
+
import "C"
|
11
|
+
|
12
|
+
func hcl_to_json(input string) string {
|
13
|
+
var v interface{}
|
14
|
+
err := hcl.Unmarshal([]byte(input), &v)
|
15
|
+
if err != nil {
|
16
|
+
return fmt.Sprintf("ERROR: %s", err.Error())
|
17
|
+
}
|
18
|
+
|
19
|
+
json, err := json.Marshal(v)
|
20
|
+
if err != nil {
|
21
|
+
return fmt.Sprintf("ERROR: %s", err.Error())
|
22
|
+
}
|
23
|
+
|
24
|
+
return string(json)
|
25
|
+
}
|
26
|
+
|
27
|
+
//export to_json
|
28
|
+
func to_json(str *C.char) *C.char {
|
29
|
+
input := C.GoString(str)
|
30
|
+
json := hcl_to_json(input)
|
31
|
+
return C.CString(json)
|
32
|
+
}
|
33
|
+
|
34
|
+
//export file_to_json
|
35
|
+
func file_to_json(file *C.char) *C.char {
|
36
|
+
input, err := ioutil.ReadFile(C.GoString(file))
|
37
|
+
if err != nil {
|
38
|
+
return C.CString(fmt.Sprintf("ERROR: %s", err.Error()))
|
39
|
+
}
|
40
|
+
|
41
|
+
json := hcl_to_json(string(input))
|
42
|
+
return C.CString(json)
|
43
|
+
}
|
44
|
+
|
45
|
+
func main() {}
|
data/lib/soltius/ci.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'rake/tasklib'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'soltius/terraform/rake_tasks'
|
4
|
+
|
5
|
+
module Soltius
|
6
|
+
module TerraformModule
|
7
|
+
# Terraform Rake task generator.
|
8
|
+
#
|
9
|
+
# @author Igor Gentil <igor.lg@gmail.com>
|
10
|
+
class RakeTasks < ::Rake::TaskLib
|
11
|
+
attr_accessor :path, :fixtures, :contract, :integration, :fixtures_path
|
12
|
+
# Creates Terraform Rake tasks and allows the callee to configure it.
|
13
|
+
#
|
14
|
+
# @yield [self] gives itself to the block
|
15
|
+
def initialize(path = '')
|
16
|
+
@fixtures = true
|
17
|
+
@contract = true
|
18
|
+
@integration = true
|
19
|
+
|
20
|
+
@path = path
|
21
|
+
@fixtures_path = "#{@path}/test/fixtures/*.tfvars"
|
22
|
+
|
23
|
+
yield self if block_given?
|
24
|
+
task_fixtures if @fixtures
|
25
|
+
task_contract if @contract
|
26
|
+
task_integration if @integration
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# Generates Rake task to display available Fixtures
|
32
|
+
#
|
33
|
+
# @api private
|
34
|
+
def task_fixtures
|
35
|
+
desc 'List Fixtures'
|
36
|
+
task 'test:fixtures' do
|
37
|
+
Dir[@fixtures_path].each do |f|
|
38
|
+
puts "#{File.basename(f, '.tfvars')}: (#{f.gsub(@path, '')})"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Generates Rake task to run Contract Tests
|
44
|
+
#
|
45
|
+
# @api private
|
46
|
+
def task_contract
|
47
|
+
desc 'Run Contract tests'
|
48
|
+
RSpec::Core::RakeTask.new('test:unit:contract') do |t|
|
49
|
+
t.pattern = 'test/contract/**/*_spec.rb'
|
50
|
+
t.rspec_opts = '--format documentation'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Generates Rake tasks to run AWSpec Tests for each Fixture File
|
55
|
+
#
|
56
|
+
# @api private
|
57
|
+
def task_integration
|
58
|
+
Dir[@fixtures_path].each do |f|
|
59
|
+
name = File.basename(f, '.tfvars')
|
60
|
+
desc "Integration Test for fixture #{name}"
|
61
|
+
RSpec::Core::RakeTask.new("test:integration:#{name}") do |t|
|
62
|
+
ENV['TFVARS_FILE'] = f
|
63
|
+
t.pattern 'integration/awspec/**/*_spec.rb'
|
64
|
+
t.rspec_opts = '--format documentation'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'soltius/utils/aws'
|
2
|
+
require 'soltius/utils/hcl'
|
3
|
+
|
4
|
+
module Soltius
|
5
|
+
module TerraformModule
|
6
|
+
class SpecHelperIntegration
|
7
|
+
attr_reader :tfvars
|
8
|
+
attr_accessor :tfvars_file
|
9
|
+
|
10
|
+
def initialize(path = '')
|
11
|
+
@tfvars_file = path
|
12
|
+
|
13
|
+
yield self if block_given?
|
14
|
+
setup
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def setup
|
20
|
+
# -- Load and Parse TFVars file
|
21
|
+
@tfvars = JSON.parse(Soltius::Utils::Hcl.file_to_json(tfvars_file))
|
22
|
+
|
23
|
+
# -- Assume the IAM Role specified in TFVars
|
24
|
+
Soltius::Utils::Aws.new.assume_role(@tfvars['region'], @tfvars['assume_role'])
|
25
|
+
|
26
|
+
# -- Load AWSpec framework and RSpec Expectations
|
27
|
+
require 'awspec'
|
28
|
+
require 'rspec/json_expectations'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Soltius
|
2
|
+
module Utils
|
3
|
+
module Array
|
4
|
+
# -- Helper Function: len
|
5
|
+
#
|
6
|
+
# Return the length of an Array. Zero if array is nil
|
7
|
+
#
|
8
|
+
# @param Array
|
9
|
+
# @return Integer
|
10
|
+
def len(arr)
|
11
|
+
begin
|
12
|
+
arr.length
|
13
|
+
rescue
|
14
|
+
0
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'awsecrets'
|
2
|
+
require 'aws-sdk'
|
3
|
+
|
4
|
+
module Soltius
|
5
|
+
module Utils
|
6
|
+
class Aws
|
7
|
+
def assume_role(region, role_arn)
|
8
|
+
role_session_name = 'AWSpec'
|
9
|
+
|
10
|
+
::Awsecrets.load
|
11
|
+
::Aws.config[:credentials] = ::Aws::AssumeRoleCredentials.new(
|
12
|
+
client: ::Aws::STS::Client.new(
|
13
|
+
region: region,
|
14
|
+
credentials: ::Aws.config[:credentials]
|
15
|
+
),
|
16
|
+
role_arn: role_arn,
|
17
|
+
role_session_name: role_session_name
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
# -- Helper Function: parse_arn
|
22
|
+
# Return a Hash with the elements of an AWS ARN
|
23
|
+
# Source: https://gist.github.com/gene1wood/5299969edc4ef21d8efcfea52158dd40
|
24
|
+
# (Source was in Python. Converted to Ruby)
|
25
|
+
def self.parse_arn(arn)
|
26
|
+
elements = arn.split(':')
|
27
|
+
result = {arn: elements[0],
|
28
|
+
partition: elements[1],
|
29
|
+
service: elements[2],
|
30
|
+
region: elements[3],
|
31
|
+
account: elements[4]}
|
32
|
+
if elements.length == 7
|
33
|
+
result[:resourcetype] = elements[5]
|
34
|
+
result[:resource] = elements[6]
|
35
|
+
elsif not elements[5].include? '/'
|
36
|
+
result[:resource] = elements[5]
|
37
|
+
result[:resourcetype] = None
|
38
|
+
else
|
39
|
+
result[:resourcetype], result[:resource] = elements[5].split('/')
|
40
|
+
end
|
41
|
+
return result
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module Soltius
|
4
|
+
module Utils
|
5
|
+
# HCL Parser using the official Hashicorp HCL implementation in Go
|
6
|
+
#
|
7
|
+
# @author Igor Gentil <igor.lg@gmail.com>
|
8
|
+
module LibHcl
|
9
|
+
extend FFI::Library
|
10
|
+
|
11
|
+
PATH = File.expand_path('../../../ext/libhcl.so', __dir__)
|
12
|
+
EXISTS = File.exists?(PATH)
|
13
|
+
|
14
|
+
ffi_lib PATH
|
15
|
+
|
16
|
+
# Parses a HCL String into JSON
|
17
|
+
#
|
18
|
+
# @param HCL String
|
19
|
+
#
|
20
|
+
# @return JSON String
|
21
|
+
attach_function :to_json, [:string], :string
|
22
|
+
|
23
|
+
# Reads a HCL file and parses it into JSON
|
24
|
+
#
|
25
|
+
# @param File path (absolute)
|
26
|
+
#
|
27
|
+
# @return JSON String
|
28
|
+
attach_function :file_to_json, [:string], :string
|
29
|
+
end
|
30
|
+
|
31
|
+
# HCL Parser, using json2hcl binary (https://github.com/kvz/json2hcl)
|
32
|
+
#
|
33
|
+
# @author Igor Gentil <igor.lg@gmail.com>
|
34
|
+
module Json2Hcl
|
35
|
+
PATH = File.expand_path('../../../ext/json2hcl.rb', __dir__)
|
36
|
+
EXISTS = File.exists?(PATH)
|
37
|
+
|
38
|
+
# Returns the full path to binary json2hcl from ext/json2hcl.rb
|
39
|
+
#
|
40
|
+
# @return String
|
41
|
+
def json2hcl
|
42
|
+
File.read(PATH)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Parses a HCL String into JSON
|
46
|
+
#
|
47
|
+
# @param HCL String
|
48
|
+
#
|
49
|
+
# @return JSON String
|
50
|
+
def to_json(str)
|
51
|
+
`echo #{str} | #{json2hcl} -reverse`
|
52
|
+
end
|
53
|
+
|
54
|
+
# Reads a HCL file and parses it into JSON
|
55
|
+
#
|
56
|
+
# @param File path (absolute)
|
57
|
+
#
|
58
|
+
# @return JSON String
|
59
|
+
def file_to_json(file)
|
60
|
+
`#{json2hcl} -reverse < #{file}`
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# HCL Parser. Uses compiled Go library libhcl if available, or binary json2hcl otherwise.
|
65
|
+
#
|
66
|
+
# @author Igor Gentil <igor.lg@gmail.com>
|
67
|
+
module Hcl
|
68
|
+
# Extend module LibHcl if ext/libhcl.so exists.
|
69
|
+
# Or else, extend module Json2Hcl if file ext/use_json2hcl.rb (generated by extconf.rb) exists.
|
70
|
+
# Or else, raise error.
|
71
|
+
if LibHcl::EXISTS
|
72
|
+
extend LibHcl
|
73
|
+
elsif Json2Hcl::EXISTS
|
74
|
+
extend Json2Hcl
|
75
|
+
else
|
76
|
+
raise '[Soltius::Utils::Hcl] Neither libhcl.so nor json2hcl are available.'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/soltius-ci.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'soltius/ci/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'soltius-ci'
|
8
|
+
spec.version = Soltius::Ci::VERSION
|
9
|
+
spec.authors = [ 'Igor Gentil' ]
|
10
|
+
spec.email = [ 'igor.lg@gmail.com' ]
|
11
|
+
|
12
|
+
spec.summary = 'Tools for Continuous Integration at Soltius'
|
13
|
+
spec.description = 'Tools and Helpers for Terraform, Packer, Chef and other automations'
|
14
|
+
spec.homepage = 'https://github.com/soltius/gem-ci'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = [ 'lib' ]
|
23
|
+
spec.extensions = [ 'ext/extconf.rb' ]
|
24
|
+
|
25
|
+
spec.add_dependency 'aws-sdk'
|
26
|
+
spec.add_dependency 'awsecrets', '~> 1.13'
|
27
|
+
spec.add_dependency 'awspec', '~> 0.85.2'
|
28
|
+
spec.add_dependency 'ffi', '~> 1.9'
|
29
|
+
spec.add_dependency 'rspec_junit_formatter', '~> 0.3'
|
30
|
+
spec.add_dependency 'rspec-json_expectations', '~> 2.1'
|
31
|
+
|
32
|
+
spec.add_development_dependency 'bundler', '~> 1.16.a'
|
33
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
35
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: soltius-ci
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Igor Gentil
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
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: awsecrets
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: awspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.85.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.85.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ffi
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.9'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec_junit_formatter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.3'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-json_expectations
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.1'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bundler
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.16.a
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.16.a
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '12.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '12.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: pry
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.10'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.10'
|
153
|
+
description: Tools and Helpers for Terraform, Packer, Chef and other automations
|
154
|
+
email:
|
155
|
+
- igor.lg@gmail.com
|
156
|
+
executables: []
|
157
|
+
extensions:
|
158
|
+
- ext/extconf.rb
|
159
|
+
extra_rdoc_files: []
|
160
|
+
files:
|
161
|
+
- ".gitignore"
|
162
|
+
- ".travis.yml"
|
163
|
+
- CHANGELOG.md
|
164
|
+
- Gemfile
|
165
|
+
- Gemfile.lock
|
166
|
+
- LICENSE.md
|
167
|
+
- README.md
|
168
|
+
- Rakefile
|
169
|
+
- VERSION
|
170
|
+
- bin/console
|
171
|
+
- bin/setup
|
172
|
+
- ext/Makefile.erb
|
173
|
+
- ext/extconf.rb
|
174
|
+
- ext/libhcl.go
|
175
|
+
- lib/soltius/ci.rb
|
176
|
+
- lib/soltius/ci/version.rb
|
177
|
+
- lib/soltius/terraform/actions.rb
|
178
|
+
- lib/soltius/terraform/rake_tasks.rb
|
179
|
+
- lib/soltius/terraform_module/rake_tasks.rb
|
180
|
+
- lib/soltius/terraform_module/spec_helper_contract.rb
|
181
|
+
- lib/soltius/terraform_module/spec_helper_integration.rb
|
182
|
+
- lib/soltius/utils/array.rb
|
183
|
+
- lib/soltius/utils/aws.rb
|
184
|
+
- lib/soltius/utils/hcl.rb
|
185
|
+
- soltius-ci.gemspec
|
186
|
+
homepage: https://github.com/soltius/gem-ci
|
187
|
+
licenses:
|
188
|
+
- MIT
|
189
|
+
metadata: {}
|
190
|
+
post_install_message:
|
191
|
+
rdoc_options: []
|
192
|
+
require_paths:
|
193
|
+
- lib
|
194
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
version: '0'
|
199
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - ">="
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '0'
|
204
|
+
requirements: []
|
205
|
+
rubyforge_project:
|
206
|
+
rubygems_version: 2.6.12
|
207
|
+
signing_key:
|
208
|
+
specification_version: 4
|
209
|
+
summary: Tools for Continuous Integration at Soltius
|
210
|
+
test_files: []
|