class Artifactory::Resource::Certificate
Public Class Methods
all(options = {})
click to toggle source
Get a list of all certificates in the system.
@param [Hash] options
the list of options
@option options [Artifactory::Client] :client
the client object to make the request with
@return [Array<Resource::Certificate>]
the list of builds
# File lib/artifactory/resources/certificate.rb, line 16 def all(options = {}) client = extract_client!(options) client.get("/api/system/security/certificates").map do |cert| from_hash(cert, client: client) end.compact end
from_hash(hash, options = {})
click to toggle source
@see Artifactory::Resource::Base.from_hash
Calls superclass method
Artifactory::Resource::Base::from_hash
# File lib/artifactory/resources/certificate.rb, line 26 def from_hash(hash, options = {}) super.tap do |instance| instance.issued_on = Time.parse(instance.issued_on) rescue nil instance.valid_until = Time.parse(instance.valid_until) rescue nil end end
Public Instance Methods
delete()
click to toggle source
Delete this certificate from artifactory, suppressing any ResourceNotFound
exceptions might occur.
@return [Boolean]
true if the object was deleted successfully, false otherwise
# File lib/artifactory/resources/certificate.rb, line 49 def delete client.delete(api_path) true rescue Error::HTTPError false end
upload()
click to toggle source
Upload a certificate. If the first parameter is a File object, that file descriptor is passed to the uploader. If the first parameter is a string, it is assumed to be a path to a local file on disk. This method will automatically construct the File object from the given path.
@example Upload a certificate from a File instance
certificate = Certificate.new(local_path: '/path/to/cert.pem', certificate_alias: 'test') certificate.upload
@return [Resource::Certificate]
# File lib/artifactory/resources/certificate.rb, line 68 def upload file = File.new(File.expand_path(local_path)) headers = { "Content-Type" => "application/text" } response = client.post(api_path, file, headers) return unless response.is_a?(Hash) self.class.all.select { |x| x.certificate_alias.eql?(certificate_alias) }.first end
Private Instance Methods
api_path()
click to toggle source
The path to this certificate on the server.
@return [String]
# File lib/artifactory/resources/certificate.rb, line 86 def api_path "/api/system/security/certificates/#{url_safe(certificate_alias)}" end