Skip to content

Commit

Permalink
Support the force registration of tentacles (#153)
Browse files Browse the repository at this point in the history
* feat: support force flag for command calls
* Docs and validate option_flag with !.empty?
  • Loading branch information
NootN00t authored and brentm5 committed Jan 17, 2020
1 parent 73b0468 commit abb6c87
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ end
- :api_key: Api Key used to register Tentacle to Octopus Server
- :roles: Array of roles to apply to Tentacle when registering with Octopus Deploy Server (e.g ["web-server","app-server"])
- :environment: Which environment or environments the Tentacle will become part of when registering with Octopus Deploy Server (Defaults to node.chef_environment). Accepts string or array.
- :forced_registration: Whether the command should include `--force` to support overwriting tentacle references that already exist in Octopus Server
- :tenants: Optional array of tenants to add to the Tentacle. Tenant must already exist on Octopus Deploy Server. Requires Octopus 3.4
- :tenant_tags: Optional array of tenant tags to add to the Tentacle. Tags must already exist on Octopus Deploy Server. If tag is part of a tag group, include the group name followed by a slash `<groupname>/<tag>`. e.g ( Priority/VIP, Datacenter/US ).. Requires Octopus 3.4
- :tentacle_name: Optional custom name for Tentacle. Defaults to the Chef node name
Expand Down
5 changes: 5 additions & 0 deletions libraries/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ def option_list(name, options)
options.map { |option| option(name, option) }.join(' ') if name && options
end

# Includes the named option based on boolean input
def option_flag(name, value)
name && !name.empty? && value ? "--#{name} " : ''
end

def option(name, option)
"--#{name} \"#{option}\"" if name && option
end
Expand Down
15 changes: 14 additions & 1 deletion resources/tentacle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
property :tenants, [Array, nil], default: nil
property :tenant_tags, [Array, nil], default: nil
property :tentacle_name, String, default: node.name
property :forced_registration, [true, false], default: false
property :service_user, [String, nil], default: nil
property :service_password, [String, nil], default: nil
property :public_dns, String, default: node['fqdn']
Expand Down Expand Up @@ -159,7 +160,19 @@
action :run
cwd tentacle_install_location
code <<-EOH
.\\Tentacle.exe register-with --instance "#{new_resource.instance}" --server "#{new_resource.server}" --name "#{new_resource.tentacle_name}" --publicHostName "#{new_resource.public_dns}" --apiKey "#{new_resource.api_key}" #{register_comm_config(new_resource.polling, port)} #{option_list('environment', environment)} #{option_list('role', new_resource.roles)} #{option_list('tenant', new_resource.tenants)} #{option_list('tenanttag', new_resource.tenant_tags)} #{option('tenanted-deployment-participation', new_resource.tenated_deployment_participation)} --console
.\\Tentacle.exe register-with --instance "#{new_resource.instance}" `
--server "#{new_resource.server}" `
--name "#{new_resource.tentacle_name}" `
--publicHostName "#{new_resource.public_dns}" `
--apiKey "#{new_resource.api_key}" `
#{register_comm_config(new_resource.polling, port)} `
#{option_list('environment', environment)} `
#{option_list('role', new_resource.roles)} `
#{option_list('tenant', new_resource.tenants)} `
#{option_list('tenanttag', new_resource.tenant_tags)} `
#{option('tenanted-deployment-participation', new_resource.tenated_deployment_participation)} `
#{option_flag('force', new_resource.forced_registration)} `
--console
#{catch_powershell_error('Registering Tentacle')}
EOH
# This is sort of a hack, you need to specify the config_path on register if it is not default
Expand Down
22 changes: 22 additions & 0 deletions spec/unit/lib_shared_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@
end
end

describe 'option_flag' do
it 'should return --attr flag if name is valid and value is true' do
name = 'attr'
value = true
expect(shared.option_flag(name, value)).to eq '--attr '
end

it 'should return empty string if name is valid and value is false' do
name = 'attr'
value = false
expect(shared.option_flag(name, value)).to eq ''
end

it 'should return empty string if inputs are invalid' do
expect(shared.option_flag('', false)).to eq ''
expect(shared.option_flag('', true)).to eq ''
expect(shared.option_flag(nil, true)).to eq ''
expect(shared.option_flag(nil, false)).to eq ''
expect(shared.option_flag('attr', nil)).to eq ''
end
end

describe 'option' do
it 'should return the command line command for an option' do
name = 'name'
Expand Down

0 comments on commit abb6c87

Please sign in to comment.