Class: GoogleSslCert::CLI::Create

Inherits:
Base
  • Object
show all
Defined in:
lib/google_ssl_cert/cli/create.rb

Instance Method Summary collapse

Methods included from Logging

#logger

Methods included from Helpers::Global

#global?

Methods included from GoogleServices

#region_ssl_certificates, #resource_manager, #secret_manager_service, #ssl_certificates

Constructor Details

#initialize(options = {}) ⇒ Create

Returns a new instance of Create.



3
4
5
6
7
# File 'lib/google_ssl_cert/cli/create.rb', line 3

def initialize(options={})
  super
  @cert_name = GoogleSslCert::Name.new(@options)
  @secret_name  = @options[:secret_name] || @cert_name.base_name
end

Instance Method Details

#create_certObject

Google API Docs:

https://cloud.google.com/compute/docs/reference/rest/v1/sslCertificates/insert


17
18
19
# File 'lib/google_ssl_cert/cli/create.rb', line 17

def create_cert
  GoogleSslCert::Cert.new(@options.merge(cert_name: @cert_name.generated_name)).create
end

#runObject



9
10
11
12
13
# File 'lib/google_ssl_cert/cli/create.rb', line 9

def run
  validate!
  create_cert
  save_secret if @options[:save_secret]
end

#save_secretObject

The secret name is expected to be static/predictable The secret value is the changed/updated google ssl cert

Example:

secret_name  = demo_ssl-cert-name
secret_value = google-ssl-cert-20211013231005

gcloud compute ssl-certificates list
NAME                            TYPE          CREATION_TIMESTAMP             EXPIRE_TIME                    MANAGED_STATUS
google-ssl-cert-20211013231005  SELF_MANAGED  2021-10-13T16:10:05.795-07:00  2022-10-12T17:22:01.000-07:00
gcloud secrets list
NAME                CREATED              REPLICATION_POLICY  LOCATIONS
demo_ssl-cert-name  2021-10-13T23:10:06  automatic


35
36
37
38
# File 'lib/google_ssl_cert/cli/create.rb', line 35

def save_secret
  secret_value = @cert_name.generated_name # @cert_name the value because it will be referenced. the @cert_name or 'key' will be the same
  secret.save(@secret_name, secret_value)
end

#secretObject



40
41
42
# File 'lib/google_ssl_cert/cli/create.rb', line 40

def secret
  GoogleSslCert::Secret.new(@options)
end