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)


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

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

#keyObject



62
63
64
# File 'lib/puma/acme/structs.rb', line 62

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

#namesObject



66
67
68
# File 'lib/puma/acme/structs.rb', line 66

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

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

Returns:

  • (Boolean)


78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/puma/acme/structs.rb', line 78

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)


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

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