diff --git a/lib/uffizzi/auth_helper.rb b/lib/uffizzi/auth_helper.rb index b35e1fe9..37204b55 100644 --- a/lib/uffizzi/auth_helper.rb +++ b/lib/uffizzi/auth_helper.rb @@ -16,7 +16,7 @@ def sign_out Uffizzi::Token.delete if Uffizzi::Token.exists? end - def check_login(project_option) + def check_login(project_option = nil) raise Uffizzi::Error.new('You are not logged in. Run `uffizzi login`.') unless signed_in? raise Uffizzi::Error.new('This command needs project to be set in config file') unless project_set?(project_option) end diff --git a/lib/uffizzi/cli/cluster.rb b/lib/uffizzi/cli/cluster.rb index 27d8f473..07d78ba9 100644 --- a/lib/uffizzi/cli/cluster.rb +++ b/lib/uffizzi/cli/cluster.rb @@ -76,7 +76,6 @@ def wake(name = nil) def run(command, command_args = {}) Uffizzi.ui.output_format = options[:output] Uffizzi::AuthHelper.check_login(options[:project]) - project_slug = options[:project].nil? ? ConfigFile.read_option(:project) : options[:project] case command when 'list' @@ -124,16 +123,13 @@ def handle_create_command(command_args) end cluster_name = command_args[:name] || options[:name] || ClusterService.generate_name - creation_source = options[:"creation-source"] || ClusterService::MANUAL_CREATION_SOURCE - k8s_version = options[:"k8s-version"] Uffizzi.ui.say_error_and_exit("Cluster name: #{cluster_name} is not valid.") unless ClusterService.valid_name?(cluster_name) unless ClusterService.valid_name?(cluster_name) Uffizzi.ui.say_error_and_exit("Cluster name: #{cluster_name} is not valid.") end - manifest_file_path = options[:manifest] - params = cluster_creation_params(cluster_name, creation_source, manifest_file_path) + params = cluster_creation_params(cluster_name) response = create_cluster(server, project_slug, params) return ResponseHelper.handle_failed_response(response) unless ResponseHelper.created?(response) @@ -211,7 +207,8 @@ def handle_delete_cluster(cluster_name) def handle_update_kubeconfig_command(command_args) kubeconfig_path = options[:kubeconfig] || KubeconfigService.default_path - cluster_data = ClusterService.fetch_cluster_data(command_args[:cluster_name], **cluster_api_connection_params) + cluster_name = command_args[:cluster_name] + cluster_data = ClusterService.fetch_cluster_data(cluster_name, **cluster_api_connection_params) unless cluster_data[:kubeconfig].present? say_error_update_kubeconfig(cluster_data) @@ -289,11 +286,15 @@ def say_error_update_kubeconfig(cluster_data) end end - def cluster_creation_params(name:, creation_source:, manifest_file_path:, k8s_version:) + def cluster_creation_params(cluster_name) + creation_source = options[:"creation-source"] || ClusterService::MANUAL_CREATION_SOURCE + manifest_file_path = options[:manifest] + k8s_version = options[:"k8s-version"] manifest_content = load_manifest_file(manifest_file_path) + { cluster: { - name: name, + name: cluster_name, manifest: manifest_content, creation_source: creation_source, k8s_version: k8s_version, @@ -438,7 +439,7 @@ def oidc_token end def project_slug - @project_slug ||= ConfigFile.read_option(:project) + @project_slug ||= options[:project].nil? ? ConfigFile.read_option(:project) : options[:project] end def server diff --git a/lib/uffizzi/cli/dev.rb b/lib/uffizzi/cli/dev.rb index 663f465e..e195bf57 100644 --- a/lib/uffizzi/cli/dev.rb +++ b/lib/uffizzi/cli/dev.rb @@ -15,7 +15,7 @@ class Cli::Dev < Thor method_option :kubeconfig, type: :string method_option :'k8s-version', required: false, type: :string def start(config_path = 'skaffold.yaml') - Uffizzi::AuthHelper.check_login(options[:project]) + Uffizzi::AuthHelper.check_login DevService.check_skaffold_existence DevService.check_running_daemon if options[:quiet] DevService.check_skaffold_config_existence(config_path) @@ -52,7 +52,7 @@ def stop desc 'describe [NAME]', 'Describe dev environment' def describe(name = nil) - check_login + Uffizzi::AuthHelper.check_login dev_environment = get_dev_environment(name) if dev_environment.nil? @@ -71,11 +71,7 @@ def describe(name = nil) private def start_create_cluster - params = cluster_creation_params( - name: ClusterService.generate_name, - creation_source: ClusterService::MANUAL_CREATION_SOURCE, - k8s_version: options[:"k8s-version"], - ) + params = cluster_creation_params Uffizzi.ui.say('Start creating a cluster') response = create_cluster(server, project_slug, params) return ResponseHelper.handle_failed_response(response) unless ResponseHelper.created?(response) @@ -129,13 +125,13 @@ def update_clusters_config(id, params) ConfigFile.write_option(:clusters, clusters_config) end - def cluster_creation_params(name, creation_source) + def cluster_creation_params { cluster: { - name: name, + name: ClusterService.generate_name, manifest: nil, - creation_source: creation_source, - k8s_version: k8s_version, + creation_source: ClusterService::MANUAL_CREATION_SOURCE, + k8s_version: options[:"k8s-version"], }, token: oidc_token, }