-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
377 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
uffizzi-cli (2.2.2) | ||
uffizzi-cli (2.3.0) | ||
activesupport | ||
awesome_print | ||
faker | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'uffizzi' | ||
require 'uffizzi/auth_helper' | ||
require 'uffizzi/response_helper' | ||
|
||
module Uffizzi | ||
class Cli::Dev::Ingress < Thor | ||
include ApiClient | ||
|
||
desc 'open', 'Open dev environment hosts' | ||
def open | ||
Uffizzi::AuthHelper.check_login | ||
DevService.check_running_process! | ||
|
||
if DevService.startup? | ||
Uffizzi.ui.say_error_and_exit('Dev environment not started yet') | ||
end | ||
|
||
dev_environment = DevService.dev_environment | ||
cluster_name = dev_environment[:cluster_name] | ||
params = { cluster_name: cluster_name } | ||
response = get_cluster_ingresses(server, project_slug, params) | ||
|
||
return ResponseHelper.handle_failed_response(response) unless ResponseHelper.ok?(response) | ||
|
||
ingress_hosts = response.dig(:body, :ingresses) | ||
urls = ingress_hosts.map { |host| "https://#{host}" } | ||
urls.each { |url| Uffizzi.launchy.open(url) { Uffizzi.ui.say(url) } } | ||
end | ||
|
||
private | ||
|
||
def server | ||
@server ||= ConfigFile.read_option(:server) | ||
end | ||
|
||
def project_slug | ||
@project_slug ||= ConfigFile.read_option(:project) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'uffizzi/helpers/config_helper' | ||
|
||
class ClusterCommonService | ||
class << self | ||
def save_previous_current_context(kubeconfig_path, current_context) | ||
return if kubeconfig_path.nil? || Uffizzi::ConfigHelper.previous_current_context_by_path(kubeconfig_path).present? | ||
|
||
previous_current_contexts = Uffizzi::ConfigHelper.set_previous_current_context_by_path(kubeconfig_path, current_context) | ||
Uffizzi::ConfigFile.write_option(:previous_current_contexts, previous_current_contexts) | ||
end | ||
|
||
def update_clusters_config(id, params) | ||
clusters_config = Uffizzi::ConfigHelper.update_clusters_config_by_id(id, params) | ||
Uffizzi::ConfigFile.write_option(:clusters, clusters_config) | ||
end | ||
|
||
def parse_kubeconfig(kubeconfig) | ||
return if kubeconfig.nil? | ||
|
||
Psych.safe_load(Base64.decode64(kubeconfig)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'uffizzi/helpers/config_helper' | ||
require 'uffizzi/services/cluster/common_service' | ||
require 'uffizzi/services/kubeconfig_service' | ||
|
||
class ClusterCreateService | ||
class << self | ||
def save_kubeconfig(kubeconfig, kubeconfig_path, is_update_current_context) | ||
kubeconfig_path = kubeconfig_path.nil? ? KubeconfigService.default_path : kubeconfig_path | ||
KubeconfigService.save_to_filepath(kubeconfig_path, kubeconfig) do |kubeconfig_by_path| | ||
merged_kubeconfig = KubeconfigService.merge(kubeconfig_by_path, kubeconfig) | ||
|
||
if is_update_current_context | ||
new_current_context = KubeconfigService.get_current_context(kubeconfig) | ||
new_kubeconfig = KubeconfigService.update_current_context(merged_kubeconfig, new_current_context) | ||
|
||
next new_kubeconfig if kubeconfig_by_path.nil? | ||
|
||
previous_current_context = KubeconfigService.get_current_context(kubeconfig_by_path) | ||
ClusterCommonService.save_previous_current_context(kubeconfig_path, previous_current_context) | ||
new_kubeconfig | ||
else | ||
merged_kubeconfig | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'uffizzi/helpers/config_helper' | ||
require 'uffizzi/services/kubeconfig_service' | ||
|
||
class ClusterDeleteService | ||
class << self | ||
def exclude_kubeconfig(cluster_id, kubeconfig) | ||
cluster_config = Uffizzi::ConfigHelper.cluster_config_by_id(cluster_id) | ||
return if cluster_config.nil? | ||
|
||
kubeconfig_path = cluster_config[:kubeconfig_path] | ||
Uffizzi::ConfigFile.write_option(:clusters, Uffizzi::ConfigHelper.clusters_config_without(cluster_id)) | ||
|
||
KubeconfigService.save_to_filepath(kubeconfig_path, kubeconfig) do |kubeconfig_by_path| | ||
if kubeconfig_by_path.nil? | ||
msg = "Warning: kubeconfig at path #{kubeconfig_path} does not exist" | ||
return Uffizzi.ui.say(msg) | ||
end | ||
|
||
new_kubeconfig = KubeconfigService.exclude(kubeconfig_by_path, kubeconfig) | ||
first_context = KubeconfigService.get_first_context(new_kubeconfig) | ||
new_current_context = first_context.present? ? first_context['name'] : nil | ||
KubeconfigService.update_current_context(new_kubeconfig, new_current_context) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
class ClusterListService | ||
class << self | ||
# REFACTOR_ME: | ||
# Uffizzi.ui.output_format = Uffizzi::UI::Shell::PRETTY_LIST | ||
# Uffizzi.ui.say(data) | ||
def render_plain_clusters(clusters) | ||
clusters.map do |cluster| | ||
project_name = cluster.dig(:project, :name) | ||
|
||
if project_name.present? | ||
"- Cluster name: #{cluster[:name].strip} Project name: #{project_name.strip}" | ||
else | ||
"- #{cluster[:name]}" | ||
end | ||
end.join("\n") | ||
end | ||
end | ||
end |
Oops, something went wrong.