Skip to content

Commit

Permalink
Updated Rakefile to delete extension from GOV cloud
Browse files Browse the repository at this point in the history
Signed-off-by: NimishaS <nimisha.sharad@msystechnologies.com>
  • Loading branch information
NimishaS committed Sep 15, 2017
1 parent ddafdaf commit 13b6505
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ def update_definition_xml(xml, args)
File.write(xml, doc.to_xml)
end

def get_definition_xml_name(date_tag = nil)
date_tag.nil? ? "#{MANIFEST_NAME}_#{Date.today.strftime("%Y%m%d")}" : "#{MANIFEST_NAME}_#{date_tag}"
def get_definition_xml_name(args)
"#{MANIFEST_NAME}_#{args.target_type}_#{args.build_date_yyyymmdd}"
end

def get_definition_xml(args, date_tag = nil)
Expand Down Expand Up @@ -372,7 +372,7 @@ CONFIRMATION
puts "Continuing with publish request..."

date_tag = Date.today.strftime("%Y%m%d")
manifestFile = File.new("publishDefinitionXml_#{date_tag}", "w")
manifestFile = File.new("#{MANIFEST_NAME}_#{args.target_type}_#{date_tag}", "w")
definitionXmlFile = manifestFile.path
puts "Writing publishDefinitionXml to #{definitionXmlFile}..."
puts "[[\n#{definitionXml}\n]]"
Expand Down Expand Up @@ -430,8 +430,6 @@ task :delete, [:deploy_type, :target_type, :chef_deploy_namespace, :full_extensi
publish_options = JSON.parse(File.read("Publish.json"))
extensionName = publish_options[args.target_type]["definitionParams"]["extensionName"]

delete_uri = get_mgmt_uri(args.deploy_type) + "#{subscription_id}/services/extensions/#{args.chef_deploy_namespace}/#{extensionName}/#{args.full_extension_version}"

# Get user confirmation, since we are deleting from Azure.
puts <<-CONFIRMATION
Expand All @@ -443,7 +441,6 @@ This task deletes a published chef extension package from Azure #{args.deploy_ty
Subscription Name: #{subscription_name}
Publisher Name: #{args.chef_deploy_namespace}
Extension Name: #{extensionName}
Delete Uri: #{delete_uri}
****************************************
CONFIRMATION

Expand All @@ -453,7 +450,20 @@ CONFIRMATION

puts "Continuing with delete request..."

system("powershell -nologo -noprofile -executionpolicy unrestricted Import-Module .\\scripts\\deletepkg.psm1;Delete-ChefPkg #{ENV["publishsettings"]} \"\'#{subscription_name}\'\" #{delete_uri}")
if args.deploy_type == GOV
begin
cli_cmd = Mixlib::ShellOut.new("#{ENV['azure_extension_cli']} delete-version --name #{extensionName} --version #{args.full_extension_version}")
result = cli_cmd.run_command
result.error!
puts "The extension has been successfully deleted."
rescue Mixlib::ShellOut::ShellCommandFailed => e
puts "Failure while running `#{ENV['azure_extension_cli']} delete-version`: #{e}"
exit
end
else
delete_uri = get_mgmt_uri(args.deploy_type) + "#{subscription_id}/services/extensions/#{args.chef_deploy_namespace}/#{extensionName}/#{args.full_extension_version}"
system("powershell -nologo -noprofile -executionpolicy unrestricted Import-Module .\\scripts\\deletepkg.psm1;Delete-ChefPkg #{ENV["publishsettings"]} \"\'#{subscription_name}\'\" #{delete_uri}")
end
end

desc "Updates the azure chef extension package metadata which was publised Ex: update[\"definitionxml.xml\"]."
Expand All @@ -475,7 +485,7 @@ task :update, [:deploy_type, :target_type, :extension_version, :build_date_yyyym
# assert build date since we form the build tag
error_and_exit! "Please specify the :build_date_yyyymmdd param used to identify the published build" if args.build_date_yyyymmdd.nil?

definitionXmlFile = get_definition_xml_name(args.build_date_yyyymmdd)
definitionXmlFile = get_definition_xml_name(args)
update_definition_xml(definitionXmlFile, args) # Updates IsInternal as False for public release and True for internal release

subscription_id, subscription_name = load_publish_settings
Expand Down

0 comments on commit 13b6505

Please sign in to comment.