Class: Train::Transports::Gcp::Connection
- Inherits:
-
BaseConnection
- Object
- BaseConnection
- Train::Transports::Gcp::Connection
- Defined in:
- lib/train/transports/gcp.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #gcp_admin_client ⇒ Object
-
#gcp_client(klass) ⇒ Object
Let’s allow for other clients too.
-
#gcp_compute_client ⇒ Object
Instantiate some named classes for ease of use.
- #gcp_iam_client ⇒ Object
- #gcp_project_client ⇒ Object
- #gcp_storage_client ⇒ Object
-
#initialize(options) ⇒ Connection
constructor
A new instance of Connection.
- #platform ⇒ Object
- #unique_identifier ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(options) ⇒ Connection
Returns a new instance of Connection.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/train/transports/gcp.rb', line 37 def initialize() super() # additional GCP platform metadata # The google-apis-core dependency is the common for all gcp service related gems. release = Gem.loaded_specs["google-apis-core"].version @platform_details = { release: "google-apis-core-v#{release}" } # Initialize the client object cache @cache_enabled[:api_call] = true @cache[:api_call] = {} connect end |
Instance Method Details
#connect ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/train/transports/gcp.rb', line 90 def connect ENV["GOOGLE_APPLICATION_CREDENTIALS"] = @options[:google_application_credentials] if @options[:google_application_credentials] ENV["GOOGLE_CLOUD_PROJECT"] = @options[:google_cloud_project] if @options[:google_cloud_project] # GCP initialization scopes = ["https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/compute"] = Google::Auth.get_application_default(scopes) Google::Apis::ClientOptions.default.application_name = "chef-inspec-train" Google::Apis::ClientOptions.default.application_version = Train::VERSION Google::Apis::RequestOptions.default. = end |
#gcp_admin_client ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/train/transports/gcp.rb', line 73 def gcp_admin_client scopes = ["https://www.googleapis.com/auth/admin.directory.user.readonly"] = Google::Auth.get_application_default(scopes).dup # Use of the Admin API requires delegation (impersonation). An email address of a Super Admin in # the G Suite account may be required. .sub = @options[:google_super_admin_email] if @options[:google_super_admin_email] Google::Apis::RequestOptions.default. = gcp_client(Google::Apis::AdminDirectoryV1::DirectoryService) end |
#gcp_client(klass) ⇒ Object
Let’s allow for other clients too
84 85 86 87 88 |
# File 'lib/train/transports/gcp.rb', line 84 def gcp_client(klass) return klass.new unless cache_enabled?(:api_call) @cache[:api_call][klass.to_s.to_sym] ||= klass.new end |
#gcp_compute_client ⇒ Object
Instantiate some named classes for ease of use
57 58 59 |
# File 'lib/train/transports/gcp.rb', line 57 def gcp_compute_client gcp_client(Google::Apis::ComputeV1::ComputeService) end |
#gcp_iam_client ⇒ Object
61 62 63 |
# File 'lib/train/transports/gcp.rb', line 61 def gcp_iam_client gcp_client(Google::Apis::IamV1::IamService) end |
#gcp_project_client ⇒ Object
65 66 67 |
# File 'lib/train/transports/gcp.rb', line 65 def gcp_project_client gcp_client(Google::Apis::CloudresourcemanagerV1::CloudResourceManagerService) end |
#gcp_storage_client ⇒ Object
69 70 71 |
# File 'lib/train/transports/gcp.rb', line 69 def gcp_storage_client gcp_client(Google::Apis::StorageV1::StorageService) end |
#platform ⇒ Object
52 53 54 |
# File 'lib/train/transports/gcp.rb', line 52 def platform force_platform!("gcp", @platform_details) end |
#unique_identifier ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/train/transports/gcp.rb', line 106 def unique_identifier unique_id = "default" # use auth client_id for users (issuer is nil) = gcp_iam_client.. unique_id = .client_id if .respond_to?(:client_id) && !.client_id.nil? # for service account credentials (client_id is nil) unique_id = .issuer if .respond_to?(:issuer) && !.issuer.nil? unique_id end |
#uri ⇒ Object
102 103 104 |
# File 'lib/train/transports/gcp.rb', line 102 def uri "gcp://#{unique_identifier}" end |