wombat-cli 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +23 -23
- data/.travis.yml +22 -27
- data/CHANGELOG.md +438 -423
- data/DESIGN.md +49 -49
- data/Gemfile +5 -5
- data/README.md +146 -146
- data/Rakefile +26 -26
- data/bin/wombat +24 -24
- data/generator_files/Vagrantfile +120 -120
- data/generator_files/cookbooks/automate/.gitignore +16 -16
- data/generator_files/cookbooks/automate/.kitchen.ec2.yml +34 -34
- data/generator_files/cookbooks/automate/.kitchen.yml +24 -24
- data/generator_files/cookbooks/automate/Berksfile +6 -6
- data/generator_files/cookbooks/automate/README.md +4 -4
- data/generator_files/cookbooks/automate/chefignore +102 -102
- data/generator_files/cookbooks/automate/libraries/_helper.rb +52 -52
- data/generator_files/cookbooks/automate/libraries/delivery_api.rb +204 -204
- data/generator_files/cookbooks/automate/libraries/delivery_project.rb +31 -31
- data/generator_files/cookbooks/automate/libraries/dsl.rb +4 -4
- data/generator_files/cookbooks/automate/metadata.rb +11 -11
- data/generator_files/cookbooks/automate/recipes/default.rb +118 -124
- data/generator_files/cookbooks/automate/recipes/update-users.rb +48 -48
- data/generator_files/cookbooks/automate/templates/delivery.erb +6 -6
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/automate.crt +26 -26
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/automate.key +27 -27
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/chef.crt +25 -25
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/chef.key +27 -27
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/compliance.crt +26 -26
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/compliance.key +27 -27
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/private.pem +27 -27
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/files/public.pub +1 -1
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/metadata.rb +3 -3
- data/generator_files/cookbooks/automate/test/fixtures/cookbooks/mock_data/recipes/default.rb +27 -27
- data/generator_files/cookbooks/automate/test/integration/default/automate_spec.rb +56 -56
- data/generator_files/cookbooks/build_node/.gitignore +16 -16
- data/generator_files/cookbooks/build_node/.kitchen.ec2.yml +37 -37
- data/generator_files/cookbooks/build_node/.kitchen.yml +23 -23
- data/generator_files/cookbooks/build_node/Berksfile +8 -8
- data/generator_files/cookbooks/build_node/README.md +4 -4
- data/generator_files/cookbooks/build_node/chefignore +102 -102
- data/generator_files/cookbooks/build_node/metadata.rb +12 -12
- data/generator_files/cookbooks/build_node/recipes/default.rb +38 -38
- data/generator_files/cookbooks/build_node/templates/client.erb +2 -2
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/automate.crt +26 -26
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/automate.key +27 -27
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/chef.crt +25 -25
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/chef.key +27 -27
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/compliance.crt +26 -26
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/compliance.key +27 -27
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/private.pem +27 -27
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/files/public.pub +1 -1
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/metadata.rb +2 -2
- data/generator_files/cookbooks/build_node/test/fixtures/cookbooks/mock_data/recipes/default.rb +18 -18
- data/generator_files/cookbooks/build_node/test/integration/default/build-node_spec.rb +40 -40
- data/generator_files/cookbooks/chef_server/.gitignore +16 -16
- data/generator_files/cookbooks/chef_server/.kitchen.ec2.yml +34 -34
- data/generator_files/cookbooks/chef_server/.kitchen.yml +24 -24
- data/generator_files/cookbooks/chef_server/Berksfile +6 -6
- data/generator_files/cookbooks/chef_server/README.md +4 -4
- data/generator_files/cookbooks/chef_server/chefignore +102 -102
- data/generator_files/cookbooks/chef_server/metadata.rb +11 -11
- data/generator_files/cookbooks/chef_server/recipes/bootstrap_users.rb +91 -91
- data/generator_files/cookbooks/chef_server/recipes/default.rb +113 -113
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/automate.crt +26 -26
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/automate.key +27 -27
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/chef.crt +25 -25
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/chef.key +27 -27
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/compliance.crt +26 -26
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/compliance.key +27 -27
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/private.pem +27 -27
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/files/public.pub +1 -1
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/metadata.rb +2 -2
- data/generator_files/cookbooks/chef_server/test/fixtures/cookbooks/mock_data/recipes/default.rb +23 -23
- data/generator_files/cookbooks/chef_server/test/integration/default/chef_server_spec.rb +50 -50
- data/generator_files/cookbooks/compliance/.gitignore +16 -16
- data/generator_files/cookbooks/compliance/.kitchen.ec2.yml +34 -34
- data/generator_files/cookbooks/compliance/.kitchen.yml +24 -24
- data/generator_files/cookbooks/compliance/Berksfile +7 -7
- data/generator_files/cookbooks/compliance/README.md +4 -4
- data/generator_files/cookbooks/compliance/chefignore +102 -102
- data/generator_files/cookbooks/compliance/metadata.rb +11 -11
- data/generator_files/cookbooks/compliance/recipes/default.rb +57 -57
- data/generator_files/cookbooks/compliance/spec/spec_helper.rb +2 -2
- data/generator_files/cookbooks/compliance/spec/unit/recipes/default_spec.rb +20 -20
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/automate.crt +26 -26
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/automate.key +27 -27
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/chef.crt +25 -25
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/chef.key +27 -27
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/compliance.crt +26 -26
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/compliance.key +27 -27
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/private.pem +27 -27
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/files/public.pub +1 -1
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/metadata.rb +4 -4
- data/generator_files/cookbooks/compliance/test/fixtures/cookbooks/mock_data/recipes/default.rb +21 -21
- data/generator_files/cookbooks/compliance/test/integration/default/compliance.rb +28 -28
- data/generator_files/cookbooks/infranodes/.gitignore +16 -16
- data/generator_files/cookbooks/infranodes/.kitchen.ec2.yml +48 -48
- data/generator_files/cookbooks/infranodes/.kitchen.yml +21 -21
- data/generator_files/cookbooks/infranodes/Berksfile +6 -6
- data/generator_files/cookbooks/infranodes/README.md +4 -4
- data/generator_files/cookbooks/infranodes/attributes/default.rb +2 -2
- data/generator_files/cookbooks/infranodes/chefignore +102 -102
- data/generator_files/cookbooks/infranodes/metadata.rb +13 -13
- data/generator_files/cookbooks/infranodes/recipes/default.rb +57 -57
- data/generator_files/cookbooks/infranodes/spec/spec_helper.rb +2 -2
- data/generator_files/cookbooks/infranodes/spec/unit/recipes/default_spec.rb +20 -20
- data/generator_files/cookbooks/infranodes/templates/default/client.rb.erb +5 -5
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/automate.crt +26 -26
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/automate.key +27 -27
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/chef.crt +25 -25
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/chef.key +27 -27
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/compliance.crt +26 -26
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/compliance.key +27 -27
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/private.pem +27 -27
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/files/public.pub +1 -1
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/metadata.rb +3 -3
- data/generator_files/cookbooks/infranodes/test/fixtures/cookbooks/mock_data/recipes/default.rb +27 -27
- data/generator_files/cookbooks/infranodes/test/integration/default/infranodes_spec.rb +22 -22
- data/generator_files/cookbooks/infranodes/test/integration/helpers/serverspec/spec_helper.rb +8 -8
- data/generator_files/cookbooks/wombat/.gitignore +16 -16
- data/generator_files/cookbooks/wombat/.kitchen.yml +43 -43
- data/generator_files/cookbooks/wombat/Berksfile +5 -5
- data/generator_files/cookbooks/wombat/README.md +4 -4
- data/generator_files/cookbooks/wombat/attributes/default.rb +79 -80
- data/generator_files/cookbooks/wombat/attributes/packer.rb +18 -18
- data/generator_files/cookbooks/wombat/chefignore +102 -102
- data/generator_files/cookbooks/wombat/metadata.rb +13 -13
- data/generator_files/cookbooks/wombat/recipes/authorized-keys.rb +20 -20
- data/generator_files/cookbooks/wombat/recipes/default.rb +111 -111
- data/generator_files/cookbooks/wombat/recipes/etc-hosts.rb +51 -51
- data/generator_files/cookbooks/workstation/.gitignore +16 -16
- data/generator_files/cookbooks/workstation/.kitchen.azure.yml +45 -0
- data/generator_files/cookbooks/workstation/.kitchen.ec2.yml +46 -30
- data/generator_files/cookbooks/workstation/.kitchen.yml +42 -22
- data/generator_files/cookbooks/workstation/Berksfile +7 -7
- data/generator_files/cookbooks/workstation/README.md +3 -3
- data/generator_files/cookbooks/workstation/chefignore +106 -102
- data/generator_files/cookbooks/workstation/files/atom.apm.list +10 -7
- data/generator_files/cookbooks/workstation/files/atom.config.cson +6 -3
- data/generator_files/cookbooks/workstation/{templates/default/ise_profile.ps1.erb → files/ise_profile.ps1} +11 -11
- data/generator_files/cookbooks/workstation/libraries/home.rb +4 -4
- data/generator_files/cookbooks/workstation/metadata.rb +14 -14
- data/generator_files/cookbooks/workstation/recipes/browser.rb +53 -58
- data/generator_files/cookbooks/workstation/recipes/certs-keys.rb +41 -45
- data/generator_files/cookbooks/workstation/recipes/chef.rb +29 -28
- data/generator_files/cookbooks/workstation/recipes/default.rb +24 -21
- data/generator_files/cookbooks/workstation/recipes/dotnet.rb +19 -17
- data/generator_files/cookbooks/workstation/recipes/editor.rb +46 -18
- data/generator_files/cookbooks/workstation/recipes/profile.rb +14 -41
- data/generator_files/cookbooks/workstation/recipes/terminal.rb +11 -11
- data/generator_files/cookbooks/workstation/templates/default/bookmarks.html.erb +23 -23
- data/generator_files/cookbooks/workstation/templates/default/data_collector.rb.erb +2 -2
- data/generator_files/cookbooks/workstation/templates/default/knife.rb.erb +10 -10
- data/generator_files/cookbooks/workstation/templates/default/master_preferences.json.erb +28 -28
- data/generator_files/cookbooks/workstation/templates/default/ssh_config.erb +16 -16
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/automate.crt +26 -26
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/automate.key +27 -27
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/chef.crt +26 -26
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/chef.key +27 -27
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/compliance.crt +26 -26
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/compliance.key +27 -27
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/private.pem +27 -27
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/files/public.pub +1 -1
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/metadata.rb +2 -2
- data/generator_files/cookbooks/workstation/test/fixtures/cookbooks/mock_data/recipes/default.rb +21 -21
- data/generator_files/cookbooks/workstation/test/integration/default/workstation_spec.rb +77 -37
- data/generator_files/packer/automate.json +136 -136
- data/generator_files/packer/build-node.json +142 -142
- data/generator_files/packer/chef-server.json +137 -137
- data/generator_files/packer/compliance.json +133 -133
- data/generator_files/packer/infranodes-windows.json +143 -143
- data/generator_files/packer/infranodes.json +134 -134
- data/generator_files/packer/scripts/PreSysprep.ps1 +9 -0
- data/generator_files/packer/workstation.json +160 -142
- data/generator_files/templates/arm.md.json.erb +754 -754
- data/generator_files/templates/arm.vhd.json.erb +630 -630
- data/generator_files/templates/bootstrap-aws.erb +39 -39
- data/generator_files/templates/cfn.json.erb +675 -674
- data/generator_files/wombat.yml +75 -74
- data/lib/wombat/aws.rb +67 -67
- data/lib/wombat/build.rb +392 -392
- data/lib/wombat/cli.rb +254 -254
- data/lib/wombat/common.rb +420 -420
- data/lib/wombat/crypto.rb +65 -65
- data/lib/wombat/delete.rb +67 -67
- data/lib/wombat/deploy.rb +128 -128
- data/lib/wombat/init.rb +32 -32
- data/lib/wombat/latest.rb +27 -27
- data/lib/wombat/output.rb +101 -101
- data/lib/wombat/update.rb +20 -20
- data/lib/wombat/version.rb +3 -3
- data/lib/wombat.rb +8 -8
- data/spec/functional/common_spec.rb +26 -26
- data/spec/spec_helper.rb +103 -103
- data/spec/unit/common_spec.rb +116 -116
- data/terraform/README.md +13 -13
- data/terraform/templates/terraform.tfvars.erb +12 -12
- data/terraform/wombat.tf +328 -328
- data/wombat-cli.gemspec +36 -36
- metadata +6 -4
@@ -1,52 +1,52 @@
|
|
1
|
-
#
|
2
|
-
# Cookbook Name:: automate
|
3
|
-
# Recipe:: _helper
|
4
|
-
#
|
5
|
-
# Author:: Salim Afiune (<afiune@chef.io>)
|
6
|
-
#
|
7
|
-
# Copyright 2015, Chef Software, Inc.
|
8
|
-
#
|
9
|
-
# All rights reserved - Do Not Redistribute
|
10
|
-
#
|
11
|
-
|
12
|
-
module Delivery
|
13
|
-
|
14
|
-
module Helper
|
15
|
-
# Delivery API helper
|
16
|
-
#
|
17
|
-
# This little helper will let us just type:
|
18
|
-
# e.g.
|
19
|
-
# delivery_api.get(...)
|
20
|
-
# delivery_api.put(...)
|
21
|
-
# delivery_api.post(...)
|
22
|
-
# delivery_api.delete(...)
|
23
|
-
#
|
24
|
-
def delivery_api
|
25
|
-
@api ||= begin
|
26
|
-
Delivery::API.new(delivery_fqdn, 'admin', delivery_admin_password, delivery_enterprise)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# Get delivery enterprise
|
31
|
-
|
32
|
-
def delivery_fqdn
|
33
|
-
"#{node['demo']['domain_prefix']}automate.#{node['demo']['domain']}"
|
34
|
-
end
|
35
|
-
|
36
|
-
def delivery_organization
|
37
|
-
node['demo']['org']
|
38
|
-
end
|
39
|
-
|
40
|
-
def delivery_enterprise
|
41
|
-
node['demo']['enterprise']
|
42
|
-
end
|
43
|
-
|
44
|
-
def delivery_admin_password
|
45
|
-
node['demo']['users']['admin']['password']
|
46
|
-
end
|
47
|
-
|
48
|
-
def return_key(key)
|
49
|
-
key =~ /\// ? File.read(key) : key
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
1
|
+
#
|
2
|
+
# Cookbook Name:: automate
|
3
|
+
# Recipe:: _helper
|
4
|
+
#
|
5
|
+
# Author:: Salim Afiune (<afiune@chef.io>)
|
6
|
+
#
|
7
|
+
# Copyright 2015, Chef Software, Inc.
|
8
|
+
#
|
9
|
+
# All rights reserved - Do Not Redistribute
|
10
|
+
#
|
11
|
+
|
12
|
+
module Delivery
|
13
|
+
|
14
|
+
module Helper
|
15
|
+
# Delivery API helper
|
16
|
+
#
|
17
|
+
# This little helper will let us just type:
|
18
|
+
# e.g.
|
19
|
+
# delivery_api.get(...)
|
20
|
+
# delivery_api.put(...)
|
21
|
+
# delivery_api.post(...)
|
22
|
+
# delivery_api.delete(...)
|
23
|
+
#
|
24
|
+
def delivery_api
|
25
|
+
@api ||= begin
|
26
|
+
Delivery::API.new(delivery_fqdn, 'admin', delivery_admin_password, delivery_enterprise)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Get delivery enterprise
|
31
|
+
|
32
|
+
def delivery_fqdn
|
33
|
+
"#{node['demo']['domain_prefix']}automate.#{node['demo']['domain']}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def delivery_organization
|
37
|
+
node['demo']['org']
|
38
|
+
end
|
39
|
+
|
40
|
+
def delivery_enterprise
|
41
|
+
node['demo']['enterprise']
|
42
|
+
end
|
43
|
+
|
44
|
+
def delivery_admin_password
|
45
|
+
node['demo']['users']['admin']['password']
|
46
|
+
end
|
47
|
+
|
48
|
+
def return_key(key)
|
49
|
+
key =~ /\// ? File.read(key) : key
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,204 +1,204 @@
|
|
1
|
-
#
|
2
|
-
# Cookbook Name:: automate
|
3
|
-
# Libraries:: delivery_api
|
4
|
-
#
|
5
|
-
# Author:: Salim Afiune (<afiune@chef.io>)
|
6
|
-
#
|
7
|
-
# Copyright 2015, Chef Software, Inc.
|
8
|
-
#
|
9
|
-
# All rights reserved - Do Not Redistribute
|
10
|
-
#
|
11
|
-
require 'net/http'
|
12
|
-
require 'json'
|
13
|
-
require 'logger'
|
14
|
-
|
15
|
-
module Delivery
|
16
|
-
|
17
|
-
# Delivery API
|
18
|
-
#
|
19
|
-
# @author Salim Afiune <afiune@chef.io>
|
20
|
-
#
|
21
|
-
class API
|
22
|
-
|
23
|
-
attr_accessor :logger
|
24
|
-
attr_accessor :hostname
|
25
|
-
attr_accessor :token
|
26
|
-
attr_accessor :username
|
27
|
-
attr_accessor :password
|
28
|
-
attr_accessor :enterprise
|
29
|
-
attr_accessor :organization
|
30
|
-
|
31
|
-
# @example Instance a Delivery API
|
32
|
-
# => Delivery::API.new('delivery-server', 'my_user', 'my_password', 'my_enterprise')
|
33
|
-
#
|
34
|
-
# @example [block usage for multiple requests] Create multiple projects
|
35
|
-
# => Delivery::API.new('delivery-server', 'my_user', 'my_password', 'marvel') do |api|
|
36
|
-
# %W{
|
37
|
-
# thor
|
38
|
-
# hulk
|
39
|
-
# ironman
|
40
|
-
# hawkeye
|
41
|
-
# BlackWidow
|
42
|
-
# CaptainAmerica
|
43
|
-
# }.each do |project|
|
44
|
-
# api.post('/e/marvel/orgs/avengers/projects',
|
45
|
-
# {
|
46
|
-
# "name": project
|
47
|
-
# }
|
48
|
-
# )
|
49
|
-
# end
|
50
|
-
# end
|
51
|
-
#
|
52
|
-
# @yield [self] if a block is given then the constructed object yields
|
53
|
-
def initialize (hostname, username, password, enterprise = nil, organization = nil)
|
54
|
-
@hostname = hostname
|
55
|
-
@username = username
|
56
|
-
@password = password
|
57
|
-
@enterprise = enterprise
|
58
|
-
@organization = organization
|
59
|
-
token
|
60
|
-
if block_given?
|
61
|
-
yield self
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def delivery_url
|
66
|
-
"https://#{@hostname}/api/v0"
|
67
|
-
end
|
68
|
-
|
69
|
-
def headers
|
70
|
-
{
|
71
|
-
"chef-delivery-token" => token,
|
72
|
-
"chef-delivery-user" => @username
|
73
|
-
}
|
74
|
-
end
|
75
|
-
|
76
|
-
def logger
|
77
|
-
@logger ||= Logger.new(STDOUT)
|
78
|
-
end
|
79
|
-
|
80
|
-
def get_delivery_endpoint(endpoint)
|
81
|
-
if endpoint.start_with?('/e')
|
82
|
-
URI("#{delivery_url}#{endpoint}")
|
83
|
-
else
|
84
|
-
URI("#{delivery_url}/e/#{enterprise}#{endpoint}")
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def enterprise=(enterprise)
|
89
|
-
@enterprise = enterprise
|
90
|
-
@token = nil
|
91
|
-
end
|
92
|
-
|
93
|
-
def http(uri)
|
94
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
95
|
-
http.use_ssl = true
|
96
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
97
|
-
http
|
98
|
-
end
|
99
|
-
|
100
|
-
def token
|
101
|
-
@token ||= begin
|
102
|
-
resp = post("/e/#{@enterprise}/get-token", {'username'=> @username, 'password'=> @password})
|
103
|
-
resp['token']
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# POST Method
|
108
|
-
# Perform a POST to a Delivery Endpoint
|
109
|
-
#
|
110
|
-
# @example Create an organization. [Using Data::String]
|
111
|
-
# => post(
|
112
|
-
# '/e/marvel/orgs',
|
113
|
-
# '{ "name": "Stark Industries" }'
|
114
|
-
# )
|
115
|
-
#
|
116
|
-
# @example Create a pipeline. [Using Data::Hash]
|
117
|
-
# => post(
|
118
|
-
# '/e/marvel/orgs/Stark Industries/projects/hulkbuster/pipelines',
|
119
|
-
# {
|
120
|
-
# "name" => "v2",
|
121
|
-
# "base" => "master"
|
122
|
-
# }
|
123
|
-
# )
|
124
|
-
#
|
125
|
-
# @param endpoint [String] The Delivery Endpoint
|
126
|
-
# @param data [String][Hash] The Body of the request
|
127
|
-
# @return [Hash]
|
128
|
-
def post(endpoint, data)
|
129
|
-
uri = get_delivery_endpoint(endpoint)
|
130
|
-
request = Net::HTTP::Post.new(uri.request_uri)
|
131
|
-
request.content_type = "application/json"
|
132
|
-
request.body = data.class.eql?(Hash) ? JSON.unparse(data) : data
|
133
|
-
headers.keys.each do |key|
|
134
|
-
request[key] = headers[key]
|
135
|
-
end unless endpoint =~ /get-token/
|
136
|
-
response = http(uri).request(request)
|
137
|
-
response_error(response)
|
138
|
-
JSON.parse(response.body) if response.body
|
139
|
-
end
|
140
|
-
|
141
|
-
# GET Method
|
142
|
-
# Perform a GET to a Delivery Endpoint
|
143
|
-
#
|
144
|
-
# @example List all users.
|
145
|
-
# => get('/e/marvel/users')
|
146
|
-
#
|
147
|
-
# @example List Organizations.
|
148
|
-
# => get('/e/marvel/orgs')
|
149
|
-
#
|
150
|
-
# @param endpoint [String] The Delivery Endpoint
|
151
|
-
# @return [Hash]
|
152
|
-
def get(endpoint)
|
153
|
-
uri = get_delivery_endpoint(endpoint)
|
154
|
-
response = http(uri).get(uri.path, headers)
|
155
|
-
response_error(response)
|
156
|
-
JSON.parse(response.body) if response.body
|
157
|
-
end
|
158
|
-
|
159
|
-
# PUT Method
|
160
|
-
# Perform a PUT to a Delivery Endpoint
|
161
|
-
#
|
162
|
-
# @param endpoint [String] The Delivery Endpoint
|
163
|
-
# @param data [String][Hash] The Body of the request
|
164
|
-
# @return [Hash]
|
165
|
-
def put(endpoint, data)
|
166
|
-
uri = get_delivery_endpoint(endpoint)
|
167
|
-
request = Net::HTTP::Put.new(uri.request_uri)
|
168
|
-
request.content_type = "application/json"
|
169
|
-
request.body = data.class.eql?(Hash) ? JSON.unparse(data) : data
|
170
|
-
headers.keys.each do |key|
|
171
|
-
request[key] = headers[key]
|
172
|
-
end
|
173
|
-
response = http(uri).request(request)
|
174
|
-
response_error(response)
|
175
|
-
JSON.parse(response.body) if response.body
|
176
|
-
end
|
177
|
-
|
178
|
-
# DELETE Method
|
179
|
-
# Perform a DELETE to a Delivery Endpoint
|
180
|
-
#
|
181
|
-
# @param endpoint [String] The Delivery Endpoint
|
182
|
-
# @return [Hash]
|
183
|
-
def delete(endpoint)
|
184
|
-
uri = get_delivery_endpoint(endpoint)
|
185
|
-
response = http(uri).delete(uri.path, headers)
|
186
|
-
response_error(response)
|
187
|
-
JSON.parse(response.body) if response.body
|
188
|
-
end
|
189
|
-
|
190
|
-
def response_error(response)
|
191
|
-
if '200' <= response.code && response.code <= '301'
|
192
|
-
logger.debug(response.body) if Chef::Log.level == :debug
|
193
|
-
else
|
194
|
-
case response.code
|
195
|
-
when '409', '404'
|
196
|
-
logger.debug(response.body) if Chef::Log.level == :debug
|
197
|
-
else
|
198
|
-
logger.error(response.body)
|
199
|
-
response.error!
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
end
|
1
|
+
#
|
2
|
+
# Cookbook Name:: automate
|
3
|
+
# Libraries:: delivery_api
|
4
|
+
#
|
5
|
+
# Author:: Salim Afiune (<afiune@chef.io>)
|
6
|
+
#
|
7
|
+
# Copyright 2015, Chef Software, Inc.
|
8
|
+
#
|
9
|
+
# All rights reserved - Do Not Redistribute
|
10
|
+
#
|
11
|
+
require 'net/http'
|
12
|
+
require 'json'
|
13
|
+
require 'logger'
|
14
|
+
|
15
|
+
module Delivery
|
16
|
+
|
17
|
+
# Delivery API
|
18
|
+
#
|
19
|
+
# @author Salim Afiune <afiune@chef.io>
|
20
|
+
#
|
21
|
+
class API
|
22
|
+
|
23
|
+
attr_accessor :logger
|
24
|
+
attr_accessor :hostname
|
25
|
+
attr_accessor :token
|
26
|
+
attr_accessor :username
|
27
|
+
attr_accessor :password
|
28
|
+
attr_accessor :enterprise
|
29
|
+
attr_accessor :organization
|
30
|
+
|
31
|
+
# @example Instance a Delivery API
|
32
|
+
# => Delivery::API.new('delivery-server', 'my_user', 'my_password', 'my_enterprise')
|
33
|
+
#
|
34
|
+
# @example [block usage for multiple requests] Create multiple projects
|
35
|
+
# => Delivery::API.new('delivery-server', 'my_user', 'my_password', 'marvel') do |api|
|
36
|
+
# %W{
|
37
|
+
# thor
|
38
|
+
# hulk
|
39
|
+
# ironman
|
40
|
+
# hawkeye
|
41
|
+
# BlackWidow
|
42
|
+
# CaptainAmerica
|
43
|
+
# }.each do |project|
|
44
|
+
# api.post('/e/marvel/orgs/avengers/projects',
|
45
|
+
# {
|
46
|
+
# "name": project
|
47
|
+
# }
|
48
|
+
# )
|
49
|
+
# end
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# @yield [self] if a block is given then the constructed object yields
|
53
|
+
def initialize (hostname, username, password, enterprise = nil, organization = nil)
|
54
|
+
@hostname = hostname
|
55
|
+
@username = username
|
56
|
+
@password = password
|
57
|
+
@enterprise = enterprise
|
58
|
+
@organization = organization
|
59
|
+
token
|
60
|
+
if block_given?
|
61
|
+
yield self
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def delivery_url
|
66
|
+
"https://#{@hostname}/api/v0"
|
67
|
+
end
|
68
|
+
|
69
|
+
def headers
|
70
|
+
{
|
71
|
+
"chef-delivery-token" => token,
|
72
|
+
"chef-delivery-user" => @username
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def logger
|
77
|
+
@logger ||= Logger.new(STDOUT)
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_delivery_endpoint(endpoint)
|
81
|
+
if endpoint.start_with?('/e')
|
82
|
+
URI("#{delivery_url}#{endpoint}")
|
83
|
+
else
|
84
|
+
URI("#{delivery_url}/e/#{enterprise}#{endpoint}")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def enterprise=(enterprise)
|
89
|
+
@enterprise = enterprise
|
90
|
+
@token = nil
|
91
|
+
end
|
92
|
+
|
93
|
+
def http(uri)
|
94
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
95
|
+
http.use_ssl = true
|
96
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
97
|
+
http
|
98
|
+
end
|
99
|
+
|
100
|
+
def token
|
101
|
+
@token ||= begin
|
102
|
+
resp = post("/e/#{@enterprise}/get-token", {'username'=> @username, 'password'=> @password})
|
103
|
+
resp['token']
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# POST Method
|
108
|
+
# Perform a POST to a Delivery Endpoint
|
109
|
+
#
|
110
|
+
# @example Create an organization. [Using Data::String]
|
111
|
+
# => post(
|
112
|
+
# '/e/marvel/orgs',
|
113
|
+
# '{ "name": "Stark Industries" }'
|
114
|
+
# )
|
115
|
+
#
|
116
|
+
# @example Create a pipeline. [Using Data::Hash]
|
117
|
+
# => post(
|
118
|
+
# '/e/marvel/orgs/Stark Industries/projects/hulkbuster/pipelines',
|
119
|
+
# {
|
120
|
+
# "name" => "v2",
|
121
|
+
# "base" => "master"
|
122
|
+
# }
|
123
|
+
# )
|
124
|
+
#
|
125
|
+
# @param endpoint [String] The Delivery Endpoint
|
126
|
+
# @param data [String][Hash] The Body of the request
|
127
|
+
# @return [Hash]
|
128
|
+
def post(endpoint, data)
|
129
|
+
uri = get_delivery_endpoint(endpoint)
|
130
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
131
|
+
request.content_type = "application/json"
|
132
|
+
request.body = data.class.eql?(Hash) ? JSON.unparse(data) : data
|
133
|
+
headers.keys.each do |key|
|
134
|
+
request[key] = headers[key]
|
135
|
+
end unless endpoint =~ /get-token/
|
136
|
+
response = http(uri).request(request)
|
137
|
+
response_error(response)
|
138
|
+
JSON.parse(response.body) if response.body
|
139
|
+
end
|
140
|
+
|
141
|
+
# GET Method
|
142
|
+
# Perform a GET to a Delivery Endpoint
|
143
|
+
#
|
144
|
+
# @example List all users.
|
145
|
+
# => get('/e/marvel/users')
|
146
|
+
#
|
147
|
+
# @example List Organizations.
|
148
|
+
# => get('/e/marvel/orgs')
|
149
|
+
#
|
150
|
+
# @param endpoint [String] The Delivery Endpoint
|
151
|
+
# @return [Hash]
|
152
|
+
def get(endpoint)
|
153
|
+
uri = get_delivery_endpoint(endpoint)
|
154
|
+
response = http(uri).get(uri.path, headers)
|
155
|
+
response_error(response)
|
156
|
+
JSON.parse(response.body) if response.body
|
157
|
+
end
|
158
|
+
|
159
|
+
# PUT Method
|
160
|
+
# Perform a PUT to a Delivery Endpoint
|
161
|
+
#
|
162
|
+
# @param endpoint [String] The Delivery Endpoint
|
163
|
+
# @param data [String][Hash] The Body of the request
|
164
|
+
# @return [Hash]
|
165
|
+
def put(endpoint, data)
|
166
|
+
uri = get_delivery_endpoint(endpoint)
|
167
|
+
request = Net::HTTP::Put.new(uri.request_uri)
|
168
|
+
request.content_type = "application/json"
|
169
|
+
request.body = data.class.eql?(Hash) ? JSON.unparse(data) : data
|
170
|
+
headers.keys.each do |key|
|
171
|
+
request[key] = headers[key]
|
172
|
+
end
|
173
|
+
response = http(uri).request(request)
|
174
|
+
response_error(response)
|
175
|
+
JSON.parse(response.body) if response.body
|
176
|
+
end
|
177
|
+
|
178
|
+
# DELETE Method
|
179
|
+
# Perform a DELETE to a Delivery Endpoint
|
180
|
+
#
|
181
|
+
# @param endpoint [String] The Delivery Endpoint
|
182
|
+
# @return [Hash]
|
183
|
+
def delete(endpoint)
|
184
|
+
uri = get_delivery_endpoint(endpoint)
|
185
|
+
response = http(uri).delete(uri.path, headers)
|
186
|
+
response_error(response)
|
187
|
+
JSON.parse(response.body) if response.body
|
188
|
+
end
|
189
|
+
|
190
|
+
def response_error(response)
|
191
|
+
if '200' <= response.code && response.code <= '301'
|
192
|
+
logger.debug(response.body) if Chef::Log.level == :debug
|
193
|
+
else
|
194
|
+
case response.code
|
195
|
+
when '409', '404'
|
196
|
+
logger.debug(response.body) if Chef::Log.level == :debug
|
197
|
+
else
|
198
|
+
logger.error(response.body)
|
199
|
+
response.error!
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
@@ -1,31 +1,31 @@
|
|
1
|
-
#
|
2
|
-
# Cookbook Name:: automate
|
3
|
-
# Libraries:: delivery_project
|
4
|
-
#
|
5
|
-
# Author:: Salim Afiune (<afiune@chef.io>)
|
6
|
-
#
|
7
|
-
# Copyright 2015, Chef Software, Inc.
|
8
|
-
#
|
9
|
-
# All rights reserved - Do Not Redistribute
|
10
|
-
#
|
11
|
-
|
12
|
-
module Delivery
|
13
|
-
|
14
|
-
# Delivery Project
|
15
|
-
#
|
16
|
-
# @author Salim Afiune <afiune@chef.io>
|
17
|
-
#
|
18
|
-
class DeliveryProject
|
19
|
-
|
20
|
-
attr_accessor :project
|
21
|
-
attr_accessor :organization
|
22
|
-
attr_accessor :enterprise
|
23
|
-
|
24
|
-
def initialize (project, organization, enterprise)
|
25
|
-
@project = project
|
26
|
-
@organization = organization
|
27
|
-
@enterprise = enterprise
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
1
|
+
#
|
2
|
+
# Cookbook Name:: automate
|
3
|
+
# Libraries:: delivery_project
|
4
|
+
#
|
5
|
+
# Author:: Salim Afiune (<afiune@chef.io>)
|
6
|
+
#
|
7
|
+
# Copyright 2015, Chef Software, Inc.
|
8
|
+
#
|
9
|
+
# All rights reserved - Do Not Redistribute
|
10
|
+
#
|
11
|
+
|
12
|
+
module Delivery
|
13
|
+
|
14
|
+
# Delivery Project
|
15
|
+
#
|
16
|
+
# @author Salim Afiune <afiune@chef.io>
|
17
|
+
#
|
18
|
+
class DeliveryProject
|
19
|
+
|
20
|
+
attr_accessor :project
|
21
|
+
attr_accessor :organization
|
22
|
+
attr_accessor :enterprise
|
23
|
+
|
24
|
+
def initialize (project, organization, enterprise)
|
25
|
+
@project = project
|
26
|
+
@organization = organization
|
27
|
+
@enterprise = enterprise
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# Mixin DeliveryDemo::Helper to Recipes & Resources
|
4
|
-
::Chef::Recipe.send(:include, Delivery::Helper)
|
1
|
+
|
2
|
+
|
3
|
+
# Mixin DeliveryDemo::Helper to Recipes & Resources
|
4
|
+
::Chef::Recipe.send(:include, Delivery::Helper)
|
5
5
|
::Chef::Resource.send(:include, Delivery::Helper)
|
@@ -1,11 +1,11 @@
|
|
1
|
-
name 'automate'
|
2
|
-
maintainer 'The Authors'
|
3
|
-
maintainer_email 'you@example.com'
|
4
|
-
license 'all_rights'
|
5
|
-
description 'Installs/Configures automate'
|
6
|
-
long_description 'Installs/Configures automate'
|
7
|
-
version '0.2.2'
|
8
|
-
|
9
|
-
depends 'chef-ingredient'
|
10
|
-
depends 'line'
|
11
|
-
depends 'wombat'
|
1
|
+
name 'automate'
|
2
|
+
maintainer 'The Authors'
|
3
|
+
maintainer_email 'you@example.com'
|
4
|
+
license 'all_rights'
|
5
|
+
description 'Installs/Configures automate'
|
6
|
+
long_description 'Installs/Configures automate'
|
7
|
+
version '0.2.2'
|
8
|
+
|
9
|
+
depends 'chef-ingredient'
|
10
|
+
depends 'line'
|
11
|
+
depends 'wombat'
|