envirobly 1.3.1 → 1.4.1

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: 2991e127dfd64a68b47720bf70561343e3b7107304d9f5da9c1423cd4a3f0105
4
- data.tar.gz: 8d80a93f0af7427bd44668aaf47b68598ae9a62abd27168a35b52e9102cf9bf2
3
+ metadata.gz: 7a02e37a74f5ed588bf8438579f5ff30035ac8eee90d58a97eb95aa90e78c6c9
4
+ data.tar.gz: a4e2bb4dedcc8801a69796ae41ceacc63ce09430ce74d96a28c540a7188ac025
5
5
  SHA512:
6
- metadata.gz: ab2ba4141f8bbc95fa907bdbfe78d30a9b1600862c9a97a34412de4bc295a4db6a8d46d52d0c97bc744792b15d57b051cf467b7d638287fb2c23e26593832e8f
7
- data.tar.gz: d9a69cb24f0d30fa89bdef0dfd06bfb07c78bc99f9fd32e9b2a2fbcfb136f81e1d72adfc39548b834b1c9ebe499fc6bb429e0dd5f9eeb1272448cf21f0018f26
6
+ metadata.gz: 953ef3a5819627d2910b41970e34c530b5a06603a46a715f96741d683171e8bd7b5db3ee862174e1e101f342a7d5af5b17fd0cbe1730fc9eacc7c07d8285ad66
7
+ data.tar.gz: 656fa66b9495e7936c15dc0d33c8661c59c3b1dde8e78982d7b577b3f6e325655a4e3567e3f6b415b7dd13c01002201a98ec73109273dae3f4e814a87350d485
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "fileutils"
2
4
  require "pathname"
3
5
 
data/lib/envirobly/api.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "json"
2
4
  require "net/http"
3
5
  require "socket"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # @deprecated
2
4
  class Envirobly::Aws::Credentials
3
5
  def initialize(params)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "zlib"
2
4
  require "json"
3
5
  require "open3"
data/lib/envirobly/aws.rb CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Envirobly::Aws
2
4
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "thor"
2
4
 
3
5
  class Envirobly::Base < Thor
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Envirobly::Cli::Main < Envirobly::Base
2
4
  include Envirobly::Colorize
3
5
 
@@ -126,6 +128,27 @@ class Envirobly::Cli::Main < Envirobly::Base
126
128
  method_option :shell, type: :string
127
129
  method_option :user, type: :string
128
130
  def exec(service_name, *command)
129
- Envirobly::ContainerShell.new(service_name, command, options).connect
131
+ Envirobly::ContainerShell.new(service_name, options).exec(command)
132
+ end
133
+
134
+ desc "rsync [SERVICE_NAME:]SOURCE_PATH [SERVICE_NAME:]DESTINATION_PATH", <<~TXT
135
+ Synchronize files between you and your service's data volume.
136
+ TXT
137
+ method_option :account_id, type: :numeric
138
+ method_option :project_id, type: :numeric
139
+ method_option :project_name, type: :string
140
+ method_option :environ_name, type: :string
141
+ method_option :args, type: :string, default: "-avzP"
142
+ def rsync(source, destination)
143
+ service_name = nil
144
+
145
+ [ source, destination ].each do |path|
146
+ if path =~ /\A([a-z0-9\-_]+):/i
147
+ service_name = $1
148
+ break
149
+ end
150
+ end
151
+
152
+ Envirobly::ContainerShell.new(service_name, options).rsync(source, destination)
130
153
  end
131
154
  end
data/lib/envirobly/cli.rb CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Envirobly::Cli
2
4
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Envirobly::Colorize
2
4
  GREEN = "\e[32m"
3
5
  RED = "\e[31m"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "dotenv"
2
4
 
3
5
  class Envirobly::Config
@@ -1,17 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Envirobly::ContainerShell
2
- CMD_TEMLATE =
3
- "AWS_ACCESS_KEY_ID='%s' " +
4
- "AWS_SECRET_ACCESS_KEY='%s' " +
5
- "AWS_SESSION_TOKEN='%s' " +
6
- "ssh -i %s " +
7
- "envirobly-service@%s " +
8
- "-o StrictHostKeyChecking=accept-new " +
4
+ AWS_ENV = [
5
+ "AWS_ACCESS_KEY_ID='%s'",
6
+ "AWS_SECRET_ACCESS_KEY='%s'",
7
+ "AWS_SESSION_TOKEN='%s'"
8
+ ]
9
+ SSH = [
10
+ "ssh -i %s",
11
+ "-o StrictHostKeyChecking=accept-new",
12
+ "-o SendEnv=ENVIROBLY_SERVICE_INTERACTIVE_SHELL",
13
+ "-o SendEnv=ENVIROBLY_SERVICE_SHELL_USER",
9
14
  "-o ProxyCommand='aws ec2-instance-connect open-tunnel --instance-id %s --region %s'"
15
+ ]
16
+ USER_AND_HOST = "envirobly-service@%s"
17
+
18
+ attr_reader :options, :service_name
10
19
 
11
- def initialize(service_name, command, options)
12
- @command = command
20
+ def initialize(service_name, options)
21
+ @service_name = service_name
13
22
  @options = options
14
23
  commit = Envirobly::Git::Commit.new "HEAD"
24
+
15
25
  @params = {
16
26
  project: {
17
27
  account_id: options.account_id || Envirobly::Defaults::Account.new.id,
@@ -20,7 +30,7 @@ class Envirobly::ContainerShell
20
30
  },
21
31
  environ: { name: options.environ_name || commit.current_branch },
22
32
  service: { name: service_name },
23
- instance: { slot: options.instance_slot }
33
+ instance: { slot: options.instance_slot || 0 }
24
34
  }
25
35
 
26
36
  if options.project_name.blank? && options.account_id.blank? && options.project_id.blank?
@@ -28,39 +38,77 @@ class Envirobly::ContainerShell
28
38
  end
29
39
  end
30
40
 
31
- def connect
32
- api = Envirobly::Api.new
33
- response = api.create_service_shell_connection @params
34
- ssh_params = response.object
35
-
36
- Tempfile.create do |tempkey|
37
- tempkey.write ssh_params.fetch("instance").fetch("private_key")
38
- tempkey.flush
39
-
40
- cmd = sprintf(
41
- CMD_TEMLATE,
42
- ssh_params.fetch("open_tunnel_credentials").fetch("access_key_id"),
43
- ssh_params.fetch("open_tunnel_credentials").fetch("secret_access_key"),
44
- ssh_params.fetch("open_tunnel_credentials").fetch("session_token"),
45
- tempkey.path,
46
- ssh_params.fetch("instance").fetch("private_ipv4"),
47
- ssh_params.fetch("instance").fetch("aws_id"),
48
- ssh_params.fetch("region")
41
+ def exec(command = nil)
42
+ with_private_key do
43
+ system join(env_vars, ssh, user_and_host, command)
44
+ end
45
+ end
46
+
47
+ def rsync(source, destination)
48
+ with_private_key do
49
+ system join(
50
+ env_vars,
51
+ %(rsync #{options.args} -e "#{ssh}"),
52
+ source.sub("#{service_name}:", "#{user_and_host}:"),
53
+ destination.sub("#{service_name}:", "#{user_and_host}:")
49
54
  )
55
+ end
56
+ end
57
+
58
+ private
59
+ def join(*parts)
60
+ parts.flatten.compact.join(" ")
61
+ end
50
62
 
51
- if @options.shell.present?
52
- cmd = "ENVIROBLY_SERVICE_INTERACTIVE_SHELL='#{@options.shell}' #{cmd} -o SendEnv=ENVIROBLY_SERVICE_INTERACTIVE_SHELL"
63
+ def connect_data
64
+ @connect_data ||= begin
65
+ api = Envirobly::Api.new
66
+ api.create_service_shell_connection(@params).object
53
67
  end
68
+ end
69
+
70
+ def with_private_key
71
+ Tempfile.create do |file|
72
+ file.write connect_data.fetch("instance").fetch("private_key")
73
+ file.flush
74
+
75
+ @private_key_path = file.path
54
76
 
55
- if @options.user.present?
56
- cmd = "ENVIROBLY_SERVICE_SHELL_USER='#{@options.user}' #{cmd} -o SendEnv=ENVIROBLY_SERVICE_SHELL_USER"
77
+ yield
78
+ end
79
+ end
80
+
81
+ def env_vars
82
+ credentials = connect_data.fetch("open_tunnel_credentials")
83
+
84
+ result = sprintf(
85
+ join(AWS_ENV),
86
+ credentials.fetch("access_key_id"),
87
+ credentials.fetch("secret_access_key"),
88
+ credentials.fetch("session_token")
89
+ )
90
+
91
+ if options.shell.present?
92
+ result = join "ENVIROBLY_SERVICE_INTERACTIVE_SHELL='#{options.shell}'", result
57
93
  end
58
94
 
59
- if @command.present?
60
- cmd = "#{cmd} #{@command.join(" ")}"
95
+ if options.user.present?
96
+ result = join "ENVIROBLY_SERVICE_SHELL_USER='#{options.user}'", result
61
97
  end
62
98
 
63
- system cmd
99
+ result
100
+ end
101
+
102
+ def ssh
103
+ sprintf(
104
+ join(SSH),
105
+ @private_key_path,
106
+ connect_data.fetch("instance").fetch("aws_id"),
107
+ connect_data.fetch("region")
108
+ )
109
+ end
110
+
111
+ def user_and_host
112
+ sprintf USER_AND_HOST, connect_data.fetch("instance").fetch("private_ipv4")
64
113
  end
65
- end
66
114
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Envirobly::Default
2
4
  attr_accessor :shell
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Envirobly::Defaults::Account < Envirobly::Default
2
4
  include Envirobly::Colorize
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Envirobly::Defaults::Project < Envirobly::Default
2
4
  def self.file = "project.yml"
3
5
  def self.regexp = /projects\/(\d+)/
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Envirobly::Defaults::Region < Envirobly::Default
2
4
  include Envirobly::Colorize
3
5
 
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Envirobly::Defaults
2
4
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "yaml"
2
4
 
3
5
  class Envirobly::Deployment
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "benchmark"
2
4
 
3
5
  class Envirobly::Duration
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "time"
2
4
  require "open3"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Envirobly::Git::Unstaged < Envirobly::Git::Commit
2
4
  def initialize(working_dir: Dir.getwd)
3
5
  @working_dir = working_dir
data/lib/envirobly/git.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Envirobly::Git
2
4
  def initialize(working_dir = Dir.getwd)
3
5
  @working_dir = working_dir
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Envirobly::Numeric < Numeric
2
4
  def initialize(value, short: false)
3
5
  @value = value
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Envirobly
2
- VERSION = "1.3.1"
4
+ VERSION = "1.4.1"
3
5
  end
data/lib/envirobly.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Envirobly
2
4
  end
3
5
 
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.3.1
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Starsi
@@ -149,6 +149,20 @@ dependencies:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
151
  version: '8.0'
152
+ - !ruby/object:Gem::Dependency
153
+ name: rubocop-rails-omakase
154
+ requirement: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '1.1'
159
+ type: :development
160
+ prerelease: false
161
+ version_requirements: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '1.1'
152
166
  email: klevo@klevo.sk
153
167
  executables:
154
168
  - envirobly