Class: Chef::Knife::ArtifactoryShare

Inherits:
Knife::SupermarketShare
  • Object
show all
Defined in:
lib/chef/knife/artifactory_share.rb

Instance Method Summary collapse

Instance Method Details

#cookbook_versionString?

Returns version of cookbook present in cookbook path or nil if no coobook versions exist locally.

Examples:

cookbook_version #=> 1.0.1
cookbook_version #=> 0.1.0
cookbook_version #=> nil

Returns:

  • (String, nil)

    version of cookbook present in cookbook path or nil if no coobook versions exist locally.



81
82
83
84
85
86
87
# File 'lib/chef/knife/artifactory_share.rb', line 81

def cookbook_version
  cl = Chef::CookbookLoader.new(cookbook_path)
  if cl.cookbook_exists?(cookbook_name)
    cookbook = cl[cookbook_name]
    cookbook.version
  end
end

#cookbook_versions_in_artifactoryArray<String>

Returns versions in artifactory.

Examples:

cookbook_versions_in_artifactory #=> ["1.0.0", "1.0.1", "1.1.0", "1.2.0"]

Returns:

  • (Array<String>)

    versions in artifactory



61
62
63
64
65
66
# File 'lib/chef/knife/artifactory_share.rb', line 61

def cookbook_versions_in_artifactory
  return [] if cookbook_name.nil?

  data = noauth_rest.get("#{supermarket_uri}/cookbooks/#{cookbook_name}")
  data["metrics"]["downloads"]["versions"].keys
end

#orig_do_uploadObject



32
# File 'lib/chef/knife/artifactory_share.rb', line 32

alias_method :orig_do_upload, :do_upload

#orig_get_categoryObject



31
# File 'lib/chef/knife/artifactory_share.rb', line 31

alias_method :orig_get_category, :get_category

#orig_runObject



30
# File 'lib/chef/knife/artifactory_share.rb', line 30

alias_method :orig_run, :run

#runObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/chef/knife/artifactory_share.rb', line 34

def run
  # I'm forced to use threadlocal until we find a better solution... can't really find a way to pass configuration
  # down to the Chef::CookbookUploader, Chef::ServerAPI, Chef::HTTP or Chef::HTTP::Authenticator
  # (which are created one after another starting) with CookbookUploader to make it skip the signing key verification.
  # Can make the authenticator skip by passing load_signing_key(nil, nil) and opts[:sign_request] => false
  Thread.current[:artifactory_deploy] = "yes"
  # Send artifactory deploy flag to super
  config[:artifactory_deploy] = true
  Chef::Log.debug("[KNIFE-ART] running site share with config: #{config}")

  if !overwrite_cookbook? && cookbook_versions_in_artifactory.include?(cookbook_version)
    ui.info("Cookbook version already exists, skipping upload.")
    exit(0)
  end

  orig_run
ensure
    # always cleanup threadlocal
  Thread.current[:artifactory_deploy] = nil
end