Sha256: 7f65328b25862c07734c62bea5dd7946012d93e359c0ab184db661d60690a3bb

Contents?: true

Size: 1.64 KB

Versions: 10

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

class Acme::Client::Resources::Authorization
  attr_reader :url, :identifier, :domain, :expires, :status, :wildcard

  def initialize(client, **arguments)
    @client = client
    assign_attributes(**arguments)
  end

  def deactivate
    assign_attributes(**@client.deactivate_authorization(url: url).to_h)
    true
  end

  def reload
    assign_attributes(**@client.authorization(url: url).to_h)
    true
  end

  def challenges
    @challenges.map do |challenge|
      initialize_challenge(challenge)
    end
  end

  def http01
    @http01 ||= challenges.find { |challenge|
      challenge.is_a?(Acme::Client::Resources::Challenges::HTTP01)
    }
  end
  alias_method :http, :http01

  def dns01
    @dns01 ||= challenges.find { |challenge|
      challenge.is_a?(Acme::Client::Resources::Challenges::DNS01)
    }
  end
  alias_method :dns, :dns01

  def to_h
    {
      url: url,
      identifier: identifier,
      status: status,
      expires: expires,
      challenges: @challenges,
      wildcard: wildcard
    }
  end

  private

  def initialize_challenge(attributes)
    arguments = {
      type: attributes.fetch('type'),
      status: attributes.fetch('status'),
      url: attributes.fetch('url'),
      token: attributes.fetch('token'),
      error: attributes['error']
    }
    Acme::Client::Resources::Challenges.new(@client, **arguments)
  end

  def assign_attributes(url:, status:, expires:, challenges:, identifier:, wildcard: false)
    @url = url
    @identifier = identifier
    @domain = identifier.fetch('value')
    @status = status
    @expires = expires
    @challenges = challenges
    @wildcard = wildcard
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
acme-client-2.0.16 lib/acme/client/resources/authorization.rb
acme-client-2.0.15 lib/acme/client/resources/authorization.rb
acme-client-2.0.14 lib/acme/client/resources/authorization.rb
acme-client-2.0.13 lib/acme/client/resources/authorization.rb
acme-client-2.0.12 lib/acme/client/resources/authorization.rb
acme-client-2.0.11 lib/acme/client/resources/authorization.rb
acme-client-2.0.10 lib/acme/client/resources/authorization.rb
acme-client-2.0.9 lib/acme/client/resources/authorization.rb
acme-client-2.0.8 lib/acme/client/resources/authorization.rb
acme-client-2.0.7 lib/acme/client/resources/authorization.rb