mock_code_manager 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9764397b0cf98fff13c86adecef1e408868185ef6ffa05271b80133880b908dd
4
- data.tar.gz: 0fffff851eab0c0012a178edb7d7a6ceaef63f1bf92077312578c6676dfa8bd2
3
+ metadata.gz: 56a9b4647bc88938884b51ab546e564d2ade43fa728ea88c9c853f0ee8081cd2
4
+ data.tar.gz: cecb1cb12d8e4c1d4fe15b423f76b56d2ede6c168e39907c3c4d9c87bca07bb3
5
5
  SHA512:
6
- metadata.gz: c51fc10a021c1aec6b9b97af39bf55c0085d7516058e7229d82091c3c3d846c605c26d4f6064b8adcc69cd3df28236f8cbebc2e1cc40d2967a6bdefa083e20df
7
- data.tar.gz: b856cc59fba06be3809425a66654e456e8b26835849665a9fadcb43fba88051310973042eaa2b96ff0410557e9938dd74cee8d7af327372cba9cc4d4d1b25f96
6
+ metadata.gz: 91c11fdd64823212f2cdae81c53961e983da79d214879a1b613a0d4d7a8884098f88a99857bb6dafdb469f90f71875a9587592d607c41df9204ff00522f13917
7
+ data.tar.gz: 7f03d3331d1c60bfd051f0168f74dab537a668ae3b27df0695171687f5aef62f06da19dd44a319ed0701a5838c9ee5bd3037db70bbce91d1204946720741147d
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .idea
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /Gemfile.lock
@@ -21,39 +21,120 @@ require 'webrick/log'
21
21
  require "webrick/https"
22
22
  require 'rack'
23
23
  require "json"
24
-
24
+ require "rugged"
25
25
 
26
26
  module MockCodeManager
27
27
  RES_DIR = File.join(File.dirname(File.expand_path(__FILE__)), "..", "res")
28
28
  SSL_DIR = "/tmp/mock_code_manager_ssl"
29
29
 
30
30
  TOKEN_OK = "PUPPET_DEPLOY_OK"
31
- TOKEN_ALWAYS_FAIL = "PUPPET_DEPLOY_FAIL"
32
- JSON_OK=[{"environment"=>"production", "id"=>66, "status"=>"queued"}]
31
+
33
32
  JSON_BAD_TOKEN={"kind"=>"puppetlabs.rbac/token-revoked", "msg"=>"Authentication token has been revoked."}
34
33
  JSON_MISSING_TOKEN={"kind"=>"puppetlabs.rbac/user-unauthenticated", "msg"=>"Route requires authentication"}
35
34
  JSON_NO_ENVIRONMENTS_SPECIFIED=[]
35
+ TEST_REPO="https://github.com/geoffwilliams/puppet-control-test"
36
+ JUNK_ID="deadbeefdeadbeef"
37
+ IDOK=66
38
+ STATUS_QUEUED = "queued"
39
+ STATUS_COMPLETE = "complete"
40
+ STATUS_FAILED = "failed"
36
41
 
37
42
  class MockCodeManager < Sinatra::Base
43
+ def get_all_branches
44
+ branches = {}
45
+ output = %x(git ls-remote #{TEST_REPO})
46
+ output.split("\n").each do |line|
47
+ line_split = line.split(/\t/)
48
+ if line_split.length == 2
49
+ environment = line_split[1].split(/\//)[-1]
50
+ revision = line_split[0]
51
+ branches[environment] = revision
52
+ else
53
+ puts "skipped invalid input: #{line}"
54
+ end
55
+ end
56
+
57
+ return branches
58
+ end
59
+
60
+ def get_deploy_all_json(wait)
61
+ get_deploy_json(get_all_branches.keys.sort, wait)
62
+ end
63
+
64
+ def get_deploy_json(requested_branches, wait)
65
+ json = []
66
+ branches = get_all_branches
67
+ id = IDOK
68
+ requested_branches.each { |requested_branch|
69
+ if branches.has_key? requested_branch
70
+ if wait
71
+ # in wait mode, sleep for a while to simulate a slow-ish server
72
+ sleep(1 + rand(10))
73
+ json << {
74
+ "environment"=>requested_branch,
75
+ "id"=>id,
76
+ "status"=>STATUS_COMPLETE,
77
+ "file-sync"=> {
78
+ "environment-commit"=>JUNK_ID,
79
+ "code-commit"=>JUNK_ID
80
+ },
81
+ "deploy-signature"=>branches[requested_branch]
82
+ }
83
+ else
84
+ json << {
85
+ "environment"=>requested_branch,
86
+ "id"=>id,
87
+ "status"=>STATUS_QUEUED
88
+ }
89
+ end
90
+ else
91
+ json << {
92
+ "environment"=>requested_branch,
93
+ "id"=>id,
94
+ "status"=>STATUS_FAILED,
95
+ "error"=>{
96
+ "kind"=>"puppetlabs.code-manager/deploy-failure",
97
+ "details"=>{
98
+ "corrected-env-name"=>requested_branch},
99
+ "msg"=>"Errors while deploying environment '#{requested_branch}' (exit code: 1):\nERROR\t -> Environment(s) '#{requested_branch}' cannot be found in any source and will not be deployed.\n"
100
+ }
101
+ }
102
+ end
103
+ id += 1
104
+ }
105
+
106
+ json
107
+ end
108
+
109
+ get '/' do
110
+ <<~"END"
111
+ <h1>Mock Code Manager</h1>
112
+ <p>
113
+ Mock control repository in use: <a href="#{TEST_REPO}">#{TEST_REPO}</a>
114
+ </p>
115
+ <pre>
116
+ token: #{TOKEN_OK}
117
+ environments: #{JSON.pretty_generate(get_all_branches)}
118
+ </pre>
119
+ END
120
+ end
121
+
38
122
  post '/code-manager/v1/deploys' do
39
123
  json = JSON.parse(request.body.read)
40
124
  token = request.env['HTTP_X_AUTHENTICATION']
125
+ wait = json.has_key?("wait") && json["wait"]
126
+ environments = json["environments"]
41
127
  if token
42
128
  if token == TOKEN_OK
43
129
 
44
130
  # environments must be a non-empty array for code manager to do anything.
45
131
  # If missing it returns an empty array []
46
132
  if json["deploy-all"] == true
47
- resp = JSON_OK
48
- elsif json["environments"].empty?
133
+ resp = self.get_deploy_all_json(wait)
134
+ elsif environments.empty?
49
135
  resp = JSON_NO_ENVIRONMENTS_SPECIFIED
50
136
  else
51
- resp = []
52
- i=66
53
- json["environments"].each { |environment|
54
- resp.push({"environment"=>environment, "id"=>i, "status"=>"queued"})
55
- i += 1
56
- }
137
+ resp = self.get_deploy_json(environments, wait)
57
138
  end
58
139
  else
59
140
  resp = JSON_BAD_TOKEN
@@ -1,3 +1,3 @@
1
1
  module MockCodeManager
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -11,6 +11,8 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{A mock version of Puppet Code Manager}
13
13
  spec.homepage = "https://github.com/GeoffWilliams/puppet-mock_code_manager"
14
+ spec.license = "Apache-2.0"
15
+
14
16
 
15
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
18
  f.match(%r{^(test|spec|features)/})
@@ -22,9 +24,11 @@ Gem::Specification.new do |spec|
22
24
  spec.add_development_dependency "bundler", "~> 2.0"
23
25
  spec.add_development_dependency "rake", "~> 12.3"
24
26
  spec.add_development_dependency "rspec", "~> 3.8"
27
+ spec.add_development_dependency "excon", "0.64.0"
25
28
 
26
29
  spec.add_dependency "sinatra", "2.0.5"
27
30
  spec.add_dependency "webrick", "1.4.2"
28
31
  spec.add_dependency "rack", "2.0.7"
32
+ spec.add_dependency "rugged", "~> 0.28.2"
29
33
 
30
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock_code_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoff Williams
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-08 00:00:00.000000000 Z
11
+ date: 2019-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: excon
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.64.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.64.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: sinatra
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,20 @@ dependencies:
94
108
  - - '='
95
109
  - !ruby/object:Gem::Version
96
110
  version: 2.0.7
111
+ - !ruby/object:Gem::Dependency
112
+ name: rugged
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.28.2
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.28.2
97
125
  description:
98
126
  email:
99
127
  - geoff@geoffwilliams.me.uk
@@ -103,9 +131,6 @@ extensions: []
103
131
  extra_rdoc_files: []
104
132
  files:
105
133
  - ".gitignore"
106
- - ".idea/misc.xml"
107
- - ".idea/modules.xml"
108
- - ".idea/vcs.xml"
109
134
  - ".rspec"
110
135
  - ".travis.yml"
111
136
  - Gemfile
@@ -120,7 +145,8 @@ files:
120
145
  - mock_code_manager.gemspec
121
146
  - res/setup_ssl.sh
122
147
  homepage: https://github.com/GeoffWilliams/puppet-mock_code_manager
123
- licenses: []
148
+ licenses:
149
+ - Apache-2.0
124
150
  metadata: {}
125
151
  post_install_message:
126
152
  rdoc_options: []