Skip to content

Commit

Permalink
[343] Fix after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
zipofar committed Oct 16, 2023
1 parent 301cdcc commit ca9415d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/uffizzi/auth_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions lib/uffizzi/cli/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def disconnect
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'
Expand Down Expand Up @@ -110,16 +109,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)
Expand Down Expand Up @@ -240,11 +236,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,
Expand Down Expand Up @@ -381,7 +381,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
Expand Down
18 changes: 7 additions & 11 deletions lib/uffizzi/cli/dev.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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?
Expand All @@ -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)
Expand Down Expand Up @@ -128,13 +124,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,
}
Expand Down

0 comments on commit ca9415d

Please sign in to comment.