nucleus 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/CHANGELOG.md +9 -0
  4. data/README.md +43 -72
  5. data/lib/nucleus/adapter_resolver.rb +3 -3
  6. data/lib/nucleus/adapters/base_adapter.rb +109 -109
  7. data/lib/nucleus/adapters/v1/cloud_foundry_v2/application.rb +111 -111
  8. data/lib/nucleus/adapters/v1/cloud_foundry_v2/cloud_foundry_v2.rb +141 -141
  9. data/lib/nucleus/adapters/v1/cloud_foundry_v2/data.rb +97 -97
  10. data/lib/nucleus/adapters/v1/cloud_foundry_v2/domains.rb +5 -5
  11. data/lib/nucleus/adapters/v1/cloud_foundry_v2/lifecycle.rb +41 -41
  12. data/lib/nucleus/adapters/v1/cloud_foundry_v2/logs.rb +6 -6
  13. data/lib/nucleus/adapters/v1/cloud_foundry_v2/regions.rb +33 -33
  14. data/lib/nucleus/adapters/v1/cloud_foundry_v2/services.rb +6 -6
  15. data/lib/nucleus/adapters/v1/cloud_foundry_v2/vars.rb +80 -80
  16. data/lib/nucleus/adapters/v1/heroku/app_states.rb +57 -57
  17. data/lib/nucleus/adapters/v1/heroku/data.rb +78 -78
  18. data/lib/nucleus/adapters/v1/heroku/heroku.rb +146 -146
  19. data/lib/nucleus/adapters/v1/heroku/lifecycle.rb +51 -51
  20. data/lib/nucleus/adapters/v1/heroku/logs.rb +2 -2
  21. data/lib/nucleus/adapters/v1/heroku/regions.rb +42 -42
  22. data/lib/nucleus/adapters/v1/heroku/services.rb +168 -168
  23. data/lib/nucleus/adapters/v1/heroku/vars.rb +65 -65
  24. data/lib/nucleus/adapters/v1/openshift_v2/app_states.rb +68 -68
  25. data/lib/nucleus/adapters/v1/openshift_v2/application.rb +1 -1
  26. data/lib/nucleus/adapters/v1/openshift_v2/data.rb +96 -96
  27. data/lib/nucleus/adapters/v1/openshift_v2/lifecycle.rb +60 -60
  28. data/lib/nucleus/adapters/v1/openshift_v2/logs.rb +106 -106
  29. data/lib/nucleus/adapters/v1/openshift_v2/openshift_v2.rb +125 -125
  30. data/lib/nucleus/adapters/v1/openshift_v2/regions.rb +58 -58
  31. data/lib/nucleus/adapters/v1/openshift_v2/services.rb +173 -173
  32. data/lib/nucleus/adapters/v1/openshift_v2/vars.rb +49 -49
  33. data/lib/nucleus/adapters/v1/stub_adapter.rb +464 -464
  34. data/lib/nucleus/core/adapter_extensions/auth/auth_client.rb +44 -44
  35. data/lib/nucleus/core/adapter_extensions/auth/expiring_token_auth_client.rb +53 -53
  36. data/lib/nucleus/core/adapter_extensions/auth/http_basic_auth_client.rb +3 -3
  37. data/lib/nucleus/core/adapter_extensions/auth/o_auth2_auth_client.rb +95 -95
  38. data/lib/nucleus/core/adapter_extensions/auth/token_auth_client.rb +36 -36
  39. data/lib/nucleus/core/adapter_extensions/http_client.rb +5 -5
  40. data/lib/nucleus/core/common/files/archive_extractor.rb +1 -1
  41. data/lib/nucleus/core/common/files/archiver.rb +2 -2
  42. data/lib/nucleus/core/file_handling/file_manager.rb +64 -64
  43. data/lib/nucleus/core/file_handling/git_deployer.rb +133 -133
  44. data/lib/nucleus/core/import/adapter_configuration.rb +53 -53
  45. data/lib/nucleus/scripts/initialize_config_defaults.rb +26 -26
  46. data/lib/nucleus/version.rb +1 -1
  47. data/nucleus.gemspec +2 -2
  48. data/spec/integration/api/auth_spec.rb +3 -3
  49. data/spec/spec_helper.rb +98 -98
  50. data/spec/test_suites.rake +1 -1
  51. data/spec/unit/adapters/git_deployer_spec.rb +262 -262
  52. data/spec/unit/common/helpers/auth_helper_spec.rb +1 -1
  53. data/tasks/evaluation.rake +1 -1
  54. data/wiki/adapter_tests.md +0 -7
  55. data/wiki/implement_new_adapter.md +1 -1
  56. metadata +4 -20
  57. data/config/adapters/cloud_control.yml +0 -32
  58. data/lib/nucleus/adapters/v1/cloud_control/application.rb +0 -108
  59. data/lib/nucleus/adapters/v1/cloud_control/authentication.rb +0 -27
  60. data/lib/nucleus/adapters/v1/cloud_control/buildpacks.rb +0 -23
  61. data/lib/nucleus/adapters/v1/cloud_control/cloud_control.rb +0 -153
  62. data/lib/nucleus/adapters/v1/cloud_control/data.rb +0 -76
  63. data/lib/nucleus/adapters/v1/cloud_control/domains.rb +0 -68
  64. data/lib/nucleus/adapters/v1/cloud_control/lifecycle.rb +0 -27
  65. data/lib/nucleus/adapters/v1/cloud_control/log_poller.rb +0 -71
  66. data/lib/nucleus/adapters/v1/cloud_control/logs.rb +0 -103
  67. data/lib/nucleus/adapters/v1/cloud_control/regions.rb +0 -32
  68. data/lib/nucleus/adapters/v1/cloud_control/scaling.rb +0 -17
  69. data/lib/nucleus/adapters/v1/cloud_control/semantic_errors.rb +0 -31
  70. data/lib/nucleus/adapters/v1/cloud_control/services.rb +0 -162
  71. data/lib/nucleus/adapters/v1/cloud_control/token.rb +0 -17
  72. data/lib/nucleus/adapters/v1/cloud_control/vars.rb +0 -88
@@ -1,65 +1,65 @@
1
- module Nucleus
2
- module Adapters
3
- module V1
4
- class Heroku < Stub
5
- module Vars
6
- # @see Stub#env_vars
7
- def env_vars(application_id)
8
- all_vars = get("/apps/#{application_id}/config-vars").body
9
- formatted_vars = []
10
- all_vars.each do |key, value|
11
- formatted_vars.push(id: key, key: key, value: value)
12
- end
13
- formatted_vars
14
- end
15
-
16
- # @see Stub#env_var
17
- def env_var(application_id, env_var_key)
18
- all_vars = get("/apps/#{application_id}/config-vars").body
19
- fail Errors::AdapterResourceNotFoundError,
20
- "Env. var key '#{env_var_key}' does not exist" unless env_var?(application_id, env_var_key, all_vars)
21
-
22
- { id: env_var_key, key: env_var_key, value: all_vars[env_var_key.to_sym] }
23
- end
24
-
25
- # @see Stub#create_env_var
26
- def create_env_var(application_id, env_var)
27
- fail Errors::SemanticAdapterRequestError,
28
- "Env. var key '#{env_var[:key]}' already taken" if env_var?(application_id, env_var[:key])
29
-
30
- request_body = { env_var[:key] => env_var[:value] }
31
- all_vars = patch("/apps/#{application_id}/config-vars", body: request_body).body
32
- { id: env_var[:key], key: env_var[:key], value: all_vars[env_var[:key].to_sym] }
33
- end
34
-
35
- # @see Stub#update_env_var
36
- def update_env_var(application_id, env_var_key, env_var)
37
- fail Errors::AdapterResourceNotFoundError,
38
- "Env. var key '#{env_var_key}' does not exist" unless env_var?(application_id, env_var_key)
39
-
40
- request_body = { env_var_key => env_var[:value] }
41
- updated_vars = patch("/apps/#{application_id}/config-vars", body: request_body).body
42
- { id: env_var_key, key: env_var_key, value: updated_vars[env_var_key.to_sym] }
43
- end
44
-
45
- # @see Stub#delete_env_var
46
- def delete_env_var(application_id, env_var_key)
47
- fail Errors::AdapterResourceNotFoundError,
48
- "Env. var key '#{env_var_key}' does not exist" unless env_var?(application_id, env_var_key)
49
-
50
- # vars can be deleted by setting them to null / nil
51
- request_body = { env_var_key => nil }
52
- patch("/apps/#{application_id}/config-vars", body: request_body).body
53
- end
54
-
55
- private
56
-
57
- def env_var?(application_id, env_var_key, all_vars = nil)
58
- all_vars = get("/apps/#{application_id}/config-vars").body if all_vars.nil?
59
- all_vars.key? env_var_key.to_sym
60
- end
61
- end
62
- end
63
- end
64
- end
65
- end
1
+ module Nucleus
2
+ module Adapters
3
+ module V1
4
+ class Heroku < Stub
5
+ module Vars
6
+ # @see Stub#env_vars
7
+ def env_vars(application_id)
8
+ all_vars = get("/apps/#{application_id}/config-vars").body
9
+ formatted_vars = []
10
+ all_vars.each do |key, value|
11
+ formatted_vars.push(id: key, key: key, value: value)
12
+ end
13
+ formatted_vars
14
+ end
15
+
16
+ # @see Stub#env_var
17
+ def env_var(application_id, env_var_key)
18
+ all_vars = get("/apps/#{application_id}/config-vars").body
19
+ raise Errors::AdapterResourceNotFoundError,
20
+ "Env. var key '#{env_var_key}' does not exist" unless env_var?(application_id, env_var_key, all_vars)
21
+
22
+ { id: env_var_key, key: env_var_key, value: all_vars[env_var_key.to_sym] }
23
+ end
24
+
25
+ # @see Stub#create_env_var
26
+ def create_env_var(application_id, env_var)
27
+ raise Errors::SemanticAdapterRequestError,
28
+ "Env. var key '#{env_var[:key]}' already taken" if env_var?(application_id, env_var[:key])
29
+
30
+ request_body = { env_var[:key] => env_var[:value] }
31
+ all_vars = patch("/apps/#{application_id}/config-vars", body: request_body).body
32
+ { id: env_var[:key], key: env_var[:key], value: all_vars[env_var[:key].to_sym] }
33
+ end
34
+
35
+ # @see Stub#update_env_var
36
+ def update_env_var(application_id, env_var_key, env_var)
37
+ raise Errors::AdapterResourceNotFoundError,
38
+ "Env. var key '#{env_var_key}' does not exist" unless env_var?(application_id, env_var_key)
39
+
40
+ request_body = { env_var_key => env_var[:value] }
41
+ updated_vars = patch("/apps/#{application_id}/config-vars", body: request_body).body
42
+ { id: env_var_key, key: env_var_key, value: updated_vars[env_var_key.to_sym] }
43
+ end
44
+
45
+ # @see Stub#delete_env_var
46
+ def delete_env_var(application_id, env_var_key)
47
+ raise Errors::AdapterResourceNotFoundError,
48
+ "Env. var key '#{env_var_key}' does not exist" unless env_var?(application_id, env_var_key)
49
+
50
+ # vars can be deleted by setting them to null / nil
51
+ request_body = { env_var_key => nil }
52
+ patch("/apps/#{application_id}/config-vars", body: request_body).body
53
+ end
54
+
55
+ private
56
+
57
+ def env_var?(application_id, env_var_key, all_vars = nil)
58
+ all_vars = get("/apps/#{application_id}/config-vars").body if all_vars.nil?
59
+ all_vars.key? env_var_key.to_sym
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,68 +1,68 @@
1
- module Nucleus
2
- module Adapters
3
- module V1
4
- class OpenshiftV2 < Stub
5
- module AppStates
6
- # Determine the current state of the application in the Nucleus lifecycle.
7
- # @return [Symbol] application state according to {Nucleus::Enums::ApplicationStates}
8
- def application_state(app, gear_groups = nil, deployments = nil)
9
- deployments = load_deployments(app[:id]) unless deployments
10
- gear_groups = load_gears(app[:id]) unless gear_groups
11
-
12
- return :created if state_created?(app, gear_groups, deployments)
13
- return :deployed if state_deployed?(app, gear_groups, deployments)
14
- return :running if gear_groups[0][:gears].any? { |gear| gear[:state] == 'started' }
15
- return :stopped if gear_groups[0][:gears].all? { |gear| gear[:state] == 'stopped' }
16
- return :idle if gear_groups[0][:gears].all? { |gear| gear[:state] == 'idle' }
17
-
18
- log.debug("Failed to determine state for: #{app}")
19
- fail Errors::UnknownAdapterCallError,
20
- 'Could not determine app state. Please verify the Openshift V2 adapter'
21
- end
22
-
23
- private
24
-
25
- def state_created?(app, gear_groups, deployments)
26
- # this state exists, but only within the first seconds before the original deployment is applied
27
- return true if gear_groups[0][:gears].all? { |gear| gear[:state] == 'new' }
28
-
29
- if app[:keep_deployments].to_i > 1
30
- if deployments.length == 1
31
- original_os_deployment = original_deployment(app, deployments)
32
- currently_activated = active_deployment(app, deployments)
33
- # if the current deployment still is the default, the state must be :created
34
- return true if original_os_deployment && original_os_deployment[:id] == currently_activated[:id]
35
- end
36
- # if there is more than 1 deployment, state can't be :created
37
- else
38
- # app was not created with nucleus or has recently been modified :/
39
- diff = Time.parse(deployments[0][:created_at]).to_i - Time.parse(app[:creation_time]).to_i
40
- # we can analyse if the deployment was created within 15 seconds after the application,
41
- # then there can't possibly be an actual code deployment
42
- return true if diff.abs < 15
43
- end
44
- # does not seem to be in state :created
45
- false
46
- end
47
-
48
- def state_deployed?(app, gear_groups, deployments)
49
- # Gears must all be stopped
50
- return false unless gear_groups[0][:gears].all? { |gear| gear[:state] == 'stopped' }
51
-
52
- deployments = load_deployments(app[:id]) unless deployments
53
-
54
- # If there still is the initial deployment, then the state can be deployed.
55
- original_os_deployment = original_deployment(app, deployments) unless original_os_deployment
56
- return false unless original_os_deployment
57
-
58
- activations = deployments.inject(0) { |a, e| a + e[:activations].length }
59
- # deduct the activations of the original deployment
60
- activations -= original_os_deployment[:activations].length
61
- return false if activations > 1
62
- true
63
- end
64
- end
65
- end
66
- end
67
- end
68
- end
1
+ module Nucleus
2
+ module Adapters
3
+ module V1
4
+ class OpenshiftV2 < Stub
5
+ module AppStates
6
+ # Determine the current state of the application in the Nucleus lifecycle.
7
+ # @return [Symbol] application state according to {Nucleus::Enums::ApplicationStates}
8
+ def application_state(app, gear_groups = nil, deployments = nil)
9
+ deployments = load_deployments(app[:id]) unless deployments
10
+ gear_groups = load_gears(app[:id]) unless gear_groups
11
+
12
+ return :created if state_created?(app, gear_groups, deployments)
13
+ return :deployed if state_deployed?(app, gear_groups, deployments)
14
+ return :running if gear_groups[0][:gears].any? { |gear| gear[:state] == 'started' }
15
+ return :stopped if gear_groups[0][:gears].all? { |gear| gear[:state] == 'stopped' }
16
+ return :idle if gear_groups[0][:gears].all? { |gear| gear[:state] == 'idle' }
17
+
18
+ log.debug("Failed to determine state for: #{app}")
19
+ raise Errors::UnknownAdapterCallError,
20
+ 'Could not determine app state. Please verify the Openshift V2 adapter'
21
+ end
22
+
23
+ private
24
+
25
+ def state_created?(app, gear_groups, deployments)
26
+ # this state exists, but only within the first seconds before the original deployment is applied
27
+ return true if gear_groups[0][:gears].all? { |gear| gear[:state] == 'new' }
28
+
29
+ if app[:keep_deployments].to_i > 1
30
+ if deployments.length == 1
31
+ original_os_deployment = original_deployment(app, deployments)
32
+ currently_activated = active_deployment(app, deployments)
33
+ # if the current deployment still is the default, the state must be :created
34
+ return true if original_os_deployment && original_os_deployment[:id] == currently_activated[:id]
35
+ end
36
+ # if there is more than 1 deployment, state can't be :created
37
+ else
38
+ # app was not created with nucleus or has recently been modified :/
39
+ diff = Time.parse(deployments[0][:created_at]).to_i - Time.parse(app[:creation_time]).to_i
40
+ # we can analyse if the deployment was created within 15 seconds after the application,
41
+ # then there can't possibly be an actual code deployment
42
+ return true if diff.abs < 15
43
+ end
44
+ # does not seem to be in state :created
45
+ false
46
+ end
47
+
48
+ def state_deployed?(app, gear_groups, deployments)
49
+ # Gears must all be stopped
50
+ return false unless gear_groups[0][:gears].all? { |gear| gear[:state] == 'stopped' }
51
+
52
+ deployments = load_deployments(app[:id]) unless deployments
53
+
54
+ # If there still is the initial deployment, then the state can be deployed.
55
+ original_os_deployment = original_deployment(app, deployments) unless original_os_deployment
56
+ return false unless original_os_deployment
57
+
58
+ activations = deployments.inject(0) { |a, e| a + e[:activations].length }
59
+ # deduct the activations of the original deployment
60
+ activations -= original_os_deployment[:activations].length
61
+ return false if activations > 1
62
+ true
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -18,7 +18,7 @@ module Nucleus
18
18
  def create_application(application_entity)
19
19
  # handle runtimes / cartridges
20
20
  fail_with(:only_one_runtime) if application_entity[:runtimes].length > 1
21
- fail_with(:must_have_runtime) if application_entity[:runtimes].length == 0
21
+ fail_with(:must_have_runtime) if application_entity[:runtimes].empty?
22
22
  application_entity[:cartridge] = cartridge(application_entity.delete(:runtimes)[0])
23
23
 
24
24
  # updates the application with a valid region identity
@@ -1,96 +1,96 @@
1
- module Nucleus
2
- module Adapters
3
- module V1
4
- class OpenshiftV2 < Stub
5
- module Data
6
- # @see Stub#deploy
7
- def deploy(application_id, file, file_compression_format)
8
- app_id = app_id_by_name(application_id)
9
- app = get("/application/#{app_id}").body[:data]
10
- app_state = application_state(app)
11
- account = get('/user').body[:data]
12
- repo_name = "nucleus.app.repo.openshift_v2.deploy.#{application_id}.#{SecureRandom.uuid}"
13
- # clone, extract, push and finally delete cloned repository (sync)
14
- with_ssh_key do
15
- GitDeployer.new(repo_name, app[:git_url], account[:email]).deploy(file, file_compression_format)
16
- end
17
-
18
- # auto deployment could be active for applications not created with Nucleus
19
- return if app[:auto_deploy]
20
-
21
- build_deployment(app_id)
22
-
23
- return unless app_state == Enums::ApplicationStates::CREATED
24
-
25
- # and finally stop so we don't get to see the sample application and switch to the deployed state
26
- send_event(application_id, 'stop')
27
- end
28
-
29
- # @see Stub#download
30
- def download(application_id, compression_format)
31
- # Only possible with git
32
- app = get("/application/#{app_id_by_name(application_id)}").body[:data]
33
- if application_state(app) == Enums::ApplicationStates::CREATED
34
- fail Errors::SemanticAdapterRequestError, 'Application must be deployed before data can be downloaded'
35
- end
36
- # compress files to archive but exclude the .git repo
37
- repo_name = "nucleus.app.repo.openshift_v2.download.#{application_id}.#{SecureRandom.uuid}"
38
- with_ssh_key do
39
- GitDeployer.new(repo_name, app[:git_url], nil).download(compression_format, true)
40
- end
41
- end
42
-
43
- # @see Stub#rebuild
44
- def rebuild(application_id)
45
- app_id = app_id_by_name(application_id)
46
- app = get("/application/#{app_id}").body[:data]
47
- if application_state(app) == Enums::ApplicationStates::CREATED
48
- fail Errors::SemanticAdapterRequestError, 'Application must be deployed before data can be rebuild'
49
- end
50
-
51
- account = get('/user').body[:data]
52
- repo_name = "nucleus.app.repo.openshift_v2.rebuild.#{application_id}.#{SecureRandom.uuid}"
53
-
54
- with_ssh_key do
55
- GitDeployer.new(repo_name, app[:git_url], account[:email]).trigger_build
56
- end
57
-
58
- # if auto deployment ist disabled, we must also trigger a clean build
59
- build_deployment(app_id) unless app[:auto_deploy]
60
-
61
- # return with updated application
62
- application(application_id)
63
- end
64
-
65
- private
66
-
67
- def build_deployment(app_id)
68
- # deploy
69
- post("/application/#{app_id}/deployments", body: { force_clean_build: true })
70
- end
71
-
72
- def with_ssh_key
73
- # 409 Conflict:
74
- # - 120: SSH key with name #{name} already exists. Use a different name or delete conflicting key and retry
75
- # - 121: Given public key is already in use. Use different key or delete conflicting key and retry.
76
-
77
- # load ssh key into Openshift
78
- matches = nucleus_config.ssh.handler.public_key.match(/(.*)\s{1}(.*)\s{1}(.*)/)
79
- key_name = register_key(matches[1], matches[2])
80
- return yield
81
- ensure
82
- # unload ssh key, allow 404 if the key couldn't be registered at first
83
- delete("/user/keys/#{key_name}", expects: [200, 204, 404]) if key_name
84
- end
85
-
86
- def register_key(type, key)
87
- key_name = "nucleus-#{SecureRandom.uuid}"
88
- # ignore if the key was already assigned to a different name (status == 409 && exit_code == 121)
89
- post('/user/keys', body: { name: key_name, type: type, content: key }, expects: [201, 409])
90
- key_name
91
- end
92
- end
93
- end
94
- end
95
- end
96
- end
1
+ module Nucleus
2
+ module Adapters
3
+ module V1
4
+ class OpenshiftV2 < Stub
5
+ module Data
6
+ # @see Stub#deploy
7
+ def deploy(application_id, file, file_compression_format)
8
+ app_id = app_id_by_name(application_id)
9
+ app = get("/application/#{app_id}").body[:data]
10
+ app_state = application_state(app)
11
+ account = get('/user').body[:data]
12
+ repo_name = "nucleus.app.repo.openshift_v2.deploy.#{application_id}.#{SecureRandom.uuid}"
13
+ # clone, extract, push and finally delete cloned repository (sync)
14
+ with_ssh_key do
15
+ GitDeployer.new(repo_name, app[:git_url], account[:email]).deploy(file, file_compression_format)
16
+ end
17
+
18
+ # auto deployment could be active for applications not created with Nucleus
19
+ return if app[:auto_deploy]
20
+
21
+ build_deployment(app_id)
22
+
23
+ return unless app_state == Enums::ApplicationStates::CREATED
24
+
25
+ # and finally stop so we don't get to see the sample application and switch to the deployed state
26
+ send_event(application_id, 'stop')
27
+ end
28
+
29
+ # @see Stub#download
30
+ def download(application_id, compression_format)
31
+ # Only possible with git
32
+ app = get("/application/#{app_id_by_name(application_id)}").body[:data]
33
+ if application_state(app) == Enums::ApplicationStates::CREATED
34
+ raise Errors::SemanticAdapterRequestError, 'Application must be deployed before data can be downloaded'
35
+ end
36
+ # compress files to archive but exclude the .git repo
37
+ repo_name = "nucleus.app.repo.openshift_v2.download.#{application_id}.#{SecureRandom.uuid}"
38
+ with_ssh_key do
39
+ GitDeployer.new(repo_name, app[:git_url], nil).download(compression_format, true)
40
+ end
41
+ end
42
+
43
+ # @see Stub#rebuild
44
+ def rebuild(application_id)
45
+ app_id = app_id_by_name(application_id)
46
+ app = get("/application/#{app_id}").body[:data]
47
+ if application_state(app) == Enums::ApplicationStates::CREATED
48
+ raise Errors::SemanticAdapterRequestError, 'Application must be deployed before data can be rebuild'
49
+ end
50
+
51
+ account = get('/user').body[:data]
52
+ repo_name = "nucleus.app.repo.openshift_v2.rebuild.#{application_id}.#{SecureRandom.uuid}"
53
+
54
+ with_ssh_key do
55
+ GitDeployer.new(repo_name, app[:git_url], account[:email]).trigger_build
56
+ end
57
+
58
+ # if auto deployment ist disabled, we must also trigger a clean build
59
+ build_deployment(app_id) unless app[:auto_deploy]
60
+
61
+ # return with updated application
62
+ application(application_id)
63
+ end
64
+
65
+ private
66
+
67
+ def build_deployment(app_id)
68
+ # deploy
69
+ post("/application/#{app_id}/deployments", body: { force_clean_build: true })
70
+ end
71
+
72
+ def with_ssh_key
73
+ # 409 Conflict:
74
+ # - 120: SSH key with name #{name} already exists. Use a different name or delete conflicting key and retry
75
+ # - 121: Given public key is already in use. Use different key or delete conflicting key and retry.
76
+
77
+ # load ssh key into Openshift
78
+ matches = nucleus_config.ssh.handler.public_key.match(/(.*)\s{1}(.*)\s{1}(.*)/)
79
+ key_name = register_key(matches[1], matches[2])
80
+ return yield
81
+ ensure
82
+ # unload ssh key, allow 404 if the key couldn't be registered at first
83
+ delete("/user/keys/#{key_name}", expects: [200, 204, 404]) if key_name
84
+ end
85
+
86
+ def register_key(type, key)
87
+ key_name = "nucleus-#{SecureRandom.uuid}"
88
+ # ignore if the key was already assigned to a different name (status == 409 && exit_code == 121)
89
+ post('/user/keys', body: { name: key_name, type: type, content: key }, expects: [201, 409])
90
+ key_name
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end