Last active
August 28, 2015 22:26
-
-
Save Maniacal/b648b2d6f387500f17c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Provider: | |
require 'artifactory_helper' | |
class Chef | |
class Provider | |
class Artifact < Chef::Provider | |
#include ArtifactoryHelper | |
def load_current_resource | |
@current_resource = Chef::Resource::Artifactory.new(new_resource.name) | |
@current_resource.remote_path(new_resource.remote_path) | |
@current_resource.override(new_resource.override) | |
end | |
def action_create | |
# Connect to Artifactory | |
ArtifactoryHelper.connect_to_artifactory | |
artifact = ArtifactoryHelper.get_artifact(current_resource.name) | |
puts "############## This is the artifact: #{artifact}" | |
end | |
end | |
end | |
end | |
Resource: | |
class Chef | |
class Resource | |
class Artifact < Chef::Resource | |
provides :artifact | |
def initialize(name, run_context=nil) | |
super | |
@resource_name = :artifact | |
@allowed_actions = [:create] | |
@action = :create | |
@name = name | |
@remote_path = nil | |
@override = false | |
end | |
def name(arg=nil) | |
set_or_return(:name, arg, :kind_of => String) | |
end | |
def remote_path(arg=nil) | |
set_or_return(:remote_path, arg, :kind_of => String) | |
end | |
def override(arg=nil) | |
set_or_return(:override, arg, :kind_of => [TrueClass, FalseClass]) | |
end | |
end | |
end | |
end | |
Helper: | |
require 'artifactory' | |
module ArtifactoryHelper | |
def connect_to_artifactory | |
Artifactory.configure do |config| | |
config.endpoint = node['artifactory_client']['endpoint'] | |
config.username = node['artifactory_client']['username'] | |
config.password = node['artifactory_client']['password'] | |
end | |
end | |
def get_artifact(artifact_name) | |
return Artifact.search(name: artifact_name).first | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment