Commit 250a8aee authored by Dennis Tang's avatar Dennis Tang

revisions

parent 1b40d324
class Projects::ClustersController < Projects::ApplicationController class Projects::ClustersController < Projects::ApplicationController
before_action :cluster, except: [:index, :new, :create_cluster] before_action :cluster, except: [:index, :new, :create]
before_action :authorize_read_cluster! before_action :authorize_read_cluster!
before_action :generate_gcp_authorize_url, only: [:new]
before_action :new_cluster, only: [:new]
before_action :existing_cluster, only: [:new]
before_action :authorize_create_cluster!, only: [:new] before_action :authorize_create_cluster!, only: [:new]
before_action :authorize_update_cluster!, only: [:update] before_action :authorize_update_cluster!, only: [:update]
before_action :authorize_admin_cluster!, only: [:destroy] before_action :authorize_admin_cluster!, only: [:destroy]
...@@ -14,9 +17,6 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -14,9 +17,6 @@ class Projects::ClustersController < Projects::ApplicationController
end end
def new def new
generate_gcp_authorize_url
tap_new_cluster
tap_existing_cluster
end end
def status def status
...@@ -67,22 +67,7 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -67,22 +67,7 @@ class Projects::ClustersController < Projects::ApplicationController
end end
end end
def tap_new_cluster def create
if GoogleApi::CloudPlatform::Client.new(token_in_session, nil)
.validate_token(expires_at_in_session)
@new_cluster = ::Clusters::Cluster.new.tap do |cluster|
cluster.build_provider_gcp
end
end
end
def tap_existing_cluster
@existing_cluster = ::Clusters::Cluster.new.tap do |cluster|
cluster.build_platform_kubernetes
end
end
def create_cluster
case params[:type] case params[:type]
when 'new' when 'new'
cluster_params = create_new_cluster_params cluster_params = create_new_cluster_params
...@@ -120,19 +105,6 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -120,19 +105,6 @@ class Projects::ClustersController < Projects::ApplicationController
.present(current_user: current_user) .present(current_user: current_user)
end end
def create_params
params.require(:cluster).permit(
:enabled,
:name,
:provider_type,
provider_gcp_attributes: [
:gcp_project_id,
:zone,
:num_nodes,
:machine_type
])
end
def update_params def update_params
if cluster.managed? if cluster.managed?
params.require(:cluster).permit( params.require(:cluster).permit(
...@@ -199,6 +171,21 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -199,6 +171,21 @@ class Projects::ClustersController < Projects::ApplicationController
# no-op # no-op
end end
def new_cluster
if GoogleApi::CloudPlatform::Client.new(token_in_session, nil)
.validate_token(expires_at_in_session)
@new_cluster = ::Clusters::Cluster.new.tap do |cluster|
cluster.build_provider_gcp
end
end
end
def existing_cluster
@existing_cluster = ::Clusters::Cluster.new.tap do |cluster|
cluster.build_platform_kubernetes
end
end
def token_in_session def token_in_session
@token_in_session ||= @token_in_session ||=
session[GoogleApi::CloudPlatform::Client.session_key_for_token] session[GoogleApi::CloudPlatform::Client.session_key_for_token]
......
...@@ -206,7 +206,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -206,7 +206,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
resources :clusters, except: [:edit, :create] do resources :clusters, except: [:edit, :create] do
collection do collection do
post '/new', to: 'clusters#create_cluster' post '/new', to: 'clusters#create'
end end
member do member do
......
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