class Chef::Knife::ArtifactoryUnshare

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/artifactory_unshare.rb, line 24
def run
  @cookbook_name = @name_args[0]
  if @cookbook_name.nil?
    show_usage
    ui.fatal "You must provide the name of the cookbook to unshare"
    exit 1
  end
  @cookbook_version = @name_args[1]
  if @cookbook_version.nil?
    show_usage
    ui.fatal "You must provide a version to unshare"
    exit 1
  end

  confirm "Are you sure you want to delete version #{@cookbook_version} of the cookbook #{@cookbook_name} from Artifactory"

  begin
    url = "#{cookbooks_api_url}/#{@cookbook_name}/#{@cookbook_version}"
    noauth_rest.delete(url, auth_header)
  rescue Net::HTTPServerException => e
    raise e unless e.message =~ /Forbidden/ || e.message =~ /Unauthorized/
    ui.error "Forbidden: You must have delete permissions on the target repo to delete #{@cookbook_name}."
    exit 1
  end

  ui.info "Deleted version #{@cookbook_version} of the cookbook #{@cookbook_name}"
end

Private Instance Methods

auth_header() click to toggle source
# File lib/chef/knife/artifactory_unshare.rb, line 58
def auth_header
  @auth_header ||= begin
    ::KnifeArtifactory::Utils.auth_header_from(cookbooks_api_url)
  end
end
cookbooks_api_url() click to toggle source
# File lib/chef/knife/artifactory_unshare.rb, line 54
def cookbooks_api_url
  "#{config[:supermarket_site]}/api/v1/cookbooks"
end