summaryrefslogtreecommitdiff
path: root/lib/google_api
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-09-25 16:10:25 +0900
committerShinya Maeda <shinya@gitlab.com>2017-09-25 16:10:25 +0900
commitd4fa672c20657a1c7d2fcfa25e9798e7ccdbf39d (patch)
tree416f477c9f574116d74cbf6687b7b18a09f550d5 /lib/google_api
parente2b195b2748c88e276163d44cdeff5b210f2522c (diff)
downloadgitlab-ce-d4fa672c20657a1c7d2fcfa25e9798e7ccdbf39d.tar.gz
Create Kubernetes cluster on GKE from k8s service
Diffstat (limited to 'lib/google_api')
-rw-r--r--lib/google_api/authentication.rb51
-rw-r--r--lib/google_api/cloud_platform/client.rb24
2 files changed, 75 insertions, 0 deletions
diff --git a/lib/google_api/authentication.rb b/lib/google_api/authentication.rb
new file mode 100644
index 00000000000..d7b473525fb
--- /dev/null
+++ b/lib/google_api/authentication.rb
@@ -0,0 +1,51 @@
+module GoogleApi
+ class Authentication
+ attr_reader :access_token, :redirect_uri, :state
+
+ def initialize(access_token, redirect_uri, state: nil)
+ @access_token = access_token
+ @redirect_uri = redirect_uri
+ @state = state
+ end
+
+ def client
+ return @client if defined?(@client)
+
+ unless config
+ raise 'OAuth configuration for google_oauth2 missing.'
+ end
+
+ @client = ::OAuth2::Client.new(
+ config.app_id,
+ config.app_secret,
+ site: 'https://accounts.google.com',
+ token_url: '/o/oauth2/token',
+ authorize_url: '/o/oauth2/auth'
+ )
+ end
+
+ def authorize_url
+ client.auth_code.authorize_url(
+ redirect_uri: redirect_uri,
+ scope: scope,
+ state: state # This is used for arbitary redirection
+ )
+ end
+
+ def get_token(code)
+ client.auth_code.get_token(code, redirect_uri: redirect_uri).token
+ end
+
+ protected
+
+ def scope
+ raise NotImplementedError
+ end
+
+ private
+
+ def config
+ Gitlab.config.omniauth.providers.find { |provider| provider.name == "google_oauth2" }
+ end
+ end
+end
diff --git a/lib/google_api/cloud_platform/client.rb b/lib/google_api/cloud_platform/client.rb
new file mode 100644
index 00000000000..2c2aefc542c
--- /dev/null
+++ b/lib/google_api/cloud_platform/client.rb
@@ -0,0 +1,24 @@
+module GoogleApi
+ module CloudPlatform
+ class Client < GoogleApi::Authentication
+ # Google::Apis::ContainerV1::ContainerService.new
+ def scope
+ 'https://www.googleapis.com/auth/cloud-platform'
+ end
+
+ def projects_zones_clusters_get
+ # TODO:
+ # service = Google::Apis::ContainerV1::ContainerService.new
+ # service.authorization = access_token
+ # project_id = params['project_id']
+ # ...
+ # response = service.list_zone_clusters(project_id, zone)
+ response
+ end
+
+ def projects_zones_clusters_create
+ # TODO
+ end
+ end
+ end
+end