From 0222b06aecf4011e5e397d0d1faea8367bf2b866 Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Tue, 17 Jan 2023 00:18:09 +0800 Subject: [PATCH 01/18] Refactor environment_variables directory structure --- lib/ey-core/cli/environment_variables.rb | 65 +------------- lib/ey-core/cli/environment_variables/list.rb | 90 +++++++++++++++++++ lib/ey-core/cli/environment_variables/main.rb | 23 +++++ lib/ey-core/cli/main.rb | 2 +- lib/ey-core/version.rb | 2 +- 5 files changed, 117 insertions(+), 65 deletions(-) create mode 100644 lib/ey-core/cli/environment_variables/list.rb create mode 100644 lib/ey-core/cli/environment_variables/main.rb diff --git a/lib/ey-core/cli/environment_variables.rb b/lib/ey-core/cli/environment_variables.rb index 940f83a..3df8a75 100644 --- a/lib/ey-core/cli/environment_variables.rb +++ b/lib/ey-core/cli/environment_variables.rb @@ -1,70 +1,9 @@ -require 'ey-core/cli/subcommand' -require 'ey-core/cli/helpers/stream_printer' +require_relative "environment_variables/main" module Ey module Core module Cli - class EnvironmentVariables < Subcommand - MASK = '****'.freeze - SYMBOLS_TO_DISPLAY = 4 - MAX_LENGTH_TO_DISPLAY = 30 - - include Ey::Core::Cli::Helpers::StreamPrinter - - title "environment_variables" - summary "Retrieve a list of Engine Yard environment variables for environments that you have access to." - - option :environment, - short: 'e', - long: 'environment', - description: 'Filter by environmeent name or id', - argument: 'Environment' - - option :application, - short: 'a', - long: 'application', - description: 'Filter by application name or id', - argument: 'Application' - - switch :display_sensitive, - short: 's', - long: 'display_sensitive', - description: 'Determines whether values of sensitive variables should be printed', - argument: 'Display Sensitive' - - def handle - environment_variables = if option(:application) - core_applications(option(:application)).flat_map(&:environment_variables) - elsif option(:environment) - core_environments(option(:environment)).flat_map(&:environment_variables) - else - core_environment_variables - end - - stream_print("ID" => 10, "Name" => 30, "Value" => 50, "Environment" => 30, "Application" => 30) do |printer| - environment_variables.each_entry do |ev| - printer.print(ev.id, ev.name, print_variable_value(ev), ev.environment_name, ev.application_name) - end - end - end - - private - - def print_variable_value(environment_variable) - if environment_variable.sensitive && !switch_active?(:display_sensitive) - hide_sensitive_data(environment_variable.value) - else - environment_variable.value - end - end - - def hide_sensitive_data(value) - if value.length > SYMBOLS_TO_DISPLAY - MASK + value[-SYMBOLS_TO_DISPLAY, SYMBOLS_TO_DISPLAY] - else - MASK - end - end + module EnvironmentVariables end end end diff --git a/lib/ey-core/cli/environment_variables/list.rb b/lib/ey-core/cli/environment_variables/list.rb new file mode 100644 index 0000000..fb29268 --- /dev/null +++ b/lib/ey-core/cli/environment_variables/list.rb @@ -0,0 +1,90 @@ +require 'ey-core/cli/subcommand' + +module Ey + module Core + module Cli + module EnvironmentVariables + class List < Ey::Core::Cli::Subcommand + MASK = '****'.freeze + SYMBOLS_TO_DISPLAY = 4 + MAX_LENGTH_TO_DISPLAY = 30 + + include Ey::Core::Cli::Helpers::StreamPrinter + + title "list" + summary "Retrieve a list of Engine Yard environment variables for environments that you have access to." + + option :environment, + short: 'e', + long: 'environment', + description: 'Filter by environmeent name or id', + argument: 'Environment' + + option :application, + short: 'a', + long: 'application', + description: 'Filter by application name or id', + argument: 'Application' + + switch :display_sensitive, + short: 's', + long: 'display_sensitive', + description: 'Determines whether values of sensitive variables should be printed', + argument: 'Display Sensitive' + + def handle + environment_variables = if option(:application) + core_applications(option(:application)).flat_map(&:environment_variables) + elsif option(:environment) + core_environments(option(:environment)).flat_map(&:environment_variables) + else + core_environment_variables + end + + # puts environment_variables + # puts environment_variables.first.name + # puts environment_variables.first.value + # puts environment_variables.first.environment_name + # puts environment_variables.first.application_name + + # .each_entry would fetch new 20 set of env var and enumerate over + # .each will simply just loop over the initial 20 set + # environment_variables.each do |ev| + # puts "#{ev.id}, #{ev.name}, #{ev.value}, #{ev.environment_name}, #{ev.application_name}}" + # end + puts "print some environment_variables here..." + puts environment_variables.count # 20 + # stream_print("ID" => 10, "Name" => 30, "Value" => 50, "Environment" => 30, "Application" => 30) do |printer| + # environment_variables.each_entry do |ev| + # printer.print(ev.id, ev.name, ev.value, ev.environment_name, ev.application_name) + # end + # end + end + + def print_variable_value(environemnt_variable) + printer.print(ev.id,.ev.name, ev.value , ev.environment_name, ev.application_Name) + end + + private + + def print_variable_value(environment_variable) + puts "in print_variable_value" + if environment_variable.sensitive && !switch_active?(:display_sensitive) + hide_sensitive_data(environment_variable.value) + else + environment_variable.value + end + end + + def hide_sensitive_data(value) + if value.length > SYMBOLS_TO_DISPLAY + MASK + value[-SYMBOLS_TO_DISPLAY, SYMBOLS_TO_DISPLAY] + else + MASK + end + end + end + end + end + end +end diff --git a/lib/ey-core/cli/environment_variables/main.rb b/lib/ey-core/cli/environment_variables/main.rb new file mode 100644 index 0000000..1d2beb7 --- /dev/null +++ b/lib/ey-core/cli/environment_variables/main.rb @@ -0,0 +1,23 @@ +require 'ey-core/cli/subcommand' +# require 'ey-core/cli/environment_variables/list' +# require 'ey-core/cli/environment_variables/create' +# require 'ey-core/cli/environment_variables/update' +# require 'ey-core/cli/environment_variables/destroy' + +module Ey + module Core + module Cli + module EnvironmentVariables + class Main < Ey::Core::Cli::Subcommand + title "environment_variables" + summary "Environment variables specific commands" + + # mount Ey::Core::Cli::EnvironmentVariables::List + # mount Ey::Core::Cli::EnvironmentVariables::Create + # mount Ey::Core::Cli::EnvironmentVariables::Destroy + # mount Ey::Core::Cli::EnvironmentVariables::Update + end + end + end + end +end diff --git a/lib/ey-core/cli/main.rb b/lib/ey-core/cli/main.rb index 787c17e..3f4999c 100644 --- a/lib/ey-core/cli/main.rb +++ b/lib/ey-core/cli/main.rb @@ -45,7 +45,7 @@ class Main < Belafonte::App mount Deploy mount DockerRegistryLogin mount Environments - mount EnvironmentVariables + mount EnvironmentVariables::Main mount Help mount Init mount Login diff --git a/lib/ey-core/version.rb b/lib/ey-core/version.rb index 1437251..842a3ab 100644 --- a/lib/ey-core/version.rb +++ b/lib/ey-core/version.rb @@ -1,5 +1,5 @@ module Ey module Core - VERSION = "3.6.4" + VERSION = "3.6.5" end end From 5b9e8852a61a144965ac9d5da4426187bc82ff4a Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Thu, 19 Jan 2023 14:16:19 +0800 Subject: [PATCH 02/18] EnvVar-List: Refactor list environment_variables --- lib/ey-core/cli/environment_variables/list.rb | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/lib/ey-core/cli/environment_variables/list.rb b/lib/ey-core/cli/environment_variables/list.rb index fb29268..5db65b6 100644 --- a/lib/ey-core/cli/environment_variables/list.rb +++ b/lib/ey-core/cli/environment_variables/list.rb @@ -40,29 +40,11 @@ def handle else core_environment_variables end - - # puts environment_variables - # puts environment_variables.first.name - # puts environment_variables.first.value - # puts environment_variables.first.environment_name - # puts environment_variables.first.application_name - - # .each_entry would fetch new 20 set of env var and enumerate over - # .each will simply just loop over the initial 20 set - # environment_variables.each do |ev| - # puts "#{ev.id}, #{ev.name}, #{ev.value}, #{ev.environment_name}, #{ev.application_name}}" - # end - puts "print some environment_variables here..." - puts environment_variables.count # 20 - # stream_print("ID" => 10, "Name" => 30, "Value" => 50, "Environment" => 30, "Application" => 30) do |printer| - # environment_variables.each_entry do |ev| - # printer.print(ev.id, ev.name, ev.value, ev.environment_name, ev.application_name) - # end - # end - end - - def print_variable_value(environemnt_variable) - printer.print(ev.id,.ev.name, ev.value , ev.environment_name, ev.application_Name) + stream_print("ID" => 10, "Name" => 30, "Value" => 50, "Environment" => 30, "Application" => 30) do |printer| + environment_variables.each_entry do |ev| + printer.print(ev.id, ev.name, ev.value, ev.environment_name, ev.application_name) + end + end end private From dec0d1943ef17c4496718a6e374c683d63f66d40 Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Thu, 19 Jan 2023 14:16:38 +0800 Subject: [PATCH 03/18] EnvVar: Mount list.rb to main --- lib/ey-core/cli/environment_variables/main.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ey-core/cli/environment_variables/main.rb b/lib/ey-core/cli/environment_variables/main.rb index 1d2beb7..ac470a0 100644 --- a/lib/ey-core/cli/environment_variables/main.rb +++ b/lib/ey-core/cli/environment_variables/main.rb @@ -1,5 +1,5 @@ require 'ey-core/cli/subcommand' -# require 'ey-core/cli/environment_variables/list' +require 'ey-core/cli/environment_variables/list' # require 'ey-core/cli/environment_variables/create' # require 'ey-core/cli/environment_variables/update' # require 'ey-core/cli/environment_variables/destroy' @@ -12,7 +12,7 @@ class Main < Ey::Core::Cli::Subcommand title "environment_variables" summary "Environment variables specific commands" - # mount Ey::Core::Cli::EnvironmentVariables::List + mount Ey::Core::Cli::EnvironmentVariables::List # mount Ey::Core::Cli::EnvironmentVariables::Create # mount Ey::Core::Cli::EnvironmentVariables::Destroy # mount Ey::Core::Cli::EnvironmentVariables::Update From 41cd552d984c2afdca7bfdc9c2da6dd5a822d0f6 Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Thu, 19 Jan 2023 17:35:37 +0800 Subject: [PATCH 04/18] CLI - Setup environment_variables/create.rb --- .../cli/environment_variables/create.rb | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 lib/ey-core/cli/environment_variables/create.rb diff --git a/lib/ey-core/cli/environment_variables/create.rb b/lib/ey-core/cli/environment_variables/create.rb new file mode 100644 index 0000000..8a668c2 --- /dev/null +++ b/lib/ey-core/cli/environment_variables/create.rb @@ -0,0 +1,73 @@ +require 'ey-core/cli/subcommand' + +module Ey + module Core + module Cli + module EnvironmentVariables + class Create < Ey::Core::Cli::Subcommand + MASK = '****'.freeze + SYMBOLS_TO_DISPLAY = 4 + MAX_LENGTH_TO_DISPLAY = 30 + + include Ey::Core::Cli::Helpers::StreamPrinter + + title "create" + summary "Create Engine Yard environment variable " + + option :environment, + short: 'e', + long: 'environment', + description: 'Filter by environmeent name or id', + argument: 'Environment' + + option :application, + short: 'a', + long: 'application', + description: 'Filter by application name or id', + argument: 'Application' + + switch :display_sensitive, + short: 's', + long: 'display_sensitive', + description: 'Determines whether values of sensitive variables should be printed', + argument: 'Display Sensitive' + + def handle + environment_variables = if option(:application) + core_applications(option(:application)).flat_map(&:environment_variables) + elsif option(:environment) + core_environments(option(:environment)).flat_map(&:environment_variables) + else + core_environment_variables + end + + stream_print("ID" => 10, "Name" => 30, "Value" => 50, "Environment" => 30, "Application" => 30) do |printer| + environment_variables.each_entry do |ev| + printer.print(ev.id, ev.name, ev.value, ev.environment_name, ev.application_name) + end + end + end + + private + + def print_variable_value(environment_variable) + puts "in print_variable_value" + if environment_variable.sensitive && !switch_active?(:display_sensitive) + hide_sensitive_data(environment_variable.value) + else + environment_variable.value + end + end + + def hide_sensitive_data(value) + if value.length > SYMBOLS_TO_DISPLAY + MASK + value[-SYMBOLS_TO_DISPLAY, SYMBOLS_TO_DISPLAY] + else + MASK + end + end + end + end + end + end +end From 4d927d5342ed92b92f6441a318efb485717d9875 Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Fri, 20 Jan 2023 11:58:17 +0800 Subject: [PATCH 05/18] mount environment_variables/create.rb on ey-core cli --- lib/ey-core/cli/environment_variables/main.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ey-core/cli/environment_variables/main.rb b/lib/ey-core/cli/environment_variables/main.rb index ac470a0..5ac5a2e 100644 --- a/lib/ey-core/cli/environment_variables/main.rb +++ b/lib/ey-core/cli/environment_variables/main.rb @@ -1,6 +1,6 @@ require 'ey-core/cli/subcommand' require 'ey-core/cli/environment_variables/list' -# require 'ey-core/cli/environment_variables/create' +require 'ey-core/cli/environment_variables/create' # require 'ey-core/cli/environment_variables/update' # require 'ey-core/cli/environment_variables/destroy' @@ -13,7 +13,7 @@ class Main < Ey::Core::Cli::Subcommand summary "Environment variables specific commands" mount Ey::Core::Cli::EnvironmentVariables::List - # mount Ey::Core::Cli::EnvironmentVariables::Create + mount Ey::Core::Cli::EnvironmentVariables::Create # mount Ey::Core::Cli::EnvironmentVariables::Destroy # mount Ey::Core::Cli::EnvironmentVariables::Update end From 5b5d60f20246f1b6acb51374e639342abb805366 Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Tue, 31 Jan 2023 17:27:05 +0800 Subject: [PATCH 06/18] Add environment_variables/update.rb --- .../cli/environment_variables/update.rb | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 lib/ey-core/cli/environment_variables/update.rb diff --git a/lib/ey-core/cli/environment_variables/update.rb b/lib/ey-core/cli/environment_variables/update.rb new file mode 100644 index 0000000..7cb7381 --- /dev/null +++ b/lib/ey-core/cli/environment_variables/update.rb @@ -0,0 +1,80 @@ +require 'ey-core/cli/subcommand' + +module Ey + module Core + module Cli + module EnvironmentVariables + class Update < Ey::Core::Cli::Subcommand + MASK = '****'.freeze + SYMBOLS_TO_DISPLAY = 4 + MAX_LENGTH_TO_DISPLAY = 30 + + include Ey::Core::Cli::Helpers::StreamPrinter + + title "Update" + summary "Update Engine Yard environment variable " + + option :environment, + short: 'e', + long: 'environment', + description: 'Filter by environmeent name or id', + argument: 'Environment' + + option :application, + short: 'a', + long: 'application', + description: 'Filter by application name or id', + argument: 'Application' + + option :display_sensitive, + short: 's', + long: 'display_sensitive', + description: 'Determines whether values of sensitive variables should be printed', + argument: 'Display Sensitive' + + option :key, + short: 'k', + long: 'key', + description: 'Key', + argument: 'Key' + + option :value, + short: 'v', + long: 'value', + description: 'Value', + argument: 'Value' + + def handle + application_name = option(:application) + environment_name = option(:environment) + key = option(:key) + value = option(:value) + + puts "Update Environment Variable" + environment = core_client.environments.first{|e| e.name == environment_name && e.application.name == application_name } + ev = core_client.environment_variables.first{|ev| ev.name == key && ev.environment_id == environment.id && ev.application_id == environment.application.id } + puts ev.update(name:key,value:value) + end + + private + + def print_variable_value(environment_variable) + if environment_variable.sensitive && !switch_active?(:display_sensitive) + hide_sensitive_data(environment_variable.value) + else + environment_variable.value + end + end + + def hide_sensitive_data(value) + if value.length > SYMBOLS_TO_DISPLAY + MASK + value[-SYMBOLS_TO_DISPLAY, SYMBOLS_TO_DISPLAY] + else + MASK + end + end + end + end + end + end +end From 4443b16bc0f3aa4507b052c8975594c94a476aa8 Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Tue, 31 Jan 2023 17:35:45 +0800 Subject: [PATCH 07/18] Refactor environment_variables/create.rb --- .../cli/environment_variables/create.rb | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/ey-core/cli/environment_variables/create.rb b/lib/ey-core/cli/environment_variables/create.rb index 8a668c2..885570c 100644 --- a/lib/ey-core/cli/environment_variables/create.rb +++ b/lib/ey-core/cli/environment_variables/create.rb @@ -26,26 +26,36 @@ class Create < Ey::Core::Cli::Subcommand description: 'Filter by application name or id', argument: 'Application' - switch :display_sensitive, + option :display_sensitive, short: 's', long: 'display_sensitive', description: 'Determines whether values of sensitive variables should be printed', argument: 'Display Sensitive' + + option :key, + short: 'k', + long: 'key', + description: 'Key', + argument: 'Key' + + option :value, + short: 'v', + long: 'value', + description: 'Value', + argument: 'Value' + def handle - environment_variables = if option(:application) - core_applications(option(:application)).flat_map(&:environment_variables) - elsif option(:environment) - core_environments(option(:environment)).flat_map(&:environment_variables) - else - core_environment_variables - end - - stream_print("ID" => 10, "Name" => 30, "Value" => 50, "Environment" => 30, "Application" => 30) do |printer| - environment_variables.each_entry do |ev| - printer.print(ev.id, ev.name, ev.value, ev.environment_name, ev.application_name) - end - end + application_name = option(:application) + environment_name = option(:environment) + key = option(:key) + value = option(:value) + + puts "Create Environment Variable" + + env = core_client.environments.filter{ |env| env.name == environment_name }&.first + + puts core_client.environment_variables.create(name:key,value:value,environment_id:env.id, application_id: env.application.id) end private From 555b56c1936bae63d7fb69b418c739871415ae3e Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Tue, 31 Jan 2023 17:36:05 +0800 Subject: [PATCH 08/18] Mount environment_variables/update.rb --- lib/ey-core/cli/environment_variables/main.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ey-core/cli/environment_variables/main.rb b/lib/ey-core/cli/environment_variables/main.rb index 5ac5a2e..a66a060 100644 --- a/lib/ey-core/cli/environment_variables/main.rb +++ b/lib/ey-core/cli/environment_variables/main.rb @@ -1,7 +1,7 @@ require 'ey-core/cli/subcommand' require 'ey-core/cli/environment_variables/list' require 'ey-core/cli/environment_variables/create' -# require 'ey-core/cli/environment_variables/update' +require 'ey-core/cli/environment_variables/update' # require 'ey-core/cli/environment_variables/destroy' module Ey @@ -14,8 +14,8 @@ class Main < Ey::Core::Cli::Subcommand mount Ey::Core::Cli::EnvironmentVariables::List mount Ey::Core::Cli::EnvironmentVariables::Create + mount Ey::Core::Cli::EnvironmentVariables::Update # mount Ey::Core::Cli::EnvironmentVariables::Destroy - # mount Ey::Core::Cli::EnvironmentVariables::Update end end end From 023991df75ca1359f15ed335d45e138ad5a5a0ea Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Thu, 2 Feb 2023 15:32:23 +0800 Subject: [PATCH 09/18] Refine environment_variables/update.rb title --- lib/ey-core/cli/environment_variables/update.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ey-core/cli/environment_variables/update.rb b/lib/ey-core/cli/environment_variables/update.rb index 7cb7381..d4fc20f 100644 --- a/lib/ey-core/cli/environment_variables/update.rb +++ b/lib/ey-core/cli/environment_variables/update.rb @@ -11,7 +11,7 @@ class Update < Ey::Core::Cli::Subcommand include Ey::Core::Cli::Helpers::StreamPrinter - title "Update" + title "update" summary "Update Engine Yard environment variable " option :environment, From 07a7202beae64b13e57427df945e20e23cc17a56 Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Fri, 10 Feb 2023 14:37:55 +0800 Subject: [PATCH 10/18] Add destroy_environment_variable request to ey-core client --- lib/ey-core/client.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ey-core/client.rb b/lib/ey-core/client.rb index 9f95f26..5600bf4 100644 --- a/lib/ey-core/client.rb +++ b/lib/ey-core/client.rb @@ -186,6 +186,7 @@ class Ey::Core::Client < Cistern::Service request :destroy_database_server_snapshot request :destroy_database_service request :destroy_environment + request :destroy_environment_variable request :destroy_firewall request :destroy_firewall_rule request :destroy_load_balancer From 8b161f0eb5af6259f072df07550a553d140fc7d0 Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Fri, 10 Feb 2023 15:19:47 +0800 Subject: [PATCH 11/18] Setup destroy cli functionality on environment_variables --- .../cli/environment_variables/destroy.rb | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 lib/ey-core/cli/environment_variables/destroy.rb diff --git a/lib/ey-core/cli/environment_variables/destroy.rb b/lib/ey-core/cli/environment_variables/destroy.rb new file mode 100644 index 0000000..9891f26 --- /dev/null +++ b/lib/ey-core/cli/environment_variables/destroy.rb @@ -0,0 +1,80 @@ +require 'ey-core/cli/subcommand' + +module Ey + module Core + module Cli + module EnvironmentVariables + class Destroy < Ey::Core::Cli::Subcommand + MASK = '****'.freeze + SYMBOLS_TO_DISPLAY = 4 + MAX_LENGTH_TO_DISPLAY = 30 + + include Ey::Core::Cli::Helpers::StreamPrinter + + title "destroy" + summary "Destory a Engine Yard environment variable " + + option :environment, + short: 'e', + long: 'environment', + description: 'Filter by environmeent name or id', + argument: 'Environment' + + option :application, + short: 'a', + long: 'application', + description: 'Filter by application name or id', + argument: 'Application' + + option :display_sensitive, + short: 's', + long: 'display_sensitive', + description: 'Determines whether values of sensitive variables should be printed', + argument: 'Display Sensitive' + + option :key, + short: 'k', + long: 'key', + description: 'Key', + argument: 'Key' + + option :value, + short: 'v', + long: 'value', + description: 'Value', + argument: 'Value' + + def handle + application_name = option(:application) + environment_name = option(:environment) + key = option(:key) + value = option(:value) + + puts "Destroy Environment Variable" + environment = core_client.environments.first{|e| e.name == environment_name && e.application.name == application_name } + ev = core_client.environment_variables.first{|ev| ev.name == key && ev.environment_id == environment.id && ev.application_id == environment.application.id } + puts ev.destroy! + end + + private + + def print_variable_value(environment_variable) + if environment_variable.sensitive && !switch_active?(:display_sensitive) + hide_sensitive_data(environment_variable.value) + else + environment_variable.value + end + end + + def hide_sensitive_data(value) + if value.length > SYMBOLS_TO_DISPLAY + MASK + value[-SYMBOLS_TO_DISPLAY, SYMBOLS_TO_DISPLAY] + else + MASK + end + end + end + end + end + end +end From b08723abc40846350c4dced742f8bc884c9c1ef7 Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Fri, 10 Feb 2023 15:41:39 +0800 Subject: [PATCH 12/18] Import destroy environment_variable to environment_variables/main.rb --- lib/ey-core/cli/environment_variables/main.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ey-core/cli/environment_variables/main.rb b/lib/ey-core/cli/environment_variables/main.rb index a66a060..be40473 100644 --- a/lib/ey-core/cli/environment_variables/main.rb +++ b/lib/ey-core/cli/environment_variables/main.rb @@ -2,7 +2,7 @@ require 'ey-core/cli/environment_variables/list' require 'ey-core/cli/environment_variables/create' require 'ey-core/cli/environment_variables/update' -# require 'ey-core/cli/environment_variables/destroy' +require 'ey-core/cli/environment_variables/destroy' module Ey module Core @@ -15,7 +15,7 @@ class Main < Ey::Core::Cli::Subcommand mount Ey::Core::Cli::EnvironmentVariables::List mount Ey::Core::Cli::EnvironmentVariables::Create mount Ey::Core::Cli::EnvironmentVariables::Update - # mount Ey::Core::Cli::EnvironmentVariables::Destroy + mount Ey::Core::Cli::EnvironmentVariables::Destroy end end end From e68ce28a970874fbc22f3f096f60a3a03075922c Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Fri, 10 Feb 2023 17:57:59 +0800 Subject: [PATCH 13/18] Overwrite destory method on environment_variable model --- lib/ey-core/models/environment_variable.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/ey-core/models/environment_variable.rb b/lib/ey-core/models/environment_variable.rb index d42b0ba..d2058f1 100644 --- a/lib/ey-core/models/environment_variable.rb +++ b/lib/ey-core/models/environment_variable.rb @@ -26,4 +26,8 @@ def save! merge_attributes(self.connection.update_environment_variable(params).body["environment_variable"]) end end + + def destroy! + connection.requests.new(self.connection.destroy_environment_variable("id" => self.id).body["request"]) + end end From dd2ef4a5f16b7e3496f739e409ff2c24b5e065af Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Sat, 11 Feb 2023 01:13:44 +0800 Subject: [PATCH 14/18] Setup destroy_environment_variables ey-core requests method --- .../requests/destroy_environment_variable.rb | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/ey-core/requests/destroy_environment_variable.rb diff --git a/lib/ey-core/requests/destroy_environment_variable.rb b/lib/ey-core/requests/destroy_environment_variable.rb new file mode 100644 index 0000000..a6295aa --- /dev/null +++ b/lib/ey-core/requests/destroy_environment_variable.rb @@ -0,0 +1,49 @@ +class Ey::Core::Client + class Real + def destroy_environment_variable(params={}) + id = params["id"] + url = params.delete("url") + + request( + :path => "/environment_variables/#{id}", + :url => url, + :method => :delete, + ) + end + end + + # class Mock + # def destroy_environment_variable(params={}) + # extract_url_params!(params) + # request_id = self.uuid + + # environment_variable_id = params["id"] || params["environment_variable"] + + # environment_variable = self.find(:environment_variables, environment_variable_id) + + # request = { + # "finished_at" => nil, + # "id" => request_id, + # "started_at" => Time.now, + # "successful" => "true", + # "type" => "deprovision_environment_variable", + # "resource" => [:environment_variables, environment_variable_id, lambda do |r| + # environment_variable.merge!("deleted_at" => Time.now) + + # self.data[:database_servers].values. + # select { |ds| ds["environment_variable"] == url_for("/environment_variables/#{environment_variable["id"]}") }. + # each { |ds| ds["deleted_at"] = Time.now } + + # r.delete("resource_url") + # end], + # } + + # self.data[:requests][request_id] = request + + # response( + # :body => {"request" => {id: request_id}}, + # :status => 201, + # ) + # end + # end +end From 4c9b6d76b1fa709fdd97be2c8c4ec4c6c423177f Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Tue, 14 Feb 2023 14:55:38 +0800 Subject: [PATCH 15/18] Refactor environment_variables creation logic --- lib/ey-core/cli/environment_variables/create.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ey-core/cli/environment_variables/create.rb b/lib/ey-core/cli/environment_variables/create.rb index 885570c..6f9eca8 100644 --- a/lib/ey-core/cli/environment_variables/create.rb +++ b/lib/ey-core/cli/environment_variables/create.rb @@ -53,9 +53,16 @@ def handle puts "Create Environment Variable" + puts application_name + puts environment_name + env = core_client.environments.filter{ |env| env.name == environment_name }&.first + app = core_client.applications.filter{ |app| app.name == application_name }&.first + puts env + puts env.application + # puts app.environments - puts core_client.environment_variables.create(name:key,value:value,environment_id:env.id, application_id: env.application.id) + puts core_client.environment_variables.create(name:key,value:value,environment_id:env.id, application_id: app.id) end private From 6dcf6b8b8b0ffa79926d75da47b152469058b992 Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Tue, 14 Feb 2023 16:09:33 +0800 Subject: [PATCH 16/18] Enable mock class under destroy_environment_variable --- .../requests/destroy_environment_variable.rb | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/lib/ey-core/requests/destroy_environment_variable.rb b/lib/ey-core/requests/destroy_environment_variable.rb index a6295aa..5b49826 100644 --- a/lib/ey-core/requests/destroy_environment_variable.rb +++ b/lib/ey-core/requests/destroy_environment_variable.rb @@ -2,48 +2,46 @@ class Ey::Core::Client class Real def destroy_environment_variable(params={}) id = params["id"] - url = params.delete("url") request( :path => "/environment_variables/#{id}", - :url => url, :method => :delete, ) end end - # class Mock - # def destroy_environment_variable(params={}) - # extract_url_params!(params) - # request_id = self.uuid + class Mock + def destroy_environment_variable(params={}) + extract_url_params!(params) + request_id = self.uuid - # environment_variable_id = params["id"] || params["environment_variable"] + environment_variable_id = params["id"] || params["environment_variable"] - # environment_variable = self.find(:environment_variables, environment_variable_id) + environment_variable = self.find(:environment_variables, environment_variable_id) - # request = { - # "finished_at" => nil, - # "id" => request_id, - # "started_at" => Time.now, - # "successful" => "true", - # "type" => "deprovision_environment_variable", - # "resource" => [:environment_variables, environment_variable_id, lambda do |r| - # environment_variable.merge!("deleted_at" => Time.now) + request = { + "finished_at" => nil, + "id" => request_id, + "started_at" => Time.now, + "successful" => "true", + "type" => "deprovision_environment_variable", + "resource" => [:environment_variables, environment_variable_id, lambda do |r| + environment_variable.merge!("deleted_at" => Time.now) - # self.data[:database_servers].values. - # select { |ds| ds["environment_variable"] == url_for("/environment_variables/#{environment_variable["id"]}") }. - # each { |ds| ds["deleted_at"] = Time.now } + self.data[:database_servers].values. + select { |ds| ds["environment_variable"] == url_for("/environment_variables/#{environment_variable["id"]}") }. + each { |ds| ds["deleted_at"] = Time.now } - # r.delete("resource_url") - # end], - # } + r.delete("resource_url") + end], + } - # self.data[:requests][request_id] = request + self.data[:requests][request_id] = request - # response( - # :body => {"request" => {id: request_id}}, - # :status => 201, - # ) - # end - # end + response( + :body => {"request" => {id: request_id}}, + :status => 201, + ) + end + end end From 5fbde9f713a0b110eaf5c6079acad1244a0f09b8 Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Thu, 16 Feb 2023 17:28:21 +0800 Subject: [PATCH 17/18] Fix environment_variables destroy error --- lib/ey-core/models/environment_variable.rb | 2 +- lib/ey-core/requests/destroy_environment_variable.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ey-core/models/environment_variable.rb b/lib/ey-core/models/environment_variable.rb index d2058f1..1dbff20 100644 --- a/lib/ey-core/models/environment_variable.rb +++ b/lib/ey-core/models/environment_variable.rb @@ -28,6 +28,6 @@ def save! end def destroy! - connection.requests.new(self.connection.destroy_environment_variable("id" => self.id).body["request"]) + connection.requests.new(self.connection.destroy_environment_variable("id" => self.id).request) end end diff --git a/lib/ey-core/requests/destroy_environment_variable.rb b/lib/ey-core/requests/destroy_environment_variable.rb index 5b49826..241e1e8 100644 --- a/lib/ey-core/requests/destroy_environment_variable.rb +++ b/lib/ey-core/requests/destroy_environment_variable.rb @@ -3,10 +3,11 @@ class Real def destroy_environment_variable(params={}) id = params["id"] - request( + response = request( :path => "/environment_variables/#{id}", :method => :delete, ) + response end end From e6c4a8b03278a84d36f55d2f3948f861754f7824 Mon Sep 17 00:00:00 2001 From: Kyle-Law Date: Thu, 16 Feb 2023 17:28:27 +0800 Subject: [PATCH 18/18] Refinement --- lib/ey-core/cli/environment_variables/create.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/ey-core/cli/environment_variables/create.rb b/lib/ey-core/cli/environment_variables/create.rb index 6f9eca8..0403b53 100644 --- a/lib/ey-core/cli/environment_variables/create.rb +++ b/lib/ey-core/cli/environment_variables/create.rb @@ -52,23 +52,14 @@ def handle value = option(:value) puts "Create Environment Variable" - - puts application_name - puts environment_name - env = core_client.environments.filter{ |env| env.name == environment_name }&.first app = core_client.applications.filter{ |app| app.name == application_name }&.first - puts env - puts env.application - # puts app.environments - puts core_client.environment_variables.create(name:key,value:value,environment_id:env.id, application_id: app.id) end private def print_variable_value(environment_variable) - puts "in print_variable_value" if environment_variable.sensitive && !switch_active?(:display_sensitive) hide_sensitive_data(environment_variable.value) else