Class: HCloud::Certificate

Inherits:
Resource show all
Defined in:
lib/hcloud/resources/certificate.rb

Overview

Represents a certificate

List all certificates

HCloud::Certificate.all
# => [#<HCloud::Certificate id: 1, ...>, ...]

Sort certificates

HCloud::Certificate.sort(name: :desc)
# => [#<HCloud::Certificate id: 1, ...>, ...]

HCloud::Certificate.sort(:id, name: :asc)
# => [#<HCloud::Certificate id: 1, ...>, ...]

Search certificates

HCloud::Certificate.where(name: "my_certificate")
# => #<HCloud::Certificate id: 1, ...>

HCloud::Certificate.where(type: "uploaded")
# => #<HCloud::Certificate id: 1, ...>

HCloud::Certificate.where(label_selector: { environment: "production" })
# => #<HCloud::Certificate id: 1, ...>

Find certificate by ID

HCloud::Certificate.find(1)
# => #<HCloud::Certificate id: 1, ...>

Create certificate

certificate = HCloud::Certificate.new(name: "my_certificate", type: "managed", domain_names: ["example.com"])
certificate.create
certificate.created?
# => true

certificate = HCloud::Certificate.create(name: "my_certificate", type: "managed", domain_names: ["example.com"])
# => #<HCloud::Certificate id: 1, ...>

Update certificate

certificate = HCloud::Certificate.find(1)
certificate.name = "another_certificate"
certificate.update

Delete certificate

certificate = HCloud::Certificate.find(1)
certificate.delete
certificate.deleted?
# => true

Actions

List actions

actions = HCloud::Certificate.find(1).actions
# => [#<HCloud::Action id: 1, ...>, ...]

Sort actions

HCloud::Certificate.find(1).actions.sort(finished: :desc)
# => [#<HCloud::Action id: 1, ...>, ...]

HCloud::Certificate.find(1).actions.sort(:command, finished: :asc)
# => [#<HCloud::Actions id: 1, ...>, ...]

Search actions

HCloud::Certificate.find(1).actions.where(command: "set_rules")
# => #<HCloud::Action id: 1, ...>

HCloud::Certificate.find(1).actions.where(status: "success")
# => #<HCloud::Action id: 1, ...>

Find action by ID

HCloud::Certificate.find(1).actions.find(1)
# => #<HCloud::Action id: 1, ...>

Resource-specific actions

Retry issuance or renewal

certificate = HCloud::Certificate.find(1)

certificate.retry
# => #<HCloud::Action ...>

Instance Method Summary collapse

Methods inherited from Resource

#==, attribute, client, #initialize, #inspect, resource_name, #to_h

Constructor Details

This class inherits a constructor from HCloud::Resource

Instance Method Details

#creatable_attributesObject



125
126
127
# File 'lib/hcloud/resources/certificate.rb', line 125

def creatable_attributes
  [:name, :labels, :type, :private_key, :certificate, :domain_names]
end

#updatable_attributesObject



129
130
131
# File 'lib/hcloud/resources/certificate.rb', line 129

def updatable_attributes
  [:name, :labels]
end