Sha256: 62998d5452a461ff5e757a2f31c8c6f6ccd772ded88101c5207fcefcf8041552

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

# 
# Copyright 2019 Ken Spencer / IotaSpencer
#
# 
# File: ${FILENAME}
# Created: 3/14/19
#
# License is in project root, MIT License is in use.
require 'cloudflare_client'
require 'configparser'
require 'pathname'
require 'public_suffix'

module Certflare
  class CleanUp
    def initialize
    @configs_dir = Pathname.new('/etc/')
    @cfg = YAML.load_file(@configs_dir.join('certflare'))
    @api_key = @cfg['api_key']
    @email = @cfg['email']
    @client = CloudflareClient::Zone.new(auth_key: @api_key, email: @email)
    end
    def get_certbot_vars
      @domain = ENV['CERTBOT_DOMAIN']
      @validation = ENV['CERTBOT_VALIDATION']
    end
    def get_domain
      domain = ENV['CERTBOT_DOMAIN']
      @full_domain = domain
      @main_domain = PublicSuffix.domain(domain)
    end
    def remove_zone_id
      @domain_dir = Pathname.new("/tmp").join("certflare", "CERTBOT_#{@domain}")
      if @domain_dir.join('ZONE_ID').exist?
        @zone_id = File.read(@domain_dir.join('ZONE_ID').to_s)
        File.delete(@domain_dir.join('ZONE_ID').to_s)
      end
    end
    def remove_record_id
      if @domain_dir.join('RECORD_ID').exist?
        @record_id = File.read(@domain_dir.join('RECORD_ID').to_s)
        File.delete(@domain_dir.join('RECORD_ID').to_s)
      end
    end
    def remove_txt_record
      unless (defined?(@zone_id)).nil?
        unless (defined?(@record_id)).nil?
          zone = CloudflareClient::Zone::DNS.new(auth_key: @api_key, email: @email, zone_id: @zone_id)
          zone.delete(id: @record_id)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
certflare-0.1.10 lib/certflare/common/cleanup.rb