Class: GoogleApi::CloudPlatform::Client

Inherits:
Auth
  • Object
show all
Defined in:
lib/google_api/cloud_platform/client.rb

Constant Summary collapse

SCOPE =
'https://www.googleapis.com/auth/cloud-platform'
LEAST_TOKEN_LIFE_TIME =
10.minutes
CLUSTER_MASTER_AUTH_USERNAME =
'admin'
CLUSTER_IPV4_CIDR_BLOCK =
'/16'
CLUSTER_OAUTH_SCOPES =
[
  "https://www.googleapis.com/auth/devstorage.read_only",
  "https://www.googleapis.com/auth/logging.write",
  "https://www.googleapis.com/auth/monitoring"
].freeze

Constants inherited from Auth

Auth::ConfigMissingError

Instance Attribute Summary

Attributes inherited from Auth

#access_token, #redirect_uri, #state

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Auth

#authorize_url, #get_token, #initialize

Constructor Details

This class inherits a constructor from GoogleApi::Auth

Class Method Details

.new_session_key_for_redirect_uriObject


31
32
33
34
35
# File 'lib/google_api/cloud_platform/client.rb', line 31

def new_session_key_for_redirect_uri
  SecureRandom.hex.tap do |state|
    yield session_key_for_redirect_uri(state)
  end
end

.session_key_for_expires_atObject


27
28
29
# File 'lib/google_api/cloud_platform/client.rb', line 27

def session_key_for_expires_at
  :cloud_platform_expires_at
end

.session_key_for_redirect_uri(state) ⇒ Object


37
38
39
# File 'lib/google_api/cloud_platform/client.rb', line 37

def session_key_for_redirect_uri(state)
  "cloud_platform_second_redirect_uri_#{state}"
end

.session_key_for_tokenObject


23
24
25
# File 'lib/google_api/cloud_platform/client.rb', line 23

def session_key_for_token
  :cloud_platform_access_token
end

Instance Method Details

#parse_operation_id(self_link) ⇒ Object


81
82
83
84
# File 'lib/google_api/cloud_platform/client.rb', line 81

def parse_operation_id(self_link)
  m = self_link.match(%r{projects/.*/zones/.*/operations/(.*)})
  m[1] if m
end

#projects_zones_clusters_create(project_id, zone, cluster_name, cluster_size, machine_type:, legacy_abac:, enable_addons: []) ⇒ Object


63
64
65
66
67
68
69
70
71
72
# File 'lib/google_api/cloud_platform/client.rb', line 63

def projects_zones_clusters_create(project_id, zone, cluster_name, cluster_size, machine_type:, legacy_abac:, enable_addons: [])
  service = Google::Apis::ContainerV1beta1::ContainerService.new
  service.authorization = access_token

  cluster_options = make_cluster_options(cluster_name, cluster_size, machine_type, legacy_abac, enable_addons)

  request_body = Google::Apis::ContainerV1beta1::CreateClusterRequest.new(cluster_options)

  service.create_cluster(project_id, zone, request_body, options: user_agent_header)
end

#projects_zones_clusters_get(project_id, zone, cluster_id) ⇒ Object


56
57
58
59
60
61
# File 'lib/google_api/cloud_platform/client.rb', line 56

def projects_zones_clusters_get(project_id, zone, cluster_id)
  service = Google::Apis::ContainerV1::ContainerService.new
  service.authorization = access_token

  service.get_zone_cluster(project_id, zone, cluster_id, options: user_agent_header)
end

#projects_zones_operations(project_id, zone, operation_id) ⇒ Object


74
75
76
77
78
79
# File 'lib/google_api/cloud_platform/client.rb', line 74

def projects_zones_operations(project_id, zone, operation_id)
  service = Google::Apis::ContainerV1::ContainerService.new
  service.authorization = access_token

  service.get_zone_operation(project_id, zone, operation_id, options: user_agent_header)
end

#scopeObject


42
43
44
# File 'lib/google_api/cloud_platform/client.rb', line 42

def scope
  SCOPE
end

#validate_token(expires_at) ⇒ Object


46
47
48
49
50
51
52
53
54
# File 'lib/google_api/cloud_platform/client.rb', line 46

def validate_token(expires_at)
  return false unless access_token
  return false unless expires_at

  # Making sure that the token will have been still alive during the cluster creation.
  return false if token_life_time(expires_at) < LEAST_TOKEN_LIFE_TIME

  true
end