Commit b3cf1530 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add oauth reference to jupyter cluster app

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 4220e914
...@@ -6,7 +6,15 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll ...@@ -6,7 +6,15 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll
def create def create
application = @application_class.find_or_create_by!(cluster: @cluster) application = @application_class.find_or_create_by!(cluster: @cluster)
application.update(hostname: params[:hostname]) if application.respond_to?(:hostname)
if application.respond_to?(:hostname)
application.update(hostname: params[:hostname])
end
if application.respond_to?(:oauth_application)
application.oauth_application = create_oauth_application(application)
application.save
end
Clusters::Applications::ScheduleInstallationService.new(project, current_user).execute(application) Clusters::Applications::ScheduleInstallationService.new(project, current_user).execute(application)
...@@ -24,4 +32,15 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll ...@@ -24,4 +32,15 @@ class Projects::Clusters::ApplicationsController < Projects::ApplicationControll
def application_class def application_class
@application_class ||= Clusters::Cluster::APPLICATIONS[params[:application]] || render_404 @application_class ||= Clusters::Cluster::APPLICATIONS[params[:application]] || render_404
end end
def create_oauth_application(application)
oauth_application_params = {
name: params[:application],
redirect_uri: application.callback_url,
scopes: 'api read_user openid',
owner: current_user
}
Applications::CreateService.new(current_user, oauth_application_params).execute
end
end end
...@@ -9,6 +9,8 @@ module Clusters ...@@ -9,6 +9,8 @@ module Clusters
include ::Clusters::Concerns::ApplicationStatus include ::Clusters::Concerns::ApplicationStatus
include ::Clusters::Concerns::ApplicationData include ::Clusters::Concerns::ApplicationData
belongs_to :oauth_application, class_name: 'Doorkeeper::Application'
default_value_for :version, VERSION default_value_for :version, VERSION
def chart def chart
...@@ -32,16 +34,40 @@ module Clusters ...@@ -32,16 +34,40 @@ module Clusters
) )
end end
def callback_url
"http://#{hostname}/hub/oauth_callback"
end
private private
def specification def specification
{ {
"ingress" => { "hosts" => [hostname] }, "ingress" => {
"hub" => { "cookieSecret" => SecureRandom.hex(32) }, "hosts" => [hostname]
"proxy" => { "secretToken" => SecureRandom.hex(32) } },
"hub" => {
"extraEnv" => {
"GITLAB_HOST" => gitlab_url
},
"cookieSecret" => SecureRandom.hex(32)
},
"proxy" => {
"secretToken" => SecureRandom.hex(32)
},
"auth" => {
"gitlab" => {
"clientId" => oauth_application.uid,
"clientSecret" => oauth_application.secret,
"callbackUrl" => callback_url
}
}
} }
end end
def gitlab_url
Gitlab.config.gitlab.url
end
def content_values def content_values
YAML.load_file(chart_values_file).deep_merge!(specification) YAML.load_file(chart_values_file).deep_merge!(specification)
end end
......
...@@ -9,6 +9,7 @@ class CreateClustersApplicationsJupyter < ActiveRecord::Migration ...@@ -9,6 +9,7 @@ class CreateClustersApplicationsJupyter < ActiveRecord::Migration
def change def change
create_table :clusters_applications_jupyters do |t| create_table :clusters_applications_jupyters do |t|
t.references :cluster, null: false, unique: true, foreign_key: { on_delete: :cascade } t.references :cluster, null: false, unique: true, foreign_key: { on_delete: :cascade }
t.references :oauth_application
t.integer :status, null: false t.integer :status, null: false
t.string :version, null: false t.string :version, null: false
......
...@@ -637,6 +637,7 @@ ActiveRecord::Schema.define(version: 20180521171529) do ...@@ -637,6 +637,7 @@ ActiveRecord::Schema.define(version: 20180521171529) do
create_table "clusters_applications_jupyters", force: :cascade do |t| create_table "clusters_applications_jupyters", force: :cascade do |t|
t.integer "cluster_id", null: false t.integer "cluster_id", null: false
t.integer "oauth_application_id"
t.integer "status", null: false t.integer "status", null: false
t.string "version", null: false t.string "version", null: false
t.string "hostname" t.string "hostname"
......
...@@ -7,6 +7,9 @@ hub: ...@@ -7,6 +7,9 @@ hub:
extraConfig: | extraConfig: |
c.KubeSpawner.cmd = ['jupyter-labhub'] c.KubeSpawner.cmd = ['jupyter-labhub']
auth:
type: gitlab
singleuser: singleuser:
defaultUrl: "/lab" defaultUrl: "/lab"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment