Module: Google::Iam

Defined in:
lib/google/iam.rb,
lib/google/iam/client/version.rb

Defined Under Namespace

Modules: Client

Class Method Summary collapse

Class Method Details

.policies(version: :v2, transport: :grpc, &block) ⇒ ::Object

Create a new client object for Policies.

By default, this returns an instance of Google::Iam::V2::Policies::Client for a gRPC client for version V2 of the API. However, you can specify a different API version by passing it in the version parameter. If the Policies service is supported by that API version, and the corresponding gem is available, the appropriate versioned client will be returned. You can also specify a different transport by passing :rest or :grpc in the transport parameter.

Raises an exception if the currently installed versioned client gem for the given API version does not support the given transport of the Policies service. You can determine whether the method will succeed by calling policies_available?.

About Policies

An interface for managing Identity and Access Management (IAM) policies.

Parameters:

  • version (::String, ::Symbol) (defaults to: :v2)

    The API version to connect to. Optional. Defaults to :v2.

  • transport (:grpc, :rest) (defaults to: :grpc)

    The transport to use. Defaults to :grpc.

Returns:

  • (::Object)

    A client object for the specified version.



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/google/iam.rb', line 56

def self.policies version: :v2, transport: :grpc, &block
  require "google/iam/#{version.to_s.downcase}"

  package_name = Google::Iam
                 .constants
                 .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
                 .first
  service_module = Google::Iam.const_get(package_name).const_get(:Policies)
  service_module = service_module.const_get(:Rest) if transport == :rest
  service_module.const_get(:Client).new(&block)
end

.policies_available?(version: :v2, transport: :grpc) ⇒ boolean

Determines whether the Policies service is supported by the current client. If true, you can retrieve a client object by calling policies. If false, that method will raise an exception. This could happen if the given API version does not exist or does not support the Policies service, or if the versioned client gem needs an update to support the Policies service.

Parameters:

  • version (::String, ::Symbol) (defaults to: :v2)

    The API version to connect to. Optional. Defaults to :v2.

  • transport (:grpc, :rest) (defaults to: :grpc)

    The transport to use. Defaults to :grpc.

Returns:

  • (boolean)

    Whether the service is available.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/google/iam.rb', line 80

def self.policies_available? version: :v2, transport: :grpc
  require "google/iam/#{version.to_s.downcase}"
  package_name = Google::Iam
                 .constants
                 .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
                 .first
  return false unless package_name
  service_module = Google::Iam.const_get package_name
  return false unless service_module.const_defined? :Policies
  service_module = service_module.const_get :Policies
  if transport == :rest
    return false unless service_module.const_defined? :Rest
    service_module = service_module.const_get :Rest
  end
  service_module.const_defined? :Client
rescue ::LoadError
  false
end