Class: Puma::Acme::Cert

Inherits:
Struct
  • Object
show all
Defined in:
lib/puma/acme/structs.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifiers: nil, **kwargs) ⇒ Cert

Returns a new instance of Cert.



56
57
58
59
60
# File 'lib/puma/acme/structs.rb', line 56

def initialize(identifiers: nil, **kwargs)
  identifiers = identifiers&.map { |value| Identifier.parse(value) }

  super(identifiers: identifiers, **kwargs)
end

Instance Attribute Details

#algorithmObject

Returns the value of attribute algorithm

Returns:

  • (Object)

    the current value of algorithm



51
52
53
# File 'lib/puma/acme/structs.rb', line 51

def algorithm
  @algorithm
end

#cert_pemObject

Returns the value of attribute cert_pem

Returns:

  • (Object)

    the current value of cert_pem



51
52
53
# File 'lib/puma/acme/structs.rb', line 51

def cert_pem
  @cert_pem
end

#identifiersObject

Returns the value of attribute identifiers

Returns:

  • (Object)

    the current value of identifiers



51
52
53
# File 'lib/puma/acme/structs.rb', line 51

def identifiers
  @identifiers
end

#key_pemObject

Returns the value of attribute key_pem

Returns:

  • (Object)

    the current value of key_pem



51
52
53
# File 'lib/puma/acme/structs.rb', line 51

def key_pem
  @key_pem
end

#orderObject

Returns the value of attribute order

Returns:

  • (Object)

    the current value of order



51
52
53
# File 'lib/puma/acme/structs.rb', line 51

def order
  @order
end

Class Method Details

.key(algorithm:, identifiers:) ⇒ Object



52
53
54
# File 'lib/puma/acme/structs.rb', line 52

def self.key(algorithm:, identifiers:)
  new(algorithm: algorithm, identifiers: identifiers).key
end

Instance Method Details

#expired?(now: Time.now.utc) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/puma/acme/structs.rb', line 77

def expired?(now: Time.now.utc)
  x509.not_after < now
end

#keyObject



69
70
71
# File 'lib/puma/acme/structs.rb', line 69

def key
  [:cert, algorithm, identifiers&.map(&:key)]
end

#namesObject



73
74
75
# File 'lib/puma/acme/structs.rb', line 73

def names
  identifiers&.map(&:value)
end

#renewable?(renew_in, now: Time.now.utc) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/puma/acme/structs.rb', line 85

def renewable?(renew_in, now: Time.now.utc)
  case renew_in
  when Float
    renew_at = x509.not_before + (x509.not_after - x509.not_before) * renew_in
  when Integer
    renew_at = x509.not_before + renew_in
  else
    raise UnknownRenewIn, renew_in
  end

  now >= renew_at
end

#usable?(now: Time.now.utc) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/puma/acme/structs.rb', line 81

def usable?(now: Time.now.utc)
  !cert_pem.nil? && !key_pem.nil? && !expired?(now: now)
end