Class: Autoproj::Jenkins::Credentials

Inherits:
Object
  • Object
show all
Defined in:
lib/autoproj/jenkins/credentials.rb

Overview

Management of the mapping from a VCS description to the corresponding Jenkins credential

Defined Under Namespace

Classes: Credential

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCredentials

Returns a new instance of Credentials.



40
41
42
# File 'lib/autoproj/jenkins/credentials.rb', line 40

def initialize
    @credentials = Hash.new
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



38
39
40
# File 'lib/autoproj/jenkins/credentials.rb', line 38

def credentials
  @credentials
end

Class Method Details

.parse(string) ⇒ Credential

Parse a string that represents a single credential and return it

Parameters:

Returns:



27
28
29
30
31
32
33
34
35
36
# File 'lib/autoproj/jenkins/credentials.rb', line 27

def self.parse(string)
    vcs, *uri = string.split(':')
    if !vcs || vcs.empty? || uri.empty?
        raise ArgumentError, "expected VCS:URL but got #{string}"
    elsif !Autoproj::Jenkins.vcs_supported?(vcs)
        raise UnhandledVCS, "#{vcs} is not a supported VCS"
    end
    uri = URI.parse(uri.join(':'))
    Credential.new(vcs.to_sym, uri.scheme, uri.host)
end

Instance Method Details

#[](vcs) ⇒ Object



48
49
50
# File 'lib/autoproj/jenkins/credentials.rb', line 48

def [](vcs)
    credentials[vcs.to_sym] || Array.new
end

#add(credential) ⇒ Object



52
53
54
# File 'lib/autoproj/jenkins/credentials.rb', line 52

def add(credential)
    (credentials[credential.vcs] ||= Array.new) << credential
end

#empty?Boolean

Returns:



44
45
46
# File 'lib/autoproj/jenkins/credentials.rb', line 44

def empty?
    credentials.empty?
end

#for(vcs) ⇒ nil, Credential

Return the credential description for the given VCS

Parameters:

Returns:



60
61
62
63
64
# File 'lib/autoproj/jenkins/credentials.rb', line 60

def for(vcs)
    self[vcs.type].find do |c|
        c.matches?(vcs)
    end
end