Class: RightScale::CookbookRepository

Inherits:
Object
  • Object
show all
Includes:
Serializable
Defined in:
lib/right_agent/core_payload_types/cookbook_repository.rb

Overview

Cookbook repository

Constant Summary collapse

CHARS =

List of characters used to build cookbooks sha1 hash path component

("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Serializable

included

Constructor Details

#initialize(*args) ⇒ CookbookRepository

Initialize fields from given arguments



67
68
69
70
71
72
73
74
75
# File 'lib/right_agent/core_payload_types/cookbook_repository.rb', line 67

def initialize(*args)
  @repo_type      = args[0].to_sym
  @url            = args[1] if args.size > 1
  @tag            = args[2] if args.size > 2
  @cookbooks_path = args[3] if args.size > 3
  @ssh_key        = args[4] if args.size > 4
  @username       = args[5] if args.size > 5
  @password       = args[6] if args.size > 6
end

Instance Attribute Details

#cookbooks_pathObject

(Array) Path to cookbooks inside repostory Append to the location of the repository on disk prior to running chef. Optional (use location of repository as cookbook path if nil)



52
53
54
# File 'lib/right_agent/core_payload_types/cookbook_repository.rb', line 52

def cookbooks_path
  @cookbooks_path
end

#passwordObject

(String) Password used to retrieve svn and raw repositories Not used for git repositories.



64
65
66
# File 'lib/right_agent/core_payload_types/cookbook_repository.rb', line 64

def password
  @password
end

#repo_typeObject

(Symbol) Type of repository: one of :git, :svn, :download or :local

  • :git denotes a ‘git’ repository that should be retrieved via ‘git clone’

  • :svn denotes a ‘svn’ repository that should be retrieved via ‘svn checkout’

  • :download denotes a tar ball that should be retrieved via HTTP GET (HTTPS if url starts with https://)

  • :local denotes an already available cookbook (useful for testing)



39
40
41
# File 'lib/right_agent/core_payload_types/cookbook_repository.rb', line 39

def repo_type
  @repo_type
end

#ssh_keyObject

(String) Private SSH key used to retrieve git repositories Not used for svn and raw repositories.



56
57
58
# File 'lib/right_agent/core_payload_types/cookbook_repository.rb', line 56

def ssh_key
  @ssh_key
end

#tagObject

(String) git commit or svn branch that should be used to retrieve repository Use ‘master’ for git and ‘trunk’ for svn if tag is nil. Not used for raw repositories.



47
48
49
# File 'lib/right_agent/core_payload_types/cookbook_repository.rb', line 47

def tag
  @tag
end

#urlObject

(String) URI to repository (e.g. git://github.com/opscode/chef-repo.git)



42
43
44
# File 'lib/right_agent/core_payload_types/cookbook_repository.rb', line 42

def url
  @url
end

#usernameObject

(String) Username used to retrieve svn and raw repositories Not used for git repositories.



60
61
62
# File 'lib/right_agent/core_payload_types/cookbook_repository.rb', line 60

def username
  @username
end

Class Method Details

.from_hash(h) ⇒ Object

Instantiate from hash Keys of hash should be the corresponding symolized field name

Parameters

h(Hash)

Hash of values used to initialize cookbook repository

Return

repo(RightScale::CookbookRepository)

Corresponding instance



85
86
87
# File 'lib/right_agent/core_payload_types/cookbook_repository.rb', line 85

def self.from_hash(h)
  repo = new(h[:repo_type], h[:url], h[:tag], h[:cookbooks_path], h[:ssh_key], h[:username], h[:password])
end

Instance Method Details

#display_nameObject Also known as: to_s

Human friendly name used for audits

Return

name(String)

Cookbook repository display name



98
99
100
# File 'lib/right_agent/core_payload_types/cookbook_repository.rb', line 98

def display_name
  name = @url + (@tag && !@tag.empty? ? ":#{@tag}" : '')
end

#first_credentialObject

SVN username or git SSH key Provide compatibility for scraper



105
106
107
# File 'lib/right_agent/core_payload_types/cookbook_repository.rb', line 105

def first_credential
  @ssh_key || @username
end

#second_credentialObject

SVN password Provide compatibility for scraper



111
112
113
# File 'lib/right_agent/core_payload_types/cookbook_repository.rb', line 111

def second_credential
  @password
end

#serialized_membersObject

Array of serialized fields given to constructor



90
91
92
# File 'lib/right_agent/core_payload_types/cookbook_repository.rb', line 90

def serialized_members
  [ @repo_type, @url, @tag, @cookbooks_path, @ssh_key, @username, @password ]
end