From 96c2502928969562c7d129f87d3bc1ad2c37920d Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Fri, 10 Oct 2025 17:33:58 +0200 Subject: [PATCH 01/45] changing Target API --- lib/envirobly/config.rb | 5 +- lib/envirobly/target.rb | 43 ++-- test/envirobly/target_test.rb | 247 ++++++++++---------- test/fixtures/targets/.default/account_url | 1 + test/fixtures/targets/.default/project_name | 1 + test/fixtures/targets/.default/region | 1 + 6 files changed, 152 insertions(+), 146 deletions(-) create mode 100644 test/fixtures/targets/.default/account_url create mode 100644 test/fixtures/targets/.default/project_name create mode 100644 test/fixtures/targets/.default/region diff --git a/lib/envirobly/config.rb b/lib/envirobly/config.rb index 4568c81..b876183 100644 --- a/lib/envirobly/config.rb +++ b/lib/envirobly/config.rb @@ -4,7 +4,8 @@ module Envirobly class Config DIR = ".envirobly" BASE = "deploy.yml" - OVERRIDES_PATTERN = /deploy\.([a-z0-9\-_]+)\.yml/i + ENVIRON_OVERRIDE_REGEXP = /deploy\.([a-z0-9\-_]+)\.yml/i + TARGETS_PATH = Pathname.new(DIR).join(".targets") attr_reader :errors @@ -43,7 +44,7 @@ def merge(environ_name = nil) private def config_file?(file) - file == BASE || file.match?(OVERRIDES_PATTERN) + file == BASE || file.match?(ENVIRON_OVERRIDE_REGEXP) end def parse(content, path) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index eb7592d..fc6d3ae 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -2,30 +2,24 @@ module Envirobly class Target - attr_accessor :account_id, :project_id, :region + attr_accessor :project_id, :region def initialize( - default_account_id: nil, - default_project_id: nil, - default_region: nil, - default_project_name: nil, - default_environ_name: nil, - account_id: nil, - project_id: nil, + name: nil, + account_url: nil, region: nil, project_name: nil, - environ_name: nil + environ_name: nil, + config_path: Config::TARGETS_PATH ) - @default_account_id = default_account_id - @default_project_id = default_project_id - @default_region = default_region - @default_project_name = default_project_name - @default_environ_name = default_environ_name - @account_id = account_id - @project_id = project_id + @name = name + @account_url = account_id @region = region + @project_id = project_id @project_name = project_name @environ_name = environ_name + @config_path = config_path + @default_target_dir = config_path.join(".default") end def missing_params @@ -40,10 +34,16 @@ def missing_params end end - def account_id - return if @project_id + def account_url + @account_url.presence || default_account_url + end - @account_id || @default_account_id + def account_id + if account_url =~ /accounts\/(\d)+/i + $1.to_i + else + nil + end end def project_id @@ -83,5 +83,10 @@ def ignored_params end end end + + private + def default_account_url + File.read(@default_target_dir.join("account_url")).strip + end end end diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index 4a60442..bba67d3 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -5,134 +5,131 @@ module Envirobly class TargetTest < ActiveSupport::TestCase test "all defaults exist, no overrides" do - target = Target.new( - default_account_id: 1, - default_project_id: 2, - default_region: "eu-north-1" - ) + target = Target.new config_path: Pathname.new("test/fixtures/targets") + assert_equal "https://example.com/accounts/1", target.account_url assert_equal 1, target.account_id - assert_equal 2, target.project_id + assert_equal "world", target.project_name assert_equal "eu-north-1", target.region end - test "all defaults exist, override account_id" do - target = Target.new( - default_account_id: 1, - default_project_id: 2, - default_region: "eu-north-1", - account_id: 3 - ) - assert_equal 3, target.account_id - assert_nil target.project_id - assert_equal "eu-north-1", target.region - end - - test "all defaults exist, override project_id" do - target = Target.new( - default_account_id: 1, - default_project_id: 2, - default_region: "eu-north-1", - project_id: 3 - ) - assert_nil target.account_id - assert_equal 3, target.project_id - assert_nil target.region - end - - test "ignored_params when project_id is specified" do - target = Target.new( - default_account_id: 1, - default_project_id: 2, - default_project_name: "dirname", - project_name: "custom", - account_id: 6, - project_id: 3, - region: "us-east-2" - ) - assert_equal %i[ account_id region project_name ], target.ignored_params - assert_empty target.missing_params - - target = Target.new( - project_id: 3, - region: "us-east-2" - ) - assert_equal %i[ region ], target.ignored_params - assert_empty target.missing_params - - target = Target.new( - project_id: 3 - ) - assert_empty target.ignored_params - assert_empty target.missing_params - end - - test "missing_params" do - target = Target.new - assert_equal %i[ account_id region ], target.missing_params - - target.account_id = 6 - assert_equal %i[ region ], target.missing_params - - target.region = "us-east-2" - assert_empty target.missing_params - end - - test "project_name overrides default_project_id and default_project_name" do - target = Target.new( - default_account_id: 1, - default_project_id: 2, - default_project_name: "dirname", - project_name: "custom" - ) - assert_equal 1, target.account_id - assert_nil target.project_id - assert_equal "custom", target.project_name - assert_equal %i[ region ], target.missing_params - end - - test "project_id overrides project_name" do - target = Target.new( - default_account_id: 1, - default_project_id: 2, - default_project_name: "dirname", - project_name: "custom", - project_id: 3 - ) - assert_nil target.account_id - assert_equal 3, target.project_id - assert_nil target.project_name - assert_nil target.region - assert_empty target.missing_params - assert_equal %i[ project_name ], target.ignored_params - end - - test "default_project_name and default_environ_name and no other defaults" do - target = Target.new( - default_project_name: "dirname", - default_environ_name: "main" - ) - assert_nil target.account_id - assert_nil target.project_id - assert_equal "dirname", target.project_name - assert_equal "main", target.environ_name - assert_nil target.region - assert_equal %i[ account_id region ], target.missing_params - assert_empty target.ignored_params - end - - test "environ_name override" do - target = Target.new( - default_project_name: "dirname", - default_environ_name: "main", - environ_name: "production" - ) - assert_nil target.account_id - assert_nil target.project_id - assert_equal "dirname", target.project_name - assert_equal "production", target.environ_name - assert_nil target.region - assert_equal %i[ account_id region ], target.missing_params - assert_empty target.ignored_params - end + # test "all defaults exist, override account_id" do + # target = Target.new( + # default_account_id: 1, + # default_project_id: 2, + # default_region: "eu-north-1", + # account_id: 3 + # ) + # assert_equal 3, target.account_id + # assert_nil target.project_id + # assert_equal "eu-north-1", target.region + # end + # + # test "all defaults exist, override project_id" do + # target = Target.new( + # default_account_id: 1, + # default_project_id: 2, + # default_region: "eu-north-1", + # project_id: 3 + # ) + # assert_nil target.account_id + # assert_equal 3, target.project_id + # assert_nil target.region + # end + # + # test "ignored_params when project_id is specified" do + # target = Target.new( + # default_account_id: 1, + # default_project_id: 2, + # default_project_name: "dirname", + # project_name: "custom", + # account_id: 6, + # project_id: 3, + # region: "us-east-2" + # ) + # assert_equal %i[ account_id region project_name ], target.ignored_params + # assert_empty target.missing_params + # + # target = Target.new( + # project_id: 3, + # region: "us-east-2" + # ) + # assert_equal %i[ region ], target.ignored_params + # assert_empty target.missing_params + # + # target = Target.new( + # project_id: 3 + # ) + # assert_empty target.ignored_params + # assert_empty target.missing_params + # end + # + # test "missing_params" do + # target = Target.new + # assert_equal %i[ account_id region ], target.missing_params + # + # target.account_id = 6 + # assert_equal %i[ region ], target.missing_params + # + # target.region = "us-east-2" + # assert_empty target.missing_params + # end + # + # test "project_name overrides default_project_id and default_project_name" do + # target = Target.new( + # default_account_id: 1, + # default_project_id: 2, + # default_project_name: "dirname", + # project_name: "custom" + # ) + # assert_equal 1, target.account_id + # assert_nil target.project_id + # assert_equal "custom", target.project_name + # assert_equal %i[ region ], target.missing_params + # end + # + # test "project_id overrides project_name" do + # target = Target.new( + # default_account_id: 1, + # default_project_id: 2, + # default_project_name: "dirname", + # project_name: "custom", + # project_id: 3 + # ) + # assert_nil target.account_id + # assert_equal 3, target.project_id + # assert_nil target.project_name + # assert_nil target.region + # assert_empty target.missing_params + # assert_equal %i[ project_name ], target.ignored_params + # end + # + # test "default_project_name and default_environ_name and no other defaults" do + # target = Target.new( + # default_project_name: "dirname", + # default_environ_name: "main" + # ) + # assert_nil target.account_id + # assert_nil target.project_id + # assert_equal "dirname", target.project_name + # assert_equal "main", target.environ_name + # assert_nil target.region + # assert_equal %i[ account_id region ], target.missing_params + # assert_empty target.ignored_params + # end + # + # test "environ_name override" do + # target = Target.new( + # default_project_name: "dirname", + # default_environ_name: "main", + # environ_name: "production" + # ) + # assert_nil target.account_id + # assert_nil target.project_id + # assert_equal "dirname", target.project_name + # assert_equal "production", target.environ_name + # assert_nil target.region + # assert_equal %i[ account_id region ], target.missing_params + # assert_empty target.ignored_params + # end end end diff --git a/test/fixtures/targets/.default/account_url b/test/fixtures/targets/.default/account_url new file mode 100644 index 0000000..403996f --- /dev/null +++ b/test/fixtures/targets/.default/account_url @@ -0,0 +1 @@ +https://example.com/accounts/1 diff --git a/test/fixtures/targets/.default/project_name b/test/fixtures/targets/.default/project_name new file mode 100644 index 0000000..cc628cc --- /dev/null +++ b/test/fixtures/targets/.default/project_name @@ -0,0 +1 @@ +world diff --git a/test/fixtures/targets/.default/region b/test/fixtures/targets/.default/region new file mode 100644 index 0000000..eaf877f --- /dev/null +++ b/test/fixtures/targets/.default/region @@ -0,0 +1 @@ +eu-north-1 From 763cc76ab3895f189abe63a0c003ade6c4ec515a Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Fri, 10 Oct 2025 17:41:06 +0200 Subject: [PATCH 02/45] pass --- lib/envirobly/target.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index fc6d3ae..4f093e9 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -13,7 +13,7 @@ def initialize( config_path: Config::TARGETS_PATH ) @name = name - @account_url = account_id + @account_url = account_url @region = region @project_id = project_id @project_name = project_name @@ -53,9 +53,7 @@ def project_id end def project_name - return if @project_id - - @project_name.presence || @default_project_name + @project_name.presence || default_project_name end def environ_name @@ -63,9 +61,7 @@ def environ_name end def region - return if @project_id - - @region || @default_region + @region.presence || default_region end def ignored_params @@ -88,5 +84,13 @@ def ignored_params def default_account_url File.read(@default_target_dir.join("account_url")).strip end + + def default_project_name + File.read(@default_target_dir.join("project_name")).strip + end + + def default_region + File.read(@default_target_dir.join("region")).strip + end end end From a89e936c1db58f7e298d7e3dd054a716a7b54ed2 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Fri, 10 Oct 2025 17:42:21 +0200 Subject: [PATCH 03/45] refactor --- lib/envirobly/target.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 4f093e9..e37fdbb 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -81,16 +81,20 @@ def ignored_params end private + def default_value_for(type) + File.read(@default_target_dir.join(type)).strip + end + def default_account_url - File.read(@default_target_dir.join("account_url")).strip + default_value_for "account_url" end def default_project_name - File.read(@default_target_dir.join("project_name")).strip + default_value_for "project_name" end def default_region - File.read(@default_target_dir.join("region")).strip + default_value_for "region" end end end From 1f090d2e78e85c6b7ca544e816cfe866282d4bb1 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Fri, 10 Oct 2025 17:44:16 +0200 Subject: [PATCH 04/45] test "all defaults exist, override account_url" do --- test/envirobly/target_test.rb | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index bba67d3..bdab6ec 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -12,18 +12,17 @@ class TargetTest < ActiveSupport::TestCase assert_equal "eu-north-1", target.region end - # test "all defaults exist, override account_id" do - # target = Target.new( - # default_account_id: 1, - # default_project_id: 2, - # default_region: "eu-north-1", - # account_id: 3 - # ) - # assert_equal 3, target.account_id - # assert_nil target.project_id - # assert_equal "eu-north-1", target.region - # end - # + test "all defaults exist, override account_url" do + target = Target.new( + account_url: "https://example.com/accounts/3", + config_path: Pathname.new("test/fixtures/targets") + ) + assert_equal "https://example.com/accounts/3", target.account_url + assert_equal 3, target.account_id + assert_equal "world", target.project_name + assert_equal "eu-north-1", target.region + end + # test "all defaults exist, override project_id" do # target = Target.new( # default_account_id: 1, From a1b808f8952735ecb009d2c2cc3b19b282f3e13b Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Fri, 10 Oct 2025 17:45:18 +0200 Subject: [PATCH 05/45] test "all defaults exist, override project_name" do --- test/envirobly/target_test.rb | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index bdab6ec..64ad56c 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -23,18 +23,16 @@ class TargetTest < ActiveSupport::TestCase assert_equal "eu-north-1", target.region end - # test "all defaults exist, override project_id" do - # target = Target.new( - # default_account_id: 1, - # default_project_id: 2, - # default_region: "eu-north-1", - # project_id: 3 - # ) - # assert_nil target.account_id - # assert_equal 3, target.project_id - # assert_nil target.region - # end - # + test "all defaults exist, override project_name" do + target = Target.new( + project_name: "home", + config_path: Pathname.new("test/fixtures/targets") + ) + assert_equal 1, target.account_id + assert_equal "home", target.project_name + assert_equal "eu-north-1", target.region + end + # test "ignored_params when project_id is specified" do # target = Target.new( # default_account_id: 1, From 57c8595ef639a3f7748d753409f2ceb52b0028d7 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Fri, 10 Oct 2025 17:46:51 +0200 Subject: [PATCH 06/45] drop ignored_params --- lib/envirobly/container_shell.rb | 4 ---- lib/envirobly/deployment.rb | 4 ---- lib/envirobly/target.rb | 16 ---------------- test/envirobly/target_test.rb | 30 ------------------------------ 4 files changed, 54 deletions(-) diff --git a/lib/envirobly/container_shell.rb b/lib/envirobly/container_shell.rb index 1152162..6966c01 100644 --- a/lib/envirobly/container_shell.rb +++ b/lib/envirobly/container_shell.rb @@ -42,10 +42,6 @@ def initialize(service_name, options, shell:) target.account_id = default_account.require_value end - target.ignored_params.each do |param| - shell.say "--#{param.to_s.parameterize} ignored, due to other arguments overriding it" - end - @params = { account_id: target.account_id, project_id: target.project_id, diff --git a/lib/envirobly/deployment.rb b/lib/envirobly/deployment.rb index db74e09..da4efd4 100644 --- a/lib/envirobly/deployment.rb +++ b/lib/envirobly/deployment.rb @@ -37,10 +37,6 @@ def initialize(environ_name:, commit:, account_id:, project_name:, project_id:, target.region = @default_region.require_value end - target.ignored_params.each do |param| - shell.say "--#{param.to_s.parameterize} ignored, due to other arguments overriding it" - end - @environ_name = target.environ_name @params = { account_id: target.account_id, diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index e37fdbb..cff6ec9 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -64,22 +64,6 @@ def region @region.presence || default_region end - def ignored_params - [].tap do |result| - if @account_id && @project_id - result << :account_id - end - - if @project_id && @region - result << :region - end - - if @project_id && @project_name.present? - result << :project_name - end - end - end - private def default_value_for(type) File.read(@default_target_dir.join(type)).strip diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index 64ad56c..14178c7 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -33,33 +33,6 @@ class TargetTest < ActiveSupport::TestCase assert_equal "eu-north-1", target.region end - # test "ignored_params when project_id is specified" do - # target = Target.new( - # default_account_id: 1, - # default_project_id: 2, - # default_project_name: "dirname", - # project_name: "custom", - # account_id: 6, - # project_id: 3, - # region: "us-east-2" - # ) - # assert_equal %i[ account_id region project_name ], target.ignored_params - # assert_empty target.missing_params - # - # target = Target.new( - # project_id: 3, - # region: "us-east-2" - # ) - # assert_equal %i[ region ], target.ignored_params - # assert_empty target.missing_params - # - # target = Target.new( - # project_id: 3 - # ) - # assert_empty target.ignored_params - # assert_empty target.missing_params - # end - # # test "missing_params" do # target = Target.new # assert_equal %i[ account_id region ], target.missing_params @@ -97,7 +70,6 @@ class TargetTest < ActiveSupport::TestCase # assert_nil target.project_name # assert_nil target.region # assert_empty target.missing_params - # assert_equal %i[ project_name ], target.ignored_params # end # # test "default_project_name and default_environ_name and no other defaults" do @@ -111,7 +83,6 @@ class TargetTest < ActiveSupport::TestCase # assert_equal "main", target.environ_name # assert_nil target.region # assert_equal %i[ account_id region ], target.missing_params - # assert_empty target.ignored_params # end # # test "environ_name override" do @@ -126,7 +97,6 @@ class TargetTest < ActiveSupport::TestCase # assert_equal "production", target.environ_name # assert_nil target.region # assert_equal %i[ account_id region ], target.missing_params - # assert_empty target.ignored_params # end end end From 3d42cf3fd4b581e129be8df7c4a03ebff7770d79 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Fri, 10 Oct 2025 17:51:39 +0200 Subject: [PATCH 07/45] test "missing_params" do --- lib/envirobly/target.rb | 10 ++++++---- test/envirobly/target_test.rb | 23 ++++++++++++----------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index cff6ec9..d575ce6 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -2,7 +2,7 @@ module Envirobly class Target - attr_accessor :project_id, :region + attr_accessor :account_url, :project_name, :region def initialize( name: nil, @@ -24,11 +24,11 @@ def initialize( def missing_params [].tap do |result| - if project_id.blank? && account_id.blank? - result << :account_id + if account_url.blank? + result << :account_url end - if project_id.blank? && region.blank? + if region.blank? result << :region end end @@ -67,6 +67,8 @@ def region private def default_value_for(type) File.read(@default_target_dir.join(type)).strip + rescue Errno::ENOENT + nil end def default_account_url diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index 14178c7..a2043bd 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -33,17 +33,18 @@ class TargetTest < ActiveSupport::TestCase assert_equal "eu-north-1", target.region end - # test "missing_params" do - # target = Target.new - # assert_equal %i[ account_id region ], target.missing_params - # - # target.account_id = 6 - # assert_equal %i[ region ], target.missing_params - # - # target.region = "us-east-2" - # assert_empty target.missing_params - # end - # + test "missing_params" do + target = Target.new + assert_equal %i[ account_url region ], target.missing_params + + target.account_url = "https://example.com/accounts/3" + assert_equal 3, target.account_id + assert_equal %i[ region ], target.missing_params + + target.region = "us-east-2" + assert_empty target.missing_params + end + # test "project_name overrides default_project_id and default_project_name" do # target = Target.new( # default_account_id: 1, From 3c60aebf79e1d172d383421ea8962b0446d0e406 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Fri, 10 Oct 2025 17:53:55 +0200 Subject: [PATCH 08/45] cleanup --- lib/envirobly/target.rb | 7 ------- test/envirobly/target_test.rb | 28 ---------------------------- 2 files changed, 35 deletions(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index d575ce6..1ab32f3 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -15,7 +15,6 @@ def initialize( @name = name @account_url = account_url @region = region - @project_id = project_id @project_name = project_name @environ_name = environ_name @config_path = config_path @@ -46,12 +45,6 @@ def account_id end end - def project_id - return if @project_id.blank? && (@account_id.present? || @project_name.present?) - - @project_id || @default_project_id - end - def project_name @project_name.presence || default_project_name end diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index a2043bd..64af744 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -45,34 +45,6 @@ class TargetTest < ActiveSupport::TestCase assert_empty target.missing_params end - # test "project_name overrides default_project_id and default_project_name" do - # target = Target.new( - # default_account_id: 1, - # default_project_id: 2, - # default_project_name: "dirname", - # project_name: "custom" - # ) - # assert_equal 1, target.account_id - # assert_nil target.project_id - # assert_equal "custom", target.project_name - # assert_equal %i[ region ], target.missing_params - # end - # - # test "project_id overrides project_name" do - # target = Target.new( - # default_account_id: 1, - # default_project_id: 2, - # default_project_name: "dirname", - # project_name: "custom", - # project_id: 3 - # ) - # assert_nil target.account_id - # assert_equal 3, target.project_id - # assert_nil target.project_name - # assert_nil target.region - # assert_empty target.missing_params - # end - # # test "default_project_name and default_environ_name and no other defaults" do # target = Target.new( # default_project_name: "dirname", From 8386626b9da8bb6f5f740f63956bd53681ea910a Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Fri, 10 Oct 2025 17:57:16 +0200 Subject: [PATCH 09/45] test "default_project_name and default_environ_name and no other defaults" do --- lib/envirobly/target.rb | 6 +++++- test/envirobly/target_test.rb | 25 ++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 1ab32f3..33755f2 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -10,6 +10,8 @@ def initialize( region: nil, project_name: nil, environ_name: nil, + default_environ_name: nil, + default_project_name: nil, config_path: Config::TARGETS_PATH ) @name = name @@ -17,6 +19,8 @@ def initialize( @region = region @project_name = project_name @environ_name = environ_name + @default_environ_name = default_environ_name + @default_project_name = default_project_name @config_path = config_path @default_target_dir = config_path.join(".default") end @@ -46,7 +50,7 @@ def account_id end def project_name - @project_name.presence || default_project_name + @project_name.presence || default_project_name.presence || @default_project_name end def environ_name diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index 64af744..dc14de7 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -45,19 +45,18 @@ class TargetTest < ActiveSupport::TestCase assert_empty target.missing_params end - # test "default_project_name and default_environ_name and no other defaults" do - # target = Target.new( - # default_project_name: "dirname", - # default_environ_name: "main" - # ) - # assert_nil target.account_id - # assert_nil target.project_id - # assert_equal "dirname", target.project_name - # assert_equal "main", target.environ_name - # assert_nil target.region - # assert_equal %i[ account_id region ], target.missing_params - # end - # + test "default_project_name and default_environ_name and no other defaults" do + target = Target.new( + default_project_name: "dirname", + default_environ_name: "main" + ) + assert_nil target.account_id + assert_equal "dirname", target.project_name + assert_equal "main", target.environ_name + assert_nil target.region + assert_equal %i[ account_url region ], target.missing_params + end + # test "environ_name override" do # target = Target.new( # default_project_name: "dirname", From e298a8de88415d867cc5f0be01aa819027d1b2a2 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Fri, 10 Oct 2025 17:59:01 +0200 Subject: [PATCH 10/45] exapnd --- test/envirobly/target_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index dc14de7..843de01 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -5,10 +5,11 @@ module Envirobly class TargetTest < ActiveSupport::TestCase test "all defaults exist, no overrides" do - target = Target.new config_path: Pathname.new("test/fixtures/targets") + target = Target.new config_path: Pathname.new("test/fixtures/targets"), default_project_name: "123", default_environ_name: "abcd" assert_equal "https://example.com/accounts/1", target.account_url assert_equal 1, target.account_id assert_equal "world", target.project_name + assert_equal "abcd", target.environ_name assert_equal "eu-north-1", target.region end @@ -25,6 +26,7 @@ class TargetTest < ActiveSupport::TestCase test "all defaults exist, override project_name" do target = Target.new( + default_project_name: "dirname", project_name: "home", config_path: Pathname.new("test/fixtures/targets") ) From a26ee5a7149a00e8f2267453ce3c716a2c8db525 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Fri, 10 Oct 2025 18:00:09 +0200 Subject: [PATCH 11/45] test "environ_name override" do --- test/envirobly/target_test.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index 843de01..f23d613 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -59,18 +59,18 @@ class TargetTest < ActiveSupport::TestCase assert_equal %i[ account_url region ], target.missing_params end - # test "environ_name override" do - # target = Target.new( - # default_project_name: "dirname", - # default_environ_name: "main", - # environ_name: "production" - # ) - # assert_nil target.account_id - # assert_nil target.project_id - # assert_equal "dirname", target.project_name - # assert_equal "production", target.environ_name - # assert_nil target.region - # assert_equal %i[ account_id region ], target.missing_params - # end + test "environ_name override" do + target = Target.new( + default_project_name: "dirname", + default_environ_name: "main", + environ_name: "production" + ) + assert_nil target.account_url + assert_nil target.account_id + assert_equal "dirname", target.project_name + assert_equal "production", target.environ_name + assert_nil target.region + assert_equal %i[ account_url region ], target.missing_params + end end end From 6fee1b145b00cfefa9641ea7651d6af7df2e1cc6 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Fri, 10 Oct 2025 18:06:57 +0200 Subject: [PATCH 12/45] save_defaults --- lib/envirobly/target.rb | 7 +++++++ test/envirobly/target_test.rb | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 33755f2..3e18214 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -61,6 +61,13 @@ def region @region.presence || default_region end + def save_defaults + FileUtils.mkdir_p @default_target_dir + File.write @default_target_dir.join("account_url"), account_url + File.write @default_target_dir.join("project_name"), project_name + File.write @default_target_dir.join("region"), region + end + private def default_value_for(type) File.read(@default_target_dir.join(type)).strip diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index f23d613..5403214 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -72,5 +72,16 @@ class TargetTest < ActiveSupport::TestCase assert_nil target.region assert_equal %i[ account_url region ], target.missing_params end + + test "save_defaults" do + config_path = Pathname.new Dir.mktmpdir + target = Target.new(config_path:, account_url: "https://example.com/accounts/3", region: "us-east-2", project_name: "yes") + target.save_defaults + assert_equal "https://example.com/accounts/3", File.read(config_path.join ".default/account_url") + assert_equal "us-east-2", File.read(config_path.join ".default/region") + assert_equal "yes", File.read(config_path.join ".default/project_name") + ensure + FileUtils.rm_rf config_path + end end end From 515e0d3b11ad0d4eeb7c18ec79a4989733d7dd19 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Fri, 10 Oct 2025 18:08:28 +0200 Subject: [PATCH 13/45] refactor --- lib/envirobly/target.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 3e18214..11260d6 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -63,9 +63,9 @@ def region def save_defaults FileUtils.mkdir_p @default_target_dir - File.write @default_target_dir.join("account_url"), account_url - File.write @default_target_dir.join("project_name"), project_name - File.write @default_target_dir.join("region"), region + write_default "account_url" + write_default "project_name" + write_default "region" end private @@ -75,6 +75,10 @@ def default_value_for(type) nil end + def write_default(type) + File.write @default_target_dir.join(type), send(type) + end + def default_account_url default_value_for "account_url" end From b691d111ac44fe1c226e37a5aa8fb2050cf138e1 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 11:16:51 +0200 Subject: [PATCH 14/45] path as environ name overrides default --- lib/envirobly/target.rb | 17 +++++++++++++---- test/envirobly/target_test.rb | 28 ++++++++++++++-------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 11260d6..92552de 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -5,20 +5,18 @@ class Target attr_accessor :account_url, :project_name, :region def initialize( - name: nil, + path = nil, account_url: nil, region: nil, project_name: nil, - environ_name: nil, default_environ_name: nil, default_project_name: nil, config_path: Config::TARGETS_PATH ) - @name = name + load_path path @account_url = account_url @region = region @project_name = project_name - @environ_name = environ_name @default_environ_name = default_environ_name @default_project_name = default_project_name @config_path = config_path @@ -90,5 +88,16 @@ def default_project_name def default_region default_value_for "region" end + + def load_path(path) + return if path.blank? + + parts = path.split("/") + + case parts.size + when 1 + @environ_name = parts.first + end + end end end diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index 5403214..ea3b2cf 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -59,20 +59,6 @@ class TargetTest < ActiveSupport::TestCase assert_equal %i[ account_url region ], target.missing_params end - test "environ_name override" do - target = Target.new( - default_project_name: "dirname", - default_environ_name: "main", - environ_name: "production" - ) - assert_nil target.account_url - assert_nil target.account_id - assert_equal "dirname", target.project_name - assert_equal "production", target.environ_name - assert_nil target.region - assert_equal %i[ account_url region ], target.missing_params - end - test "save_defaults" do config_path = Pathname.new Dir.mktmpdir target = Target.new(config_path:, account_url: "https://example.com/accounts/3", region: "us-east-2", project_name: "yes") @@ -83,5 +69,19 @@ class TargetTest < ActiveSupport::TestCase ensure FileUtils.rm_rf config_path end + + test "path as environ name overrides default" do + target = Target.new( + "production", + default_project_name: "dirname", + default_environ_name: "main" + ) + assert_nil target.account_url + assert_nil target.account_id + assert_equal "dirname", target.project_name + assert_equal "production", target.environ_name + assert_nil target.region + assert_equal %i[ account_url region ], target.missing_params + end end end From affb1eccb13a9112bfbd460e6fee1735336008b0 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 11:30:15 +0200 Subject: [PATCH 15/45] target name prefix in path set default project name, overriden by project_name arg --- lib/envirobly/target.rb | 7 +++++-- test/envirobly/target_test.rb | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 92552de..d8888d6 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -13,7 +13,6 @@ def initialize( default_project_name: nil, config_path: Config::TARGETS_PATH ) - load_path path @account_url = account_url @region = region @project_name = project_name @@ -21,6 +20,8 @@ def initialize( @default_project_name = default_project_name @config_path = config_path @default_target_dir = config_path.join(".default") + + load_path path end def missing_params @@ -92,11 +93,13 @@ def default_region def load_path(path) return if path.blank? - parts = path.split("/") + parts = path.split("/").map &:strip case parts.size when 1 @environ_name = parts.first + when 2 + @default_project_name, @environ_name = parts end end end diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index ea3b2cf..f6ec038 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -83,5 +83,26 @@ class TargetTest < ActiveSupport::TestCase assert_nil target.region assert_equal %i[ account_url region ], target.missing_params end + + test "target name prefix in path set default project name" do + target = Target.new( + "candy/production", + default_project_name: "dirname", + default_environ_name: "main" + ) + assert_equal "candy", target.project_name + assert_equal "production", target.environ_name + end + + test "target name prefix in path set default project name, overriden by project_name arg" do + target = Target.new( + "candy/production", + default_project_name: "dirname", + default_environ_name: "main", + project_name: "stars" + ) + assert_equal "stars", target.project_name + assert_equal "production", target.environ_name + end end end From a94bd3ee3386c8b4da6258f6fb1d20fe3031af8a Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 11:36:39 +0200 Subject: [PATCH 16/45] service name as path in the service context --- lib/envirobly/target.rb | 14 +++++++++++++- test/envirobly/target_test.rb | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index d8888d6..1171776 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -3,6 +3,7 @@ module Envirobly class Target attr_accessor :account_url, :project_name, :region + attr_reader :service_name def initialize( path = nil, @@ -11,7 +12,8 @@ def initialize( project_name: nil, default_environ_name: nil, default_project_name: nil, - config_path: Config::TARGETS_PATH + config_path: Config::TARGETS_PATH, + context: nil ) @account_url = account_url @region = region @@ -20,6 +22,7 @@ def initialize( @default_project_name = default_project_name @config_path = config_path @default_target_dir = config_path.join(".default") + @context = context load_path path end @@ -95,6 +98,15 @@ def load_path(path) parts = path.split("/").map &:strip + if @context == :service + case parts.size + when 1 + @service_name = parts.first + end + + return + end + case parts.size when 1 @environ_name = parts.first diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index f6ec038..12e2d2b 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -11,6 +11,7 @@ class TargetTest < ActiveSupport::TestCase assert_equal "world", target.project_name assert_equal "abcd", target.environ_name assert_equal "eu-north-1", target.region + assert_nil target.service_name end test "all defaults exist, override account_url" do @@ -82,6 +83,7 @@ class TargetTest < ActiveSupport::TestCase assert_equal "production", target.environ_name assert_nil target.region assert_equal %i[ account_url region ], target.missing_params + assert_nil target.service_name end test "target name prefix in path set default project name" do @@ -104,5 +106,10 @@ class TargetTest < ActiveSupport::TestCase assert_equal "stars", target.project_name assert_equal "production", target.environ_name end + + test "service name as path in the service context" do + target = Target.new("puma", context: :service) + assert_equal "puma", target.service_name + end end end From 5adfc06f4f51a8478c74facd8c4b575d16868264 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 11:38:08 +0200 Subject: [PATCH 17/45] environ name and service name as path in the service context --- lib/envirobly/target.rb | 2 ++ test/envirobly/target_test.rb | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 1171776..8efc41f 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -102,6 +102,8 @@ def load_path(path) case parts.size when 1 @service_name = parts.first + when 2 + @environ_name, @service_name = parts end return diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index 12e2d2b..2cb165f 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -111,5 +111,11 @@ class TargetTest < ActiveSupport::TestCase target = Target.new("puma", context: :service) assert_equal "puma", target.service_name end + + test "environ name and service name as path in the service context" do + target = Target.new("production/puma", context: :service, default_environ_name: "main") + assert_equal "puma", target.service_name + assert_equal "production", target.environ_name + end end end From eda49f209361b86e38fb142e9329fc5051294f92 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 11:40:20 +0200 Subject: [PATCH 18/45] target name, environ name and service name as path in the service context --- lib/envirobly/target.rb | 2 ++ test/envirobly/target_test.rb | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 8efc41f..2ae3bf3 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -104,6 +104,8 @@ def load_path(path) @service_name = parts.first when 2 @environ_name, @service_name = parts + when 3 + @default_project_name, @environ_name, @service_name = parts end return diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index 2cb165f..b6057af 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -117,5 +117,12 @@ class TargetTest < ActiveSupport::TestCase assert_equal "puma", target.service_name assert_equal "production", target.environ_name end + + test "target name, environ name and service name as path in the service context" do + target = Target.new("factory/production/puma", context: :service, default_environ_name: "main", default_project_name: "dir") + assert_equal "puma", target.service_name + assert_equal "production", target.environ_name + assert_equal "factory", target.project_name + end end end From e5009c7213247a97f11f8aa00d70bfb45253a92f Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 11:45:44 +0200 Subject: [PATCH 19/45] rename --- lib/envirobly/target.rb | 22 ++++++++++++++-------- test/envirobly/target_test.rb | 7 +++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 2ae3bf3..f9ea6d4 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -3,7 +3,7 @@ module Envirobly class Target attr_accessor :account_url, :project_name, :region - attr_reader :service_name + attr_reader :name, :service_name def initialize( path = nil, @@ -21,8 +21,8 @@ def initialize( @default_environ_name = default_environ_name @default_project_name = default_project_name @config_path = config_path - @default_target_dir = config_path.join(".default") @context = context + @name = ".default" load_path path end @@ -63,22 +63,26 @@ def region @region.presence || default_region end - def save_defaults - FileUtils.mkdir_p @default_target_dir + def save + FileUtils.mkdir_p storage_dir write_default "account_url" write_default "project_name" write_default "region" end private + def storage_dir + @config_path.join(@name) + end + def default_value_for(type) - File.read(@default_target_dir.join(type)).strip + File.read(storage_dir.join(type)).strip rescue Errno::ENOENT nil end def write_default(type) - File.write @default_target_dir.join(type), send(type) + File.write storage_dir.join(type), send(type) end def default_account_url @@ -105,7 +109,8 @@ def load_path(path) when 2 @environ_name, @service_name = parts when 3 - @default_project_name, @environ_name, @service_name = parts + @name, @environ_name, @service_name = parts + @default_project_name = @name end return @@ -115,7 +120,8 @@ def load_path(path) when 1 @environ_name = parts.first when 2 - @default_project_name, @environ_name = parts + @name, @environ_name = parts + @default_project_name = @name end end end diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index b6057af..4636260 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -12,6 +12,7 @@ class TargetTest < ActiveSupport::TestCase assert_equal "abcd", target.environ_name assert_equal "eu-north-1", target.region assert_nil target.service_name + assert_equal ".default", target.name end test "all defaults exist, override account_url" do @@ -60,10 +61,10 @@ class TargetTest < ActiveSupport::TestCase assert_equal %i[ account_url region ], target.missing_params end - test "save_defaults" do + test "save" do config_path = Pathname.new Dir.mktmpdir target = Target.new(config_path:, account_url: "https://example.com/accounts/3", region: "us-east-2", project_name: "yes") - target.save_defaults + target.save assert_equal "https://example.com/accounts/3", File.read(config_path.join ".default/account_url") assert_equal "us-east-2", File.read(config_path.join ".default/region") assert_equal "yes", File.read(config_path.join ".default/project_name") @@ -84,6 +85,7 @@ class TargetTest < ActiveSupport::TestCase assert_nil target.region assert_equal %i[ account_url region ], target.missing_params assert_nil target.service_name + assert_equal ".default", target.name end test "target name prefix in path set default project name" do @@ -120,6 +122,7 @@ class TargetTest < ActiveSupport::TestCase test "target name, environ name and service name as path in the service context" do target = Target.new("factory/production/puma", context: :service, default_environ_name: "main", default_project_name: "dir") + assert_equal "factory", target.name assert_equal "puma", target.service_name assert_equal "production", target.environ_name assert_equal "factory", target.project_name From 7cb4cd41db138a898df2709c6a584d10b0b41f1b Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 11:46:10 +0200 Subject: [PATCH 20/45] rename --- lib/envirobly/target.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index f9ea6d4..4c55bba 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -75,7 +75,7 @@ def storage_dir @config_path.join(@name) end - def default_value_for(type) + def stored_value_for(type) File.read(storage_dir.join(type)).strip rescue Errno::ENOENT nil @@ -86,15 +86,15 @@ def write_default(type) end def default_account_url - default_value_for "account_url" + stored_value_for "account_url" end def default_project_name - default_value_for "project_name" + stored_value_for "project_name" end def default_region - default_value_for "region" + stored_value_for "region" end def load_path(path) From fb916828f0a1ff03f89d78a2c75f9958f309ac1b Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 11:48:11 +0200 Subject: [PATCH 21/45] refactor --- lib/envirobly/target.rb | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 4c55bba..1bcd0dc 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -40,7 +40,7 @@ def missing_params end def account_url - @account_url.presence || default_account_url + @account_url.presence || stored_value_for("account_url") end def account_id @@ -52,7 +52,7 @@ def account_id end def project_name - @project_name.presence || default_project_name.presence || @default_project_name + @project_name.presence || stored_value_for("project_name").presence || @default_project_name end def environ_name @@ -60,7 +60,7 @@ def environ_name end def region - @region.presence || default_region + @region.presence || stored_value_for("region") end def save @@ -85,18 +85,6 @@ def write_default(type) File.write storage_dir.join(type), send(type) end - def default_account_url - stored_value_for "account_url" - end - - def default_project_name - stored_value_for "project_name" - end - - def default_region - stored_value_for "region" - end - def load_path(path) return if path.blank? From ad73e374b7de51634f26007da4abcdb9b41b03bb Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 11:50:41 +0200 Subject: [PATCH 22/45] save custom name --- test/envirobly/target_test.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index 4636260..e8d3f58 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -61,7 +61,7 @@ class TargetTest < ActiveSupport::TestCase assert_equal %i[ account_url region ], target.missing_params end - test "save" do + test "save default" do config_path = Pathname.new Dir.mktmpdir target = Target.new(config_path:, account_url: "https://example.com/accounts/3", region: "us-east-2", project_name: "yes") target.save @@ -72,6 +72,18 @@ class TargetTest < ActiveSupport::TestCase FileUtils.rm_rf config_path end + test "save custom name" do + config_path = Pathname.new Dir.mktmpdir + target = Target.new("factory/main", + config_path:, account_url: "https://example.com/accounts/3", region: "us-east-2", project_name: "yes") + target.save + assert_equal "https://example.com/accounts/3", File.read(config_path.join "factory/account_url") + assert_equal "us-east-2", File.read(config_path.join "factory/region") + assert_equal "yes", File.read(config_path.join "factory/project_name") + ensure + FileUtils.rm_rf config_path + end + test "path as environ name overrides default" do target = Target.new( "production", From 08500564c35a7037375723e004939b37ad82f3e7 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 12:18:20 +0200 Subject: [PATCH 23/45] target configure --- lib/envirobly/cli/main.rb | 23 ++++++++++++------ lib/envirobly/target.rb | 50 +++++++++++++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/lib/envirobly/cli/main.rb b/lib/envirobly/cli/main.rb index 78ba6d0..8bd06cd 100644 --- a/lib/envirobly/cli/main.rb +++ b/lib/envirobly/cli/main.rb @@ -26,16 +26,25 @@ def signout say "You can sign in again with `envirobly signin`" end - desc "set_default_account", "Choose default account to deploy the current project to" - def set_default_account - Envirobly::Defaults::Account.new(shell:).require_value - end + desc "target [NAME]", "Configure deployment (default) target" + def target(name = nil) + Envirobly::AccessToken.new(shell:).require! - desc "set_default_region", "Set default region for the current project when deploying for the first time" - def set_default_region - Envirobly::Defaults::Region.new(shell:).require_value + target = Envirobly::Target.new(default_project_name: Envirobly::Defaults::Project.dirname, shell:) + target.name = name if name.present? + target.configure! end + # desc "set_default_account", "Choose default account to deploy the current project to" + # def set_default_account + # Envirobly::Defaults::Account.new(shell:).require_value + # end + # + # desc "set_default_region", "Set default region for the current project when deploying for the first time" + # def set_default_region + # Envirobly::Defaults::Region.new(shell:).require_value + # end + desc "validate", "Validates config (for given environ)" def validate(environ_name = nil) Envirobly::AccessToken.new(shell:).require! diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 1bcd0dc..5afb3ef 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -2,8 +2,8 @@ module Envirobly class Target - attr_accessor :account_url, :project_name, :region - attr_reader :name, :service_name + attr_accessor :account_url, :project_name, :region, :name + attr_reader :service_name, :shell def initialize( path = nil, @@ -13,7 +13,8 @@ def initialize( default_environ_name: nil, default_project_name: nil, config_path: Config::TARGETS_PATH, - context: nil + context: nil, + shell: nil ) @account_url = account_url @region = region @@ -23,6 +24,7 @@ def initialize( @config_path = config_path @context = context @name = ".default" + @shell = shell load_path path end @@ -64,12 +66,51 @@ def region end def save - FileUtils.mkdir_p storage_dir write_default "account_url" write_default "project_name" write_default "region" end + def configure! + shell.say "Configuring " + shell.say "#{@name} ", :green + shell.say "deploy target" + shell.say + + api = Envirobly::Api.new + accounts = api.list_accounts + + if accounts.object.blank? + shell.say_error "Please connect an AWS account to your Envirobly account first." + exit 1 + end + + data = [ [ "ID", "Name", "AWS number", "URL" ] ] + + accounts.object.pluck("id", "name", "aws_id", "url") + + shell.say "Available accounts:" + shell.print_table data, borders: true + + limited_to = accounts.object.pluck("id").map(&:to_s) + account_id = limited_to.first + + begin + account_id = shell.ask("Choose Account ID:", limited_to:, default: account_id).to_i + rescue Interrupt + shell.say_error "Cancelled", :red + exit + end + + accounts.object.each do |account| + if account_id == account["id"] + @account_url = account["url"] + break + end + end + + write_default "account_url" + end + private def storage_dir @config_path.join(@name) @@ -82,6 +123,7 @@ def stored_value_for(type) end def write_default(type) + FileUtils.mkdir_p storage_dir File.write storage_dir.join(type), send(type) end From 05ebc7488b7bcf88ae9655e769314ecf2206036a Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 12:20:27 +0200 Subject: [PATCH 24/45] refactor --- lib/envirobly/target.rb | 78 ++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 5afb3ef..053594e 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -72,43 +72,7 @@ def save end def configure! - shell.say "Configuring " - shell.say "#{@name} ", :green - shell.say "deploy target" - shell.say - - api = Envirobly::Api.new - accounts = api.list_accounts - - if accounts.object.blank? - shell.say_error "Please connect an AWS account to your Envirobly account first." - exit 1 - end - - data = [ [ "ID", "Name", "AWS number", "URL" ] ] + - accounts.object.pluck("id", "name", "aws_id", "url") - - shell.say "Available accounts:" - shell.print_table data, borders: true - - limited_to = accounts.object.pluck("id").map(&:to_s) - account_id = limited_to.first - - begin - account_id = shell.ask("Choose Account ID:", limited_to:, default: account_id).to_i - rescue Interrupt - shell.say_error "Cancelled", :red - exit - end - - accounts.object.each do |account| - if account_id == account["id"] - @account_url = account["url"] - break - end - end - - write_default "account_url" + configure_account end private @@ -154,5 +118,45 @@ def load_path(path) @default_project_name = @name end end + + def configure_account + shell.say "Configuring " + shell.say "#{@name} ", :green + shell.say "deploy target" + shell.say + + api = Envirobly::Api.new + accounts = api.list_accounts + + if accounts.object.blank? + shell.say_error "Please connect an AWS account to your Envirobly account first." + exit 1 + end + + data = [ [ "ID", "Name", "AWS number", "URL" ] ] + + accounts.object.pluck("id", "name", "aws_id", "url") + + shell.say "Available accounts:" + shell.print_table data, borders: true + + limited_to = accounts.object.pluck("id").map(&:to_s) + account_id = limited_to.first + + begin + account_id = shell.ask("Choose Account ID:", limited_to:, default: account_id).to_i + rescue Interrupt + shell.say_error "Cancelled", :red + exit + end + + accounts.object.each do |account| + if account_id == account["id"] + @account_url = account["url"] + break + end + end + + write_default "account_url" + end end end From a7a82bcbea0b0a9e3751b0c1adf52d81908cfc2f Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 12:24:45 +0200 Subject: [PATCH 25/45] refactor --- lib/envirobly/cli/main.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/envirobly/cli/main.rb b/lib/envirobly/cli/main.rb index 8bd06cd..a641594 100644 --- a/lib/envirobly/cli/main.rb +++ b/lib/envirobly/cli/main.rb @@ -7,9 +7,9 @@ class Envirobly::Cli::Main < Envirobly::Base method_option :pure, type: :boolean, default: false def version if options.pure - puts Envirobly::VERSION + say Envirobly::VERSION else - puts "envirobly CLI v#{Envirobly::VERSION}" + say "envirobly CLI v#{Envirobly::VERSION}" end end @@ -115,6 +115,7 @@ def deploy(environ_name = nil) Envirobly::AccessToken.new(shell:).require! + # TODO: Move Target use out of deployment and in here deployment = Envirobly::Deployment.new( account_id: options.account_id, region: options.region, From 37878be0635eace316cd69230f1f9bc7f9611614 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 12:35:24 +0200 Subject: [PATCH 26/45] configure project_name --- lib/envirobly/cli/main.rb | 5 ++++- lib/envirobly/target.rb | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/envirobly/cli/main.rb b/lib/envirobly/cli/main.rb index a641594..12909ee 100644 --- a/lib/envirobly/cli/main.rb +++ b/lib/envirobly/cli/main.rb @@ -30,9 +30,12 @@ def signout def target(name = nil) Envirobly::AccessToken.new(shell:).require! - target = Envirobly::Target.new(default_project_name: Envirobly::Defaults::Project.dirname, shell:) + target = Envirobly::Target.new(default_project_name: File.basename(Dir.pwd), shell:) target.name = name if name.present? target.configure! + + shell.say "#{green_check} " + shell.say "Target configured.", :green end # desc "set_default_account", "Choose default account to deploy the current project to" diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 053594e..1b98235 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -66,13 +66,14 @@ def region end def save - write_default "account_url" - write_default "project_name" - write_default "region" + save_attribute "account_url" + save_attribute "project_name" + save_attribute "region" end def configure! configure_account + configure_project_name end private @@ -86,7 +87,7 @@ def stored_value_for(type) nil end - def write_default(type) + def save_attribute(type) FileUtils.mkdir_p storage_dir File.write storage_dir.join(type), send(type) end @@ -156,7 +157,18 @@ def configure_account end end - write_default "account_url" + save_attribute "account_url" + end + + def configure_project_name + begin + @project_name = shell.ask("Name your Project:", default: project_name) + rescue Interrupt + shell.say_error "Cancelled", :red + exit + end + + save_attribute "project_name" end end end From 324c094e39e135b04a29cae866526722a9bbe3da Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 12:39:23 +0200 Subject: [PATCH 27/45] configure region --- lib/envirobly/target.rb | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 1b98235..6d627c9 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -74,6 +74,7 @@ def save def configure! configure_account configure_project_name + configure_region end private @@ -162,13 +163,42 @@ def configure_account def configure_project_name begin - @project_name = shell.ask("Name your Project:", default: project_name) - rescue Interrupt - shell.say_error "Cancelled", :red + @project_name = shell.ask("Name your project:", default: project_name) + rescue interrupt + shell.say_error "cancelled", :red exit end save_attribute "project_name" end + + def configure_region + api = Envirobly::Api.new + response = api.list_regions + + shell.say "Choose region:" + shell.print_table [ [ "Name", "Location", "Group" ] ] + + response.object.pluck("code", "title", "group_title"), borders: true + + code = nil + limited_to = response.object.pluck("code") + + while code.nil? + begin + code = shell.ask("Region name:", default: "us-east-1") + rescue Interrupt + shell.say_error "Cancelled", :red + exit + end + + unless code.in?(limited_to) + shell.say_error "'#{code}' is not a supported region, please try again" + code = nil + end + end + + @region = code + save_attribute "region" + end end end From 618ebc51a3b2588399fd0d0c92ca5037603358a1 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 12:53:52 +0200 Subject: [PATCH 28/45] missing only --- lib/envirobly/cli/main.rb | 3 ++- lib/envirobly/deployment.rb | 2 -- lib/envirobly/target.rb | 10 +++++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/envirobly/cli/main.rb b/lib/envirobly/cli/main.rb index 12909ee..37c79e6 100644 --- a/lib/envirobly/cli/main.rb +++ b/lib/envirobly/cli/main.rb @@ -27,12 +27,13 @@ def signout end desc "target [NAME]", "Configure deployment (default) target" + method_option :missing_only, type: :boolean, default: false def target(name = nil) Envirobly::AccessToken.new(shell:).require! target = Envirobly::Target.new(default_project_name: File.basename(Dir.pwd), shell:) target.name = name if name.present? - target.configure! + target.configure!(missing_only: options.missing_only) shell.say "#{green_check} " shell.say "Target configured.", :green diff --git a/lib/envirobly/deployment.rb b/lib/envirobly/deployment.rb index da4efd4..557fe3e 100644 --- a/lib/envirobly/deployment.rb +++ b/lib/envirobly/deployment.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "yaml" - module Envirobly class Deployment include Colorize diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 6d627c9..a308ad5 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -71,10 +71,10 @@ def save save_attribute "region" end - def configure! - configure_account - configure_project_name - configure_region + def configure!(missing_only: false) + configure_account unless missing_only && stored_value_for("account_url").present? + configure_project_name unless missing_only && stored_value_for("project_name").present? + configure_region unless missing_only && stored_value_for("region").present? end private @@ -185,7 +185,7 @@ def configure_region while code.nil? begin - code = shell.ask("Region name:", default: "us-east-1") + code = shell.ask("Region name:", default: region.presence || "us-east-1") rescue Interrupt shell.say_error "Cancelled", :red exit From 5c746b56e419c4963b71e5cfe26e41e555217b03 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 14:08:42 +0200 Subject: [PATCH 29/45] Name --- lib/envirobly/name.rb | 24 ++++++++++++++++++++++++ test/envirobly/name_test.rb | 19 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 lib/envirobly/name.rb create mode 100644 test/envirobly/name_test.rb diff --git a/lib/envirobly/name.rb b/lib/envirobly/name.rb new file mode 100644 index 0000000..ccbd092 --- /dev/null +++ b/lib/envirobly/name.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Envirobly + class Name + NAME_FORMAT = /\A[a-z0-9\-_]+\z/i + ERROR_MESSAGE = "is limited to alphanumerical characters, dashes and undercores" + + attr_reader :error + + def initialize(name) + @name = name + @error = nil + end + + def validate + if @name =~ NAME_FORMAT + true + else + @error = ERROR_MESSAGE + false + end + end + end +end diff --git a/test/envirobly/name_test.rb b/test/envirobly/name_test.rb new file mode 100644 index 0000000..80eb691 --- /dev/null +++ b/test/envirobly/name_test.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require "test_helper" + +module Envirobly + class NameTest < ActiveSupport::TestCase + test "successful validate" do + name = Name.new("produc-tio_n") + assert name.validate + assert_nil name.error + end + + test "failed validate" do + name = Name.new("!") + assert_not name.validate + assert_not_empty name.error + end + end +end From 917102814672d4294e9b1225089dfd69419c9f94 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 14:13:45 +0200 Subject: [PATCH 30/45] name validation during configure --- lib/envirobly/target.rb | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index a308ad5..603957a 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -162,13 +162,23 @@ def configure_account end def configure_project_name - begin - @project_name = shell.ask("Name your project:", default: project_name) - rescue interrupt - shell.say_error "cancelled", :red - exit + result = nil + + while result.nil? + begin + result = shell.ask("Name your project:", default: project_name) + rescue interrupt + shell.say_error "cancelled", :red + end + + name = Name.new(result) + unless name.validate + result = nil + shell.say_error "Name #{name.error}" + end end + @project_name = result save_attribute "project_name" end From f0582c4f69ecbb6aabf33e8b6009bdc4af973d9c Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 14:20:29 +0200 Subject: [PATCH 31/45] target validation --- lib/envirobly/target.rb | 11 +++++++++++ test/envirobly/target_test.rb | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 603957a..88e9596 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -29,6 +29,17 @@ def initialize( load_path path end + def errors + [].tap do |result| + unless @name == ".default" + name = Name.new(@name) + unless name.validate + result << "'#{@name}' is invalid. Name #{name.error}" + end + end + end + end + def missing_params [].tap do |result| if account_url.blank? diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index e8d3f58..01a7ea2 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -13,6 +13,7 @@ class TargetTest < ActiveSupport::TestCase assert_equal "eu-north-1", target.region assert_nil target.service_name assert_equal ".default", target.name + assert_empty target.errors end test "all defaults exist, override account_url" do @@ -139,5 +140,11 @@ class TargetTest < ActiveSupport::TestCase assert_equal "production", target.environ_name assert_equal "factory", target.project_name end + + test "name validation" do + target = Target.new("factory!/production") + assert_equal 1, target.errors.size + assert_equal "'factory!' is invalid. Name #{Name::ERROR_MESSAGE}", target.errors.first + end end end From 498c8da4ae6245b251458dbda1b8918f4c730830 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 14:26:48 +0200 Subject: [PATCH 32/45] name validation --- lib/envirobly/target.rb | 15 ++++++++++----- test/envirobly/target_test.rb | 5 +++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 88e9596..ae8be29 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -5,6 +5,8 @@ class Target attr_accessor :account_url, :project_name, :region, :name attr_reader :service_name, :shell + DEFAULT_NAME = ".default" + def initialize( path = nil, account_url: nil, @@ -23,7 +25,7 @@ def initialize( @default_project_name = default_project_name @config_path = config_path @context = context - @name = ".default" + @name = DEFAULT_NAME @shell = shell load_path path @@ -31,13 +33,16 @@ def initialize( def errors [].tap do |result| - unless @name == ".default" - name = Name.new(@name) + [ name, project_name, environ_name ].each_with_index do |value, index| + next if index.zero? && value == DEFAULT_NAME + + name = Name.new(value) + unless name.validate - result << "'#{@name}' is invalid. Name #{name.error}" + result << "'#{value}' is invalid. Name #{name.error}" end end - end + end.uniq end def missing_params diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index 01a7ea2..77a0a45 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -142,9 +142,10 @@ class TargetTest < ActiveSupport::TestCase end test "name validation" do - target = Target.new("factory!/production") - assert_equal 1, target.errors.size + target = Target.new("factory!/production@") + assert_equal 2, target.errors.size assert_equal "'factory!' is invalid. Name #{Name::ERROR_MESSAGE}", target.errors.first + assert_equal "'production@' is invalid. Name #{Name::ERROR_MESSAGE}", target.errors.second end end end From 4149591cea8e0db7bcab9d37e6f1775d67604af5 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 14:34:01 +0200 Subject: [PATCH 33/45] target errors --- lib/envirobly/cli/main.rb | 11 +++++++++++ lib/envirobly/name.rb | 2 +- lib/envirobly/target.rb | 8 +++++--- test/envirobly/target_test.rb | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/envirobly/cli/main.rb b/lib/envirobly/cli/main.rb index 37c79e6..c850945 100644 --- a/lib/envirobly/cli/main.rb +++ b/lib/envirobly/cli/main.rb @@ -33,6 +33,17 @@ def target(name = nil) target = Envirobly::Target.new(default_project_name: File.basename(Dir.pwd), shell:) target.name = name if name.present? + + errors = target.errors :name + + if errors.any? + errors.each do |message| + shell.say_error message + end + + exit 1 + end + target.configure!(missing_only: options.missing_only) shell.say "#{green_check} " diff --git a/lib/envirobly/name.rb b/lib/envirobly/name.rb index ccbd092..4a8c355 100644 --- a/lib/envirobly/name.rb +++ b/lib/envirobly/name.rb @@ -3,7 +3,7 @@ module Envirobly class Name NAME_FORMAT = /\A[a-z0-9\-_]+\z/i - ERROR_MESSAGE = "is limited to alphanumerical characters, dashes and undercores" + ERROR_MESSAGE = "must contain only alphanumerical characters, dashes and undercores" attr_reader :error diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index ae8be29..5d05f6c 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -31,15 +31,17 @@ def initialize( load_path path end - def errors + def errors(attributes = %i[ name project_name environ_name ]) [].tap do |result| - [ name, project_name, environ_name ].each_with_index do |value, index| + Array(attributes).each_with_index do |attr, index| + value = send attr + next if index.zero? && value == DEFAULT_NAME name = Name.new(value) unless name.validate - result << "'#{value}' is invalid. Name #{name.error}" + result << "Name '#{value}' #{name.error}" end end end.uniq diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index 77a0a45..6fdc232 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -144,8 +144,8 @@ class TargetTest < ActiveSupport::TestCase test "name validation" do target = Target.new("factory!/production@") assert_equal 2, target.errors.size - assert_equal "'factory!' is invalid. Name #{Name::ERROR_MESSAGE}", target.errors.first - assert_equal "'production@' is invalid. Name #{Name::ERROR_MESSAGE}", target.errors.second + assert_equal "Name 'factory!' #{Name::ERROR_MESSAGE}", target.errors.first + assert_equal "Name 'production@' #{Name::ERROR_MESSAGE}", target.errors.second end end end From 1f13895d0e1ce7551d2dbbec5b657019149d0101 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 14:37:36 +0200 Subject: [PATCH 34/45] tweak --- lib/envirobly/target.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index 5d05f6c..da96d96 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -160,7 +160,7 @@ def configure_account shell.print_table data, borders: true limited_to = accounts.object.pluck("id").map(&:to_s) - account_id = limited_to.first + account_id = send(:account_id).to_s.presence || limited_to.first begin account_id = shell.ask("Choose Account ID:", limited_to:, default: account_id).to_i From 483a322a8eb7f4dcd85f43402d9429c0d1a8aea3 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 14:58:14 +0200 Subject: [PATCH 35/45] use new Target in deploy --- lib/envirobly/cli/main.rb | 33 ++++++---------- lib/envirobly/deployment.rb | 77 +++++++++++-------------------------- lib/envirobly/target.rb | 11 ++++++ 3 files changed, 46 insertions(+), 75 deletions(-) diff --git a/lib/envirobly/cli/main.rb b/lib/envirobly/cli/main.rb index c850945..e6a3a0e 100644 --- a/lib/envirobly/cli/main.rb +++ b/lib/envirobly/cli/main.rb @@ -50,16 +50,6 @@ def target(name = nil) shell.say "Target configured.", :green end - # desc "set_default_account", "Choose default account to deploy the current project to" - # def set_default_account - # Envirobly::Defaults::Account.new(shell:).require_value - # end - # - # desc "set_default_region", "Set default region for the current project when deploying for the first time" - # def set_default_region - # Envirobly::Defaults::Region.new(shell:).require_value - # end - desc "validate", "Validates config (for given environ)" def validate(environ_name = nil) Envirobly::AccessToken.new(shell:).require! @@ -93,18 +83,17 @@ def instance_types(region = nil) table_data, borders: true end - desc "deploy [ENVIRON_NAME]", <<~TXT + desc "deploy [[TARGET/[ENVIRON_NAME]]", <<~TXT Deploy to environ identified by name. Name can contain letters, numbers, dashes or underscores. If environ name is left blank, current git branch name is used. TXT - method_option :account_id, type: :numeric + method_option :account_url, type: :string method_option :region, type: :string - method_option :project_id, type: :numeric method_option :project_name, type: :string method_option :commit, type: :string, default: "HEAD" method_option :dry_run, type: :boolean, default: false - def deploy(environ_name = nil) + def deploy(path = nil) commit = Envirobly::Git::Commit.new options.commit unless commit.exists? @@ -130,16 +119,18 @@ def deploy(environ_name = nil) Envirobly::AccessToken.new(shell:).require! - # TODO: Move Target use out of deployment and in here - deployment = Envirobly::Deployment.new( - account_id: options.account_id, - region: options.region, - project_id: options.project_id, + target = Envirobly::Target.new( + path, + account_url: options.account_url, project_name: options.project_name, - environ_name: environ_name.presence, - commit:, + region: options.region, + default_project_name: File.basename(Dir.pwd), + default_environ_name: commit.current_branch, shell: ) + target.render_and_exit_on_errors! + + deployment = Envirobly::Deployment.new(target:, commit:, shell:) deployment.perform(dry_run: options.dry_run) end diff --git a/lib/envirobly/deployment.rb b/lib/envirobly/deployment.rb index 557fe3e..8a80558 100644 --- a/lib/envirobly/deployment.rb +++ b/lib/envirobly/deployment.rb @@ -6,53 +6,29 @@ class Deployment attr_reader :params, :shell - def initialize(environ_name:, commit:, account_id:, project_name:, project_id:, region:, shell:) + def initialize(target:, commit:, shell:) + @target = target @commit = commit - @config = Config.new - @default_account = Defaults::Account.new(shell:) - @default_project = Defaults::Project.new(shell:) - @default_region = Defaults::Region.new(shell:) @shell = shell + @api = Api.new + @config = Config.new + end - target = Target.new( - default_account_id: @default_account.value, - default_project_id: @default_project.value, - default_region: @default_region.value, - default_project_name: Defaults::Project.dirname, - default_environ_name: commit.current_branch, - account_id:, - project_id:, - region:, - project_name:, - environ_name: - ) - - if target.missing_params.include?(:account_id) - target.account_id = @default_account.require_value - end - - if target.missing_params.include?(:region) - target.region = @default_region.require_value - end - - @environ_name = target.environ_name - @params = { - account_id: target.account_id, - project_id: target.project_id, - project_name: target.project_name, - region: target.region, + def perform(dry_run:) + params = { + account_id: @target.account_id, + project_name: @target.project_name, + region: @target.region, deployment: { - environ_name: target.environ_name, + environ_name: @target.environ_name, commit_ref: @commit.ref, commit_time: @commit.time, commit_message: @commit.message, object_tree_checksum: @commit.object_tree_checksum, - config: @config.merge(@environ_name).to_yaml + config: @config.merge(@target.environ_name).to_yaml } } - end - def perform(dry_run:) if dry_run shell.say "This is a dry run, nothing will be deployed.", :green end @@ -66,17 +42,16 @@ def perform(dry_run:) if dry_run puts green("Config:") - puts @params[:deployment][:config] + puts params[:deployment][:config] shell.say - shell.say "Targeting:", :green + shell.say "Target:", :green targets_and_values = [ - [ "Account ID", @params[:account_id].to_s ], - [ "Project ID", @params[:project_id].to_s ], - [ "Region", @params[:region] ], - [ "Project Name", @params[:project_name] ], - [ "Environ Name", @params[:deployment][:environ_name] ] + [ "Account", @target.account_url ], + [ "Region", params[:region] ], + [ "Project Name", params[:project_name] ], + [ "Environ Name", params[:deployment][:environ_name] ] ] shell.print_table targets_and_values, borders: true @@ -84,36 +59,30 @@ def perform(dry_run:) return end - # Create deployment - api = Api.new - Duration.measure do - response = api.create_deployment @params + # Create deployment + response = @api.create_deployment params print "Preparing project..." - @default_account.save_if_none response.object.fetch("account_id") - @default_project.save_if_none response.object.fetch("project_id") - @default_region.save_if_none response.object.fetch("region") - # Fetch credentials for build context upload @deployment_url = response.object.fetch("url") - @credentials_response = api.get_deployment_with_delay_and_retry @deployment_url + @credentials_response = @api.get_deployment_with_delay_and_retry @deployment_url end credentials = @credentials_response.object.fetch("credentials") region = @credentials_response.object.fetch("region") bucket = @credentials_response.object.fetch("bucket") - watch_deployment_url = @credentials_response.object.fetch("deployment_url") Duration.measure do # Upload build context Aws::S3.new(bucket:, region:, credentials:).push @commit # Perform deployment - api.put_as_json @deployment_url + @api.put_as_json @deployment_url end + watch_deployment_url = @credentials_response.object.fetch("deployment_url") puts "Follow at #{watch_deployment_url}" end end diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index da96d96..ee1d822 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -47,6 +47,17 @@ def errors(attributes = %i[ name project_name environ_name ]) end.uniq end + def render_and_exit_on_errors! + messages = errors + return if messages.empty? + + messages.each do |message| + shell.say_error message + end + + exit 1 + end + def missing_params [].tap do |result| if account_url.blank? From 972e92d64f649a3bae10fa713b4a2c497f21139d Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 15:02:43 +0200 Subject: [PATCH 36/45] path / suffix --- lib/envirobly/target.rb | 7 ++++++- test/envirobly/target_test.rb | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/envirobly/target.rb b/lib/envirobly/target.rb index ee1d822..09eb1c7 100644 --- a/lib/envirobly/target.rb +++ b/lib/envirobly/target.rb @@ -143,7 +143,12 @@ def load_path(path) case parts.size when 1 - @environ_name = parts.first + if path.end_with?("/") + @name = parts.first + @default_project_name = parts.first + else + @environ_name = parts.first + end when 2 @name, @environ_name = parts @default_project_name = @name diff --git a/test/envirobly/target_test.rb b/test/envirobly/target_test.rb index 6fdc232..ca17ce0 100644 --- a/test/envirobly/target_test.rb +++ b/test/envirobly/target_test.rb @@ -141,6 +141,13 @@ class TargetTest < ActiveSupport::TestCase assert_equal "factory", target.project_name end + test "path with / suffix means specifying target name only" do + target = Target.new("factory/", default_environ_name: "main", default_project_name: "dir") + assert_equal "factory", target.name + assert_equal "main", target.environ_name + assert_equal "factory", target.project_name + end + test "name validation" do target = Target.new("factory!/production@") assert_equal 2, target.errors.size From 8a9d5359bc421a8ead34d6ad8313e6afe4e60726 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 15:07:25 +0200 Subject: [PATCH 37/45] tweaks --- Gemfile.lock | 2 +- lib/envirobly/cli/main.rb | 1 + lib/envirobly/deployment.rb | 4 ++-- lib/envirobly/version.rb | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7bd508e..26a5e99 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - envirobly (1.10.0) + envirobly (1.11.0) activesupport (~> 8.0) aws-sdk-s3 (~> 1.182) concurrent-ruby (~> 1.3) diff --git a/lib/envirobly/cli/main.rb b/lib/envirobly/cli/main.rb index e6a3a0e..1a425ea 100644 --- a/lib/envirobly/cli/main.rb +++ b/lib/envirobly/cli/main.rb @@ -129,6 +129,7 @@ def deploy(path = nil) shell: ) target.render_and_exit_on_errors! + target.configure!(missing_only: true) deployment = Envirobly::Deployment.new(target:, commit:, shell:) deployment.perform(dry_run: options.dry_run) diff --git a/lib/envirobly/deployment.rb b/lib/envirobly/deployment.rb index 8a80558..3611731 100644 --- a/lib/envirobly/deployment.rb +++ b/lib/envirobly/deployment.rb @@ -50,8 +50,8 @@ def perform(dry_run:) targets_and_values = [ [ "Account", @target.account_url ], [ "Region", params[:region] ], - [ "Project Name", params[:project_name] ], - [ "Environ Name", params[:deployment][:environ_name] ] + [ "Project", params[:project_name] ], + [ "Environ", params[:deployment][:environ_name] ] ] shell.print_table targets_and_values, borders: true diff --git a/lib/envirobly/version.rb b/lib/envirobly/version.rb index 9dacd60..3ef598e 100644 --- a/lib/envirobly/version.rb +++ b/lib/envirobly/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Envirobly - VERSION = "1.10.0" + VERSION = "1.11.0" end From cbecdcfd6c262fe776c696af04b1e7255fb2c011 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 15:12:36 +0200 Subject: [PATCH 38/45] typo --- lib/envirobly/name.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/envirobly/name.rb b/lib/envirobly/name.rb index 4a8c355..056d24d 100644 --- a/lib/envirobly/name.rb +++ b/lib/envirobly/name.rb @@ -3,7 +3,7 @@ module Envirobly class Name NAME_FORMAT = /\A[a-z0-9\-_]+\z/i - ERROR_MESSAGE = "must contain only alphanumerical characters, dashes and undercores" + ERROR_MESSAGE = "must contain only alphanumerical characters, dashes and underscores" attr_reader :error From 0c5e7d64b3a3a9e48a504742900c00f29c8a3c31 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 16:50:49 +0200 Subject: [PATCH 39/45] exec implements new target --- lib/envirobly/cli/main.rb | 30 ++++++++++++++++---- lib/envirobly/container_shell.rb | 48 +++++++++++--------------------- 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/lib/envirobly/cli/main.rb b/lib/envirobly/cli/main.rb index 1a425ea..485f748 100644 --- a/lib/envirobly/cli/main.rb +++ b/lib/envirobly/cli/main.rb @@ -147,15 +147,33 @@ def pull(region, bucket, ref, path) Keep in mind, your container might not have a shell installed. In such cases you won't be able to start an interactive session. TXT - method_option :account_id, type: :numeric - method_option :project_id, type: :numeric + method_option :account_url, type: :string method_option :project_name, type: :string method_option :environ_name, type: :string method_option :instance_slot, type: :numeric, default: 0 method_option :shell, type: :string method_option :user, type: :string - def exec(service_name, *command) - Envirobly::ContainerShell.new(service_name, options, shell:).exec(command) + method_option :dry_run, type: :boolean, default: false + def exec(path, *command) + commit = Envirobly::Git::Commit.new "HEAD" + + # TODO: Extract to create_target + target = Envirobly::Target.new( + path, + account_url: options.account_url, + project_name: options.project_name, + region: options.region, + default_project_name: File.basename(Dir.pwd), + default_environ_name: commit.current_branch, + shell:, + context: :service + ) + target.render_and_exit_on_errors! + target.configure!(missing_only: true) + + Envirobly::ContainerShell. + new(target:, instance_slot: options.instance_slot, shell:). + exec(command, dry_run: options.dry_run) end desc "rsync [SERVICE_NAME:]SOURCE_PATH [SERVICE_NAME:]DESTINATION_PATH", <<~TXT @@ -176,6 +194,8 @@ def rsync(source, destination) end end - Envirobly::ContainerShell.new(service_name, options, shell:).rsync(source, destination) + Envirobly::ContainerShell. + new(service_name, options, shell:). + rsync(source, destination, dry_run: options.dry_run) end end diff --git a/lib/envirobly/container_shell.rb b/lib/envirobly/container_shell.rb index 6966c01..002c8bc 100644 --- a/lib/envirobly/container_shell.rb +++ b/lib/envirobly/container_shell.rb @@ -19,50 +19,36 @@ class ContainerShell attr_reader :options, :service_name - def initialize(service_name, options, shell:) - @service_name = service_name - @options = options - - commit = Git::Commit.new "HEAD" - default_account = Defaults::Account.new(shell:) - default_project = Defaults::Project.new(shell:) - - target = Target.new( - default_account_id: default_account.value, - default_project_id: default_project.value, - default_project_name: Defaults::Project.dirname, - default_environ_name: commit.current_branch, - account_id: options.account_id, - project_id: options.project_id, - project_name: options.project_name, - environ_name: options.environ_name - ) - - if target.missing_params.include?(:account_id) - target.account_id = default_account.require_value - end - + def initialize(target:, shell:, instance_slot: 0) + @shell = shell @params = { account_id: target.account_id, - project_id: target.project_id, project_name: target.project_name, environ_name: target.environ_name, - service_name:, - instance_slot: options.instance_slot || 0 + service_name: target.service_name, + instance_slot: instance_slot } + end - if options.project_name.blank? && options.account_id.blank? && options.project_id.blank? - @params[:project_id] = Defaults::Project.new.value + def exec(command = nil, dry_run: false) + if dry_run + @shell.say "Dry run", :green + @shell.say @params.to_yaml + exit end - end - def exec(command = nil) with_private_key do system join(env_vars, ssh, user_and_host, command) end end - def rsync(source, destination) + def rsync(source, destination, dry_run: false) + if dry_run + @shell.say "Dry run", :green + @shell.say @params.yaml + exit + end + with_private_key do system join( env_vars, From 5bf344e019a54286225f3dc805084579d160ed19 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 17:04:26 +0200 Subject: [PATCH 40/45] exec working --- lib/envirobly/cli/main.rb | 49 ++++++++++++++------------------ lib/envirobly/container_shell.rb | 21 +++++++------- 2 files changed, 32 insertions(+), 38 deletions(-) diff --git a/lib/envirobly/cli/main.rb b/lib/envirobly/cli/main.rb index 485f748..e94a7dd 100644 --- a/lib/envirobly/cli/main.rb +++ b/lib/envirobly/cli/main.rb @@ -119,18 +119,7 @@ def deploy(path = nil) Envirobly::AccessToken.new(shell:).require! - target = Envirobly::Target.new( - path, - account_url: options.account_url, - project_name: options.project_name, - region: options.region, - default_project_name: File.basename(Dir.pwd), - default_environ_name: commit.current_branch, - shell: - ) - target.render_and_exit_on_errors! - target.configure!(missing_only: true) - + target = create_target(path:, commit:) deployment = Envirobly::Deployment.new(target:, commit:, shell:) deployment.perform(dry_run: options.dry_run) end @@ -156,23 +145,10 @@ def pull(region, bucket, ref, path) method_option :dry_run, type: :boolean, default: false def exec(path, *command) commit = Envirobly::Git::Commit.new "HEAD" - - # TODO: Extract to create_target - target = Envirobly::Target.new( - path, - account_url: options.account_url, - project_name: options.project_name, - region: options.region, - default_project_name: File.basename(Dir.pwd), - default_environ_name: commit.current_branch, - shell:, - context: :service - ) - target.render_and_exit_on_errors! - target.configure!(missing_only: true) + target = create_target(path:, commit:, context: :service) Envirobly::ContainerShell. - new(target:, instance_slot: options.instance_slot, shell:). + new(target:, instance_slot: options.instance_slot, shell:, exec_shell: options.shell, exec_user: options.user). exec(command, dry_run: options.dry_run) end @@ -195,7 +171,24 @@ def rsync(source, destination) end Envirobly::ContainerShell. - new(service_name, options, shell:). + new(target:, shell:, rsync_args: options.args). rsync(source, destination, dry_run: options.dry_run) end + + private + def create_target(path:, commit:, context: nil) + target = Envirobly::Target.new( + path, + account_url: options.account_url, + project_name: options.project_name, + region: options.region, + default_project_name: File.basename(Dir.pwd), + default_environ_name: commit.current_branch, + shell:, + context: + ) + target.render_and_exit_on_errors! + target.configure!(missing_only: true) + target + end end diff --git a/lib/envirobly/container_shell.rb b/lib/envirobly/container_shell.rb index 002c8bc..3af4733 100644 --- a/lib/envirobly/container_shell.rb +++ b/lib/envirobly/container_shell.rb @@ -17,10 +17,11 @@ class ContainerShell ] USER_AND_HOST = "envirobly-service@%s" - attr_reader :options, :service_name - - def initialize(target:, shell:, instance_slot: 0) + def initialize(target:, shell:, instance_slot: 0, rsync_args: nil, exec_shell: nil, exec_user: nil) @shell = shell + @rsync_args = rsync_args + @exec_shell = exec_shell + @exec_user = exec_user @params = { account_id: target.account_id, project_name: target.project_name, @@ -52,9 +53,9 @@ def rsync(source, destination, dry_run: false) with_private_key do system join( env_vars, - %(rsync #{options.args} -e "#{ssh}"), - source.sub("#{service_name}:", "#{user_and_host}:"), - destination.sub("#{service_name}:", "#{user_and_host}:") + %(rsync #{@rsync_args} -e "#{ssh}"), + source.sub("#{@params[:service_name]}:", "#{user_and_host}:"), + destination.sub("#{@params[:service_name]}:", "#{user_and_host}:") ) end end @@ -92,12 +93,12 @@ def env_vars credentials.fetch("session_token") ) - if options.shell.present? - result = join "ENVIROBLY_SERVICE_INTERACTIVE_SHELL='#{options.shell}'", result + if @exec_shell.present? + result = join "ENVIROBLY_SERVICE_INTERACTIVE_SHELL='#{@exec_shell}'", result end - if options.user.present? - result = join "ENVIROBLY_SERVICE_SHELL_USER='#{options.user}'", result + if @exec_user.present? + result = join "ENVIROBLY_SERVICE_SHELL_USER='#{@exec_user}'", result end result From ae3869fb018def0f5180663a09a99f98855e8e05 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 17:17:40 +0200 Subject: [PATCH 41/45] use with rsync --- lib/envirobly/cli/main.rb | 22 +++++++++++----------- lib/envirobly/container_shell.rb | 24 +++++++++++------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/envirobly/cli/main.rb b/lib/envirobly/cli/main.rb index e94a7dd..dd78d29 100644 --- a/lib/envirobly/cli/main.rb +++ b/lib/envirobly/cli/main.rb @@ -144,8 +144,7 @@ def pull(region, bucket, ref, path) method_option :user, type: :string method_option :dry_run, type: :boolean, default: false def exec(path, *command) - commit = Envirobly::Git::Commit.new "HEAD" - target = create_target(path:, commit:, context: :service) + target = create_target(path:, context: :service) Envirobly::ContainerShell. new(target:, instance_slot: options.instance_slot, shell:, exec_shell: options.shell, exec_user: options.user). @@ -155,28 +154,29 @@ def exec(path, *command) desc "rsync [SERVICE_NAME:]SOURCE_PATH [SERVICE_NAME:]DESTINATION_PATH", <<~TXT Synchronize files between you and your service's data volume. TXT - method_option :account_id, type: :numeric - method_option :project_id, type: :numeric + method_option :account_url, type: :string method_option :project_name, type: :string method_option :environ_name, type: :string method_option :args, type: :string, default: "-avzP" + method_option :dry_run, type: :boolean, default: false def rsync(source, destination) - service_name = nil - - [ source, destination ].each do |path| - if path =~ /\A([a-z0-9\-_]+):/i - service_name = $1 + path = nil + [ source, destination ].each do |arg| + if arg =~ /\A([a-z0-9\-_\/]+):/i + path = $1 break end end + target = create_target(path:, context: :service) + Envirobly::ContainerShell. new(target:, shell:, rsync_args: options.args). - rsync(source, destination, dry_run: options.dry_run) + rsync(source, destination, path:, dry_run: options.dry_run) end private - def create_target(path:, commit:, context: nil) + def create_target(path:, commit: Envirobly::Git::Commit.new("HEAD"), context: nil) target = Envirobly::Target.new( path, account_url: options.account_url, diff --git a/lib/envirobly/container_shell.rb b/lib/envirobly/container_shell.rb index 3af4733..aaaa39a 100644 --- a/lib/envirobly/container_shell.rb +++ b/lib/envirobly/container_shell.rb @@ -32,35 +32,33 @@ def initialize(target:, shell:, instance_slot: 0, rsync_args: nil, exec_shell: n end def exec(command = nil, dry_run: false) - if dry_run - @shell.say "Dry run", :green - @shell.say @params.to_yaml - exit - end + do_dry_run if dry_run with_private_key do system join(env_vars, ssh, user_and_host, command) end end - def rsync(source, destination, dry_run: false) - if dry_run - @shell.say "Dry run", :green - @shell.say @params.yaml - exit - end + def rsync(source, destination, path:, dry_run: false) + do_dry_run if dry_run with_private_key do system join( env_vars, %(rsync #{@rsync_args} -e "#{ssh}"), - source.sub("#{@params[:service_name]}:", "#{user_and_host}:"), - destination.sub("#{@params[:service_name]}:", "#{user_and_host}:") + source.sub("#{path}:", "#{user_and_host}:"), + destination.sub("#{path}:", "#{user_and_host}:") ) end end private + def do_dry_run + @shell.say "Dry run", :green + @shell.say @params.to_yaml + exit + end + def join(*parts) parts.flatten.compact.join(" ") end From ed11d0a8d3639050517813c0c45598f6738fcc68 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 17:18:13 +0200 Subject: [PATCH 42/45] remove Defaults --- lib/envirobly/defaults/account.rb | 43 ------------------------------- lib/envirobly/defaults/project.rb | 7 ----- lib/envirobly/defaults/region.rb | 43 ------------------------------- 3 files changed, 93 deletions(-) delete mode 100644 lib/envirobly/defaults/account.rb delete mode 100644 lib/envirobly/defaults/project.rb delete mode 100644 lib/envirobly/defaults/region.rb diff --git a/lib/envirobly/defaults/account.rb b/lib/envirobly/defaults/account.rb deleted file mode 100644 index b9a6a53..0000000 --- a/lib/envirobly/defaults/account.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -class Envirobly::Defaults::Account < Envirobly::Default - include Envirobly::Colorize - - def require_value - api = Envirobly::Api.new - accounts = api.list_accounts - - if accounts.object.blank? - shell.say_error "Please connect an AWS account to your Envirobly account first." - exit 1 - end - - # If only one account exists, it will be used - id = accounts.object.first.fetch("id") - - if accounts.object.size > 1 - puts "Choose default account to deploy this project to:" - - data = [ [ "ID", "Name", "AWS number", "URL" ] ] + - accounts.object.pluck("id", "name", "aws_id", "url") - - shell.print_table data, borders: true - - limited_to = accounts.object.pluck("id").map(&:to_s) - - begin - id = shell.ask("Type in the account ID:", limited_to:).to_i - rescue Interrupt - shell.say_error "Cancelled" - exit - end - end - - save id - - shell.say "Account ##{id} set as project default " - shell.say green_check - - id - end -end diff --git a/lib/envirobly/defaults/project.rb b/lib/envirobly/defaults/project.rb deleted file mode 100644 index 284f597..0000000 --- a/lib/envirobly/defaults/project.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class Envirobly::Defaults::Project < Envirobly::Default - def self.dirname - File.basename(Dir.pwd) - end -end diff --git a/lib/envirobly/defaults/region.rb b/lib/envirobly/defaults/region.rb deleted file mode 100644 index 7af25c0..0000000 --- a/lib/envirobly/defaults/region.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -class Envirobly::Defaults::Region < Envirobly::Default - include Envirobly::Colorize - - def require_value - api = Envirobly::Api.new - response = api.list_regions - - shell.say "Choose default project region to deploy to:" - shell.print_table [ [ "Name", "Location", "Group" ] ] + - response.object.pluck("code", "title", "group_title"), borders: true - - code = nil - limited_to = response.object.pluck("code") - - while code.nil? - begin - code = shell.ask("Type in the region name:", default: "us-east-1") - rescue Interrupt - shell.say_error "Cancelled" - exit - end - - unless code.in?(limited_to) - shell.say_error "'#{code}' is not a supported region, please try again" - code = nil - end - end - - save code - - shell.say "Region '#{code}' set as project default " - shell.say green_check - - code - end - - private - def cast_value(value) - value.to_s - end -end From 5001ea3c486e1d6e28e8e59d9f04459ab79d7c06 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 17:42:41 +0200 Subject: [PATCH 43/45] unattented option --- lib/envirobly/cli/main.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/envirobly/cli/main.rb b/lib/envirobly/cli/main.rb index dd78d29..b8cf5cf 100644 --- a/lib/envirobly/cli/main.rb +++ b/lib/envirobly/cli/main.rb @@ -3,6 +3,8 @@ class Envirobly::Cli::Main < Envirobly::Base include Envirobly::Colorize + class_option :unattented, type: :boolean, default: false + desc "version", "Show Envirobly CLI version" method_option :pure, type: :boolean, default: false def version @@ -188,7 +190,7 @@ def create_target(path:, commit: Envirobly::Git::Commit.new("HEAD"), context: ni context: ) target.render_and_exit_on_errors! - target.configure!(missing_only: true) + target.configure!(missing_only: true) unless options.unattented target end end From 29338e802627eb090f33fd092ead3b13b7bb4f82 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 17:54:17 +0200 Subject: [PATCH 44/45] typo --- lib/envirobly/cli/main.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/envirobly/cli/main.rb b/lib/envirobly/cli/main.rb index b8cf5cf..3d1b49f 100644 --- a/lib/envirobly/cli/main.rb +++ b/lib/envirobly/cli/main.rb @@ -3,7 +3,7 @@ class Envirobly::Cli::Main < Envirobly::Base include Envirobly::Colorize - class_option :unattented, type: :boolean, default: false + class_option :unattended, type: :boolean, default: false desc "version", "Show Envirobly CLI version" method_option :pure, type: :boolean, default: false @@ -190,7 +190,7 @@ def create_target(path:, commit: Envirobly::Git::Commit.new("HEAD"), context: ni context: ) target.render_and_exit_on_errors! - target.configure!(missing_only: true) unless options.unattented + target.configure!(missing_only: true) unless options.unattended target end end From c637a7f8e47780688078020847d523fa6d520fe3 Mon Sep 17 00:00:00 2001 From: Robert Starsi Date: Sat, 11 Oct 2025 18:01:29 +0200 Subject: [PATCH 45/45] save target if --unattended --- lib/envirobly/cli/main.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/envirobly/cli/main.rb b/lib/envirobly/cli/main.rb index 3d1b49f..a9c8179 100644 --- a/lib/envirobly/cli/main.rb +++ b/lib/envirobly/cli/main.rb @@ -190,7 +190,13 @@ def create_target(path:, commit: Envirobly::Git::Commit.new("HEAD"), context: ni context: ) target.render_and_exit_on_errors! - target.configure!(missing_only: true) unless options.unattended + + if options.unattended + target.save + else + target.configure!(missing_only: true) + end + target end end