neetodeploy 1.1.2 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c89f6daf95ba95dadcfcbfdf897ff3b9642003da42240d53a566549ab7c80039
4
- data.tar.gz: 890eb532d959f1807b315d8fde953bbbe0590bca1b13abfd3f743a77d238b768
3
+ metadata.gz: 19af255afa80f69e3d6e3587f8917788e866cef5b296525c641415e9285d8720
4
+ data.tar.gz: d851f2610614e2f0f7d3054e72d70b770bb8deb3896fe3c70eafd9ebe70efe22
5
5
  SHA512:
6
- metadata.gz: c492b22e65f9e9f4eeccee4f0720346e94a42885efda1086bad9644414a216aea06dec6881b6764ed011867bb76a1132065c6fd77772e70d001c82e0950de4ac
7
- data.tar.gz: ef3ca43ae3235150ca96ebbd5685ec744774ececa07bc8cf9c35f1267f641200de666f2afae80a28f291afcd214cec21979a158186de519c13ed141fdf405491
6
+ metadata.gz: 40566c170d6f756b33446a237a670532188b5f32eac9cd8ee738b531793e9218e187efe091ec677b8730c68cc2e1ee27511e453cd5503dee7ee2f76f172fb554
7
+ data.tar.gz: efe2823e4c1aa55006f7284f69547e6292e378886bce2fd0ef214fbca559d185240dfd36ff498267c98698bd78fa055965359d05d26553187620c0c7d38c61b9
data/Gemfile.lock CHANGED
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- neetodeploy (1.1.1)
4
+ neetodeploy (1.1.4)
5
+ colorize
5
6
  dotenv (~> 2.8.1)
6
7
  httparty (~> 0.21.0)
7
8
  launchy (~> 2.5.0)
8
9
  terminal-table (~> 3.0.2)
9
- thor (~> 1.2.1)
10
+ thor (~> 1.3.0)
10
11
  websocket-client-simple
11
12
 
12
13
  GEM
@@ -15,6 +16,7 @@ GEM
15
16
  addressable (2.8.1)
16
17
  public_suffix (>= 2.0.2, < 6.0)
17
18
  byebug (11.1.3)
19
+ colorize (1.1.0)
18
20
  dotenv (2.8.1)
19
21
  event_emitter (0.2.6)
20
22
  httparty (0.21.0)
@@ -27,7 +29,7 @@ GEM
27
29
  public_suffix (5.0.1)
28
30
  terminal-table (3.0.2)
29
31
  unicode-display_width (>= 1.1.1, < 3)
30
- thor (1.2.1)
32
+ thor (1.3.0)
31
33
  unicode-display_width (2.4.2)
32
34
  websocket (1.2.9)
33
35
  websocket-client-simple (0.6.1)
@@ -8,24 +8,24 @@ require_relative "./unset"
8
8
 
9
9
  module NeetoDeploy
10
10
  class CLI
11
- module Config
11
+ module Env
12
12
  class Commands < Thor
13
- desc "list", "List all config vars"
13
+ desc "list", "List all environment variable"
14
14
  option :app, type: :string, aliases: "-a", required: true, desc: "App slug" # TODO make this a common static function
15
15
  def list
16
16
  List.new(options:).run
17
17
  end
18
18
 
19
- desc "set CONFIG_VARS", "Set one or more config vars"
19
+ desc "set ENVIRONMENT_VARIABLES", "Set one or more environment variables"
20
20
  option :app, type: :string, aliases: "-a", required: true, desc: "App slug" # TODO make this a common static function
21
- def set(*config_vars)
22
- Set.new(config_vars, options:).run
21
+ def set(*environment_variables)
22
+ Set.new(environment_variables, options:).run
23
23
  end
24
24
 
25
- desc "unset CONFIG_VARS", "Unset one or more config vars"
25
+ desc "unset ENVIRONMENT_VARIABLES", "Unset one or more environment variables"
26
26
  option :app, type: :string, aliases: "-a", required: true, desc: "App slug" # TODO make this a common static function
27
- def unset(*config_vars)
28
- Unset.new(config_vars, options:).run
27
+ def unset(*environment_variables)
28
+ Unset.new(environment_variables, options:).run
29
29
  end
30
30
  end
31
31
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoDeploy
4
+ class CLI
5
+ module Env
6
+ module Constants
7
+ NEETO_DEPLOY_CLI_API_ENVIRONMENT_VARIABLES_URL = "#{NEETO_DEPLOY_CLI_API_BASE_URL}/environment_variables".freeze
8
+
9
+ def environment_variables_url
10
+ NEETO_DEPLOY_CLI_API_ENVIRONMENT_VARIABLES_URL
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -8,7 +8,7 @@ require_relative "./constants"
8
8
 
9
9
  module NeetoDeploy
10
10
  class CLI
11
- module Config
11
+ module Env
12
12
  class List < CLI::Base
13
13
  include Constants
14
14
  include Session
@@ -22,14 +22,14 @@ module NeetoDeploy
22
22
 
23
23
  def run
24
24
  response = send_get_request(
25
- config_vars_url, {
25
+ environment_variables_url, {
26
26
  app_slug:
27
27
  }
28
28
  )
29
29
 
30
30
  ui.error(response) and return unless response.success?
31
31
 
32
- table = Terminal::Table.new(headings: table_columns, rows: table_rows(response["config_vars"]))
32
+ table = Terminal::Table.new(headings: table_columns, rows: table_rows(response["environment_variables"]))
33
33
  ui.success(table)
34
34
  end
35
35
 
@@ -39,9 +39,9 @@ module NeetoDeploy
39
39
  ["Key", "Value"]
40
40
  end
41
41
 
42
- def table_rows(config_vars)
43
- config_vars.map do |config_var|
44
- [config_var["key"], config_var["value"].gsub("\\n", "\n")]
42
+ def table_rows(environment_variables)
43
+ environment_variables.map do |environment_variable|
44
+ [environment_variable["key"], environment_variable["value"].gsub("\\n", "\n")]
45
45
  end
46
46
  end
47
47
  end
@@ -8,18 +8,18 @@ require_relative "./constants"
8
8
 
9
9
  module NeetoDeploy
10
10
  class CLI
11
- module Config
11
+ module Env
12
12
  class Set < CLI::Base
13
13
  include Constants
14
14
  include Session
15
15
 
16
- attr_reader :app_slug, :config_vars
16
+ attr_reader :app_slug, :environment_variables
17
17
 
18
- def initialize(config_vars_string_array, options:)
18
+ def initialize(environment_variables_string_array, options:)
19
19
  super()
20
20
  @app_slug = options[:app]
21
- @config_vars = config_vars_string_array.map do |config_var|
22
- key, value = config_var.split("=")
21
+ @environment_variables = environment_variables_string_array.map do |environment_variable|
22
+ key, value = environment_variable.split("=")
23
23
  { key:, value: }
24
24
  end
25
25
  end
@@ -27,18 +27,18 @@ module NeetoDeploy
27
27
  def run
28
28
  table = Terminal::Table.new(
29
29
  headings: table_columns,
30
- rows: config_vars.map { |config_var|
31
- [config_var[:key], config_var[:value]]
30
+ rows: environment_variables.map { |environment_variable|
31
+ [environment_variable[:key], environment_variable[:value]]
32
32
  }
33
33
  )
34
34
  ui.info(table)
35
35
 
36
- ui.info("Setting config vars and restarting app...")
36
+ ui.info("Setting environment variables and restarting app...")
37
37
 
38
38
  response = send_post_request(
39
- config_vars_url, {
39
+ environment_variables_url, {
40
40
  app_slug:,
41
- config_vars:
41
+ environment_variables:
42
42
  }
43
43
  )
44
44
 
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "terminal-table"
4
+ require "thor"
5
+
6
+ require_relative "../session"
7
+ require_relative "./constants"
8
+
9
+ module NeetoDeploy
10
+ class CLI
11
+ module Env
12
+ class Unset < CLI::Base
13
+ include Constants
14
+ include Session
15
+
16
+ attr_reader :app_slug, :environment_variables_string_array, :environment_variables
17
+
18
+ def initialize(environment_variables_string_array, options:)
19
+ super()
20
+ @app_slug = options[:app]
21
+ @environment_variables_string_array = environment_variables_string_array
22
+ @environment_variables = environment_variables_string_array.map do |environment_variable_key|
23
+ { key: environment_variable_key }
24
+ end
25
+ end
26
+
27
+ def run
28
+ ui.info("Unsetting environment variable keys #{environment_variables_string_array} and restarting app...")
29
+
30
+ response = send_delete_request(
31
+ environment_variables_url, {
32
+ app_slug:,
33
+ environment_variables:
34
+ }
35
+ )
36
+
37
+ ui.error(response) and return unless response.success?
38
+
39
+ ui.success("Done")
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,48 +1,89 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "websocket-client-simple"
3
4
  require "thor"
5
+ require "colorize"
6
+
7
+ require_relative "../session"
8
+ require_relative "./constants"
4
9
 
5
10
  module NeetoDeploy
6
11
  class CLI
7
12
  module Logs
8
13
  class Base < CLI::Base
14
+ include Constants
15
+ include Session
16
+
9
17
  attr_reader :app_name, :process_type
10
18
 
11
19
  def initialize(app_name, process_type = nil)
12
- @app_name = app_name
20
+ super()
21
+ @app_name = app_name
13
22
  @process_type = process_type
14
23
  end
15
24
 
16
25
  def process!
17
- ws = WebSocket::Client::Simple.connect "wss://neeto-deploy-lc.neetodeployapp.com/cli_logs?deployment_name=#{app_name}&&process_type=#{process_type}"
18
-
19
- ws.on :message do |msg|
20
- message = msg.data
21
- cmd = message[0]
22
- if cmd == "1"
23
- STDOUT.write message.delete_prefix("1")
24
- STDOUT.flush
25
- end
26
- end
26
+ stream_logs
27
+ end
27
28
 
28
- ws.on :open do
29
- end
29
+ private
30
30
 
31
- ws.on :close do |e|
32
- p e
33
- exit 1
31
+ def uri
32
+ "wss://connect.neetodeploy.com/cable"
34
33
  end
35
34
 
36
- ws.on :error do |e|
37
- p e
38
- puts "MyserverBackend>> Close entered. Last error:#{$!.class}:#{$!.to_s};Module:#{$0};"
39
- $@.each { |backtrace| puts backtrace }
40
- exit 1
35
+ def ensure_app_access?
36
+ response = send_get_request(app_verify_access_url, { app_slug: app_name })
37
+ @ui.error(JSON[response.body]["error"]) unless response.success?
38
+ response.success?
41
39
  end
42
40
 
43
- loop do
41
+ def stream_logs
42
+ ws_connection = WebSocket::Client::Simple.connect(uri)
43
+ session_token = common_body[:session_token]
44
+ app_slug = @app_name
45
+ process_type = @process_type
46
+ pubsub_token = SecureRandom.hex(16)
47
+
48
+ ws_connection.on :open do
49
+ payload = {
50
+ command: "subscribe",
51
+ identifier: {
52
+ channel: "Cli::LogChannel", app_slug:, pubsub_token:, process_type:,
53
+ session_token:
54
+ }.to_json
55
+ }
56
+ ws_connection.send(payload.to_json)
57
+ end
58
+
59
+ ws_connection.on :message do |msg|
60
+ unless msg.data.empty?
61
+ parsed_msg = JSON.parse(msg.data)
62
+ if parsed_msg["type"].nil?
63
+ parsed_msg["message"]&.each do |log|
64
+ STDOUT.write "#{Time.at(log[0].to_i / 1e9).to_s.light_magenta} #{log[1]}\n"
65
+ end
66
+ elsif parsed_msg["type"] == "disconnect"
67
+ puts parsed_msg["error"].red
68
+ exit
69
+ end
70
+ end
71
+ end
72
+
73
+ ws_connection.on :close do |e|
74
+ p e unless e.nil?
75
+ exit 1
76
+ end
77
+
78
+ ws_connection.on :error do |e|
79
+ p e
80
+ puts "MyserverBackend>> Close entered. Last error:#{$!.class}:#{$!.to_s};Module:#{$0};"
81
+ $@.each { |backtrace| puts backtrace }
82
+ exit 1
83
+ end
84
+
85
+ loop do end
44
86
  end
45
- end
46
87
  end
47
88
  end
48
89
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoDeploy
4
+ class CLI
5
+ module Logs
6
+ module Constants
7
+ NEETO_DEPLOY_CLI_API_ENVIRONMENT_VARIABLES_URL = "#{NEETO_DEPLOY_CLI_API_BASE_URL}/apps/access".freeze
8
+
9
+ def app_verify_access_url
10
+ NEETO_DEPLOY_CLI_API_ENVIRONMENT_VARIABLES_URL
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -7,7 +7,7 @@ module NeetoDeploy
7
7
  NEETO_DEPLOY_CLI_API_ADDONS_REDIS_URL = "#{NEETO_DEPLOY_CLI_API_BASE_URL}/addons/redis".freeze
8
8
  AVAILABLE_REDIS_CONFIGS_TO_EDIT = ["maxmemory-policy"]
9
9
 
10
- def config_vars_url
10
+ def redis_addon_url
11
11
  NEETO_DEPLOY_CLI_API_ADDONS_REDIS_URL
12
12
  end
13
13
 
@@ -21,7 +21,7 @@ module NeetoDeploy
21
21
 
22
22
  def run
23
23
  response = send_patch_request(
24
- config_vars_url, {
24
+ redis_addon_url, {
25
25
  addon_name:,
26
26
  command: "CONFIG get #{key}"
27
27
  }
@@ -29,7 +29,7 @@ module NeetoDeploy
29
29
  end
30
30
 
31
31
  response = send_patch_request(
32
- config_vars_url, {
32
+ redis_addon_url, {
33
33
  addon_name:,
34
34
  command: "CONFIG set #{key} #{value}"
35
35
  }
@@ -10,7 +10,7 @@ module NeetoDeploy
10
10
  require_relative "cli/login/base"
11
11
  require_relative "cli/exec/base"
12
12
  require_relative "cli/logs/base"
13
- require_relative "cli/config/commands"
13
+ require_relative "cli/env/commands"
14
14
  require_relative "cli/redis/commands"
15
15
 
16
16
  def self.start(*)
@@ -22,8 +22,8 @@ module NeetoDeploy
22
22
  CLI::Login::Base.new.process!
23
23
  end
24
24
 
25
- desc "config", "Manage config vars"
26
- subcommand "config", Config::Commands
25
+ desc "env", "Manage environment variable"
26
+ subcommand "env", Env::Commands
27
27
 
28
28
  desc "exec", "Exec into deployment"
29
29
  option :app, type: :string, aliases: "-a", required: true, desc: "App slug"
@@ -33,7 +33,7 @@ module NeetoDeploy
33
33
 
34
34
  desc "logs", "Show logs"
35
35
  option :app, type: :string, aliases: "-a", required: true, desc: "App slug"
36
- option :process_type, type: :string, aliases: "-p", desc: "Process type"
36
+ option :process_type, type: :string, aliases: "-p", required: true, desc: "Process type"
37
37
  def logs
38
38
  CLI::Logs::Base.new(options[:app], options[:process_type]).process!
39
39
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NeetoDeploy
4
- VERSION = "1.1.2"
4
+ VERSION = "1.1.4"
5
5
  CLI_API_VERSION = "v1"
6
6
  end
data/neetodeploy.gemspec CHANGED
@@ -34,8 +34,9 @@ Gem::Specification.new do |spec|
34
34
  spec.add_dependency "httparty", "~> 0.21.0" # for http requests
35
35
  spec.add_dependency "launchy", "~> 2.5.0" # for opening in browser
36
36
  spec.add_dependency "terminal-table", "~> 3.0.2" # for building cli table
37
- spec.add_dependency "thor", "~> 1.2.1" # for cli
37
+ spec.add_dependency "thor", "~> 1.3.0" # for cli
38
38
  spec.add_dependency "websocket-client-simple"
39
+ spec.add_dependency "colorize"
39
40
 
40
41
  # To add the files from submodules
41
42
  `git submodule --quiet foreach pwd`.split($\).each do |submodule_path|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neetodeploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Subin Siby
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-21 00:00:00.000000000 Z
11
+ date: 2024-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.2.1
75
+ version: 1.3.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.2.1
82
+ version: 1.3.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: websocket-client-simple
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: colorize
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Manage neetoDeploy apps with CLI
98
112
  email:
99
113
  - subin.siby@bigbinary.com
@@ -109,16 +123,17 @@ files:
109
123
  - lib/neeto_deploy.rb
110
124
  - lib/neeto_deploy/cli.rb
111
125
  - lib/neeto_deploy/cli/base.rb
112
- - lib/neeto_deploy/cli/config/commands.rb
113
- - lib/neeto_deploy/cli/config/constants.rb
114
- - lib/neeto_deploy/cli/config/list.rb
115
- - lib/neeto_deploy/cli/config/set.rb
116
- - lib/neeto_deploy/cli/config/unset.rb
126
+ - lib/neeto_deploy/cli/env/commands.rb
127
+ - lib/neeto_deploy/cli/env/constants.rb
128
+ - lib/neeto_deploy/cli/env/list.rb
129
+ - lib/neeto_deploy/cli/env/set.rb
130
+ - lib/neeto_deploy/cli/env/unset.rb
117
131
  - lib/neeto_deploy/cli/exec/base.rb
118
132
  - lib/neeto_deploy/cli/exec/constants.rb
119
133
  - lib/neeto_deploy/cli/login/base.rb
120
134
  - lib/neeto_deploy/cli/login/constants.rb
121
135
  - lib/neeto_deploy/cli/logs/base.rb
136
+ - lib/neeto_deploy/cli/logs/constants.rb
122
137
  - lib/neeto_deploy/cli/redis/commands.rb
123
138
  - lib/neeto_deploy/cli/redis/constants.rb
124
139
  - lib/neeto_deploy/cli/redis/get.rb
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module NeetoDeploy
4
- class CLI
5
- module Config
6
- module Constants
7
- NEETO_DEPLOY_CLI_API_CONFIG_VARS_URL = "#{NEETO_DEPLOY_CLI_API_BASE_URL}/config_vars".freeze
8
-
9
- def config_vars_url
10
- NEETO_DEPLOY_CLI_API_CONFIG_VARS_URL
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "terminal-table"
4
- require "thor"
5
-
6
- require_relative "../session"
7
- require_relative "./constants"
8
-
9
- module NeetoDeploy
10
- class CLI
11
- module Config
12
- class Unset < CLI::Base
13
- include Constants
14
- include Session
15
-
16
- attr_reader :app_slug, :config_vars_string_array, :config_vars
17
-
18
- def initialize(config_vars_string_array, options:)
19
- super()
20
- @app_slug = options[:app]
21
- @config_vars_string_array = config_vars_string_array
22
- @config_vars = config_vars_string_array.map do |config_var_key|
23
- { key: config_var_key }
24
- end
25
- end
26
-
27
- def run
28
- ui.info("Unsetting config var keys #{config_vars_string_array} and restarting app...")
29
-
30
- response = send_delete_request(
31
- config_vars_url, {
32
- app_slug:,
33
- config_vars:
34
- }
35
- )
36
-
37
- ui.error(response) and return unless response.success?
38
-
39
- ui.success("Done")
40
- end
41
- end
42
- end
43
- end
44
- end