envirobly 1.5.2 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4c576e58e00d0c198553f8947987e5e38ee2c4132a84310c84a45d1458b489e
4
- data.tar.gz: dc23f2c855310b3497414c19992669d8c78bee44a8c10603f5e0ada101775efa
3
+ metadata.gz: b171addcd3f154cbcf0707b05cb7957eb181778039fcb8981cfd94b34b5bd8e4
4
+ data.tar.gz: 41af85c70a1c67e33689dcf94c31550d6dedad8fce6fc9ab8d1fd2cd94d6c617
5
5
  SHA512:
6
- metadata.gz: f585a7854a3829846b5f86b96d9b6b203a1c032508bfdb4ecd5c522b18055153f7f612cbc7a172576349f2eed3d97e079f64a4921910a411cc4dc971f75f8296
7
- data.tar.gz: c0d628c3c80f39a7ec4159b3db1c3bd4d666638bfd013d2464faaf297686e49aa1726929ebe0313e55254d337e1d9bd13132ab92bdf28e111b267d24802876ed
6
+ metadata.gz: 6d1e5cb4ef14663cba29fa3c45a17b256334fb323e54817d16ba041ccb4d288edbc4e7809d945faf4c278fbbe6562a9914a4b9d4345c18f4785d6d189135b6d5
7
+ data.tar.gz: e9bb93ab7780128b6c82e3ebe4c29c06f4a7440fa6c3b19ca926f7a86958b52183c33288718f651b8cab980ffb7bc8af78b3d72f7a2fb255b4df9ae1dc5db536
@@ -29,12 +29,12 @@ class Envirobly::Cli::Main < Envirobly::Base
29
29
 
30
30
  desc "set_default_account", "Choose default account to deploy the current project to"
31
31
  def set_default_account
32
- Envirobly::Defaults::Account.new(shell:).require_id
32
+ Envirobly::Defaults::Account.new(shell:).require_value
33
33
  end
34
34
 
35
35
  desc "set_default_region", "Set default region for the current project when deploying for the first time"
36
36
  def set_default_region
37
- Envirobly::Defaults::Region.new(shell:).require_id
37
+ Envirobly::Defaults::Region.new(shell:).require_value
38
38
  end
39
39
 
40
40
  desc "validate", "Validates config"
@@ -24,8 +24,8 @@ class Envirobly::ContainerShell
24
24
  commit = Envirobly::Git::Commit.new "HEAD"
25
25
 
26
26
  @params = {
27
- account_id: options.account_id || Envirobly::Defaults::Account.new.id,
28
- project_name: options.project_name || File.basename(Dir.pwd), # TODO: Extract into Defaults::ProjectName
27
+ account_id: options.account_id || Envirobly::Defaults::Account.new.value,
28
+ project_name: options.project_name || Envirobly::Defaults::Project.dirname,
29
29
  project_id: options.project_id,
30
30
  environ_name: options.environ_name || commit.current_branch,
31
31
  service_name: service_name,
@@ -33,7 +33,7 @@ class Envirobly::ContainerShell
33
33
  }
34
34
 
35
35
  if options.project_name.blank? && options.account_id.blank? && options.project_id.blank?
36
- @params[:project_id] = Envirobly::Defaults::Project.new.id
36
+ @params[:project_id] = Envirobly::Defaults::Project.new.value
37
37
  end
38
38
  end
39
39
 
@@ -3,47 +3,36 @@
3
3
  class Envirobly::Default
4
4
  attr_accessor :shell
5
5
 
6
- def self.key = "url"
7
-
8
6
  def initialize(shell: nil)
9
- @path = File.join Envirobly::Config::DIR, "defaults", self.class.file
7
+ @path = File.join Envirobly::Config::DIR, "defaults", self.class.name.demodulize.downcase
10
8
  @shell = shell
11
9
  end
12
10
 
13
- def id
11
+ def value
14
12
  if File.exist?(@path)
15
- content = YAML.safe_load_file(@path)
16
-
17
- if content[self.class.key] =~ self.class.regexp
18
- return cast_id($1)
19
- end
13
+ cast_value File.read(@path).strip
14
+ else
15
+ nil
20
16
  end
21
-
22
- nil
23
17
  end
24
18
 
25
- def save(url)
26
- unless url =~ self.class.regexp
27
- raise ArgumentError, "'#{url}' must match #{self.class.regexp}"
28
- end
29
-
19
+ def save(value)
30
20
  FileUtils.mkdir_p(File.dirname(@path))
31
- content = YAML.dump({ self.class.key => url })
32
- File.write(@path, content)
21
+ File.write(@path, value)
33
22
  end
34
23
 
35
- def save_if_none(url)
36
- return if id.present?
24
+ def save_if_none(new_value)
25
+ return if value.present?
37
26
 
38
- save(url)
27
+ save(new_value)
39
28
  end
40
29
 
41
30
  def require_if_none
42
- id || require_id
31
+ value || require_value
43
32
  end
44
33
 
45
34
  private
46
- def cast_id(value)
35
+ def cast_value(value)
47
36
  value.to_i
48
37
  end
49
38
  end
@@ -3,10 +3,7 @@
3
3
  class Envirobly::Defaults::Account < Envirobly::Default
4
4
  include Envirobly::Colorize
5
5
 
6
- def self.file = "account.yml"
7
- def self.regexp = /accounts\/(\d+)/
8
-
9
- def require_id
6
+ def require_value
10
7
  api = Envirobly::Api.new
11
8
  accounts = api.list_accounts
12
9
 
@@ -15,8 +12,8 @@ class Envirobly::Defaults::Account < Envirobly::Default
15
12
  exit 1
16
13
  end
17
14
 
18
- account = accounts.object.first
19
- id = account["id"]
15
+ # If only one account exists, it will be used
16
+ id = accounts.object.first.fetch("id")
20
17
 
21
18
  if accounts.object.size > 1
22
19
  puts "Choose default account to deploy this project to:"
@@ -34,11 +31,9 @@ class Envirobly::Defaults::Account < Envirobly::Default
34
31
  shell.say_error "Cancelled"
35
32
  exit
36
33
  end
37
-
38
- account = accounts.object.find { |a| a["id"] == id }
39
34
  end
40
35
 
41
- save account["url"]
36
+ save id
42
37
 
43
38
  shell.say "Account ##{id} set as project default "
44
39
  shell.say green_check
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Envirobly::Defaults::Project < Envirobly::Default
4
- def self.file = "project.yml"
5
- def self.regexp = /projects\/(\d+)/
4
+ def self.dirname
5
+ File.basename(Dir.pwd)
6
+ end
6
7
  end
@@ -3,11 +3,7 @@
3
3
  class Envirobly::Defaults::Region < Envirobly::Default
4
4
  include Envirobly::Colorize
5
5
 
6
- def self.file = "region.yml"
7
- def self.regexp = /([a-z0-9\-)]+)/
8
- def self.key = "code"
9
-
10
- def require_id
6
+ def require_value
11
7
  api = Envirobly::Api.new
12
8
  response = api.list_regions
13
9
 
@@ -34,14 +30,14 @@ class Envirobly::Defaults::Region < Envirobly::Default
34
30
 
35
31
  save code
36
32
 
37
- shell.say "Region '#{id}' set as project default "
33
+ shell.say "Region '#{code}' set as project default "
38
34
  shell.say green_check
39
35
 
40
- id
36
+ code
41
37
  end
42
38
 
43
39
  private
44
- def cast_id(value)
45
- value
40
+ def cast_value(value)
41
+ value.to_s
46
42
  end
47
43
  end
@@ -18,10 +18,10 @@ class Envirobly::Deployment
18
18
  end
19
19
 
20
20
  if project_id.blank? && project_name.blank?
21
- project_id = @default_project.id
21
+ project_id = @default_project.value
22
22
 
23
- if project_id.nil?
24
- project_name = File.basename(Dir.pwd)
23
+ if project_id.blank?
24
+ project_name = Envirobly::Defaults::Project.dirname
25
25
  end
26
26
  end
27
27
 
@@ -69,8 +69,8 @@ class Envirobly::Deployment
69
69
 
70
70
  print "Preparing project..."
71
71
 
72
- @default_account.save_if_none response.object.fetch("account_url")
73
- @default_project.save_if_none response.object.fetch("project_url")
72
+ @default_account.save_if_none response.object.fetch("account_id")
73
+ @default_project.save_if_none response.object.fetch("project_id")
74
74
  @default_region.save_if_none response.object.fetch("region")
75
75
 
76
76
  # Fetch credentials for build context upload
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Envirobly
4
- VERSION = "1.5.2"
4
+ VERSION = "1.6.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envirobly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Starsi