neetodeploy 1.1.5 → 1.1.7

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: 305d6867816ecbca9f4c86d447117ff8fefebac877e6177000cf29f338c2b11b
4
- data.tar.gz: 97243a423a38b634cb30289dfaf93ca71cb7bc96e9d83e3c9c57e16a54814f64
3
+ metadata.gz: 1a80b1dc99cd84c07a2d0892accedceae3492a5ec4e5f8291854649634737d45
4
+ data.tar.gz: 93ac86192e895e77d8d5a39e406d006da45de22e2ff0cc06f51906c0442632b8
5
5
  SHA512:
6
- metadata.gz: de103bbd5f402dd3903b49f85008299652b7680b7a7a1e0fc8835dc3804cd91a7e204915183497fa020a9eedd7fbae20590af4c833c58e7327e276bf473c4770
7
- data.tar.gz: 7f13ee1a14bc878f0c8e718d2fa045b3ceea1f44614e78ffbcfad9cdf6fbdeca38793ef2629f33950ceb9e30f2aeb0b226987fbc6e649498bfcda841ac00fa58
6
+ metadata.gz: 353eea681bf9353635f4d1951eb11622854618ae43f4e0d26c3acb5ca49f5104320ac8f7c05722460af7b67eb0cb2170628f8cf3c13bef0fc2907672af1e58f9
7
+ data.tar.gz: 56c6c9ed6a00b6d1e1ef6071b511e4bf630652a12fca0cf6e300f905c99335e7a14dbedcf5e04193b5bd994248a31dbe72b8b69983a27b81a2b97d256de6b3e1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- neetodeploy (1.1.5)
4
+ neetodeploy (1.1.7)
5
5
  colorize
6
6
  dotenv (~> 2.8.1)
7
7
  httparty (~> 0.21.0)
data/exe/console ADDED
Binary file
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "thor"
4
4
  require_relative "./info"
5
+ require_relative "./scheduled_exports_settings"
5
6
 
6
7
  module NeetoDeploy
7
8
  class CLI
@@ -12,6 +13,12 @@ module NeetoDeploy
12
13
  def info
13
14
  Info.new(options).run
14
15
  end
16
+
17
+ desc "scheduled_exports_enabled", "Check whether scheduled exports is enabled for an app"
18
+ option :app_name, type: :string, aliases: "-a", required: true, desc: "App name"
19
+ def scheduled_exports_enabled
20
+ ScheduledExportsSettings.new(options).run
21
+ end
15
22
  end
16
23
  end
17
24
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+
5
+ require_relative "../session"
6
+ require_relative "./constants"
7
+
8
+ module NeetoDeploy
9
+ class CLI
10
+ module Addon
11
+ class ScheduledExportsSettings < CLI::Base
12
+ include Constants
13
+ include Session
14
+
15
+ attr_reader :app_name
16
+
17
+ def initialize(options)
18
+ super()
19
+ @app_name = options[:app_name]
20
+ end
21
+
22
+ def run
23
+ ui.execute_with_loading("Fetching info...") do
24
+ send_request
25
+ end
26
+ print_output
27
+ end
28
+
29
+ private
30
+
31
+ def send_request
32
+ @response = send_get_request("#{NEETO_DEPLOY_CLI_API_BASE_URL}/scheduled_exports/#{app_name}", {app_slug: app_name})
33
+ end
34
+
35
+ def print_output
36
+ ui.error(@response["error"]) and return unless @response.success?
37
+
38
+ scheduled_exports = JSON.parse(@response.body)["scheduled_exports_enabled"]
39
+ if scheduled_exports.nil?
40
+ ui.error("App doesn't seem to have a primary database addon")
41
+ else
42
+ ui.info("Scheduled exports is turned #{scheduled_exports ? "\u001b[32mon\u001b[0m" : "\u001b[31moff\u001b[0m"} for #{app_name}'s primary database")
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+
5
+ require_relative "./list"
6
+
7
+ module NeetoDeploy
8
+ class CLI
9
+ module AutoscalingConfig
10
+ class Commands < Thor
11
+ desc "list", "List autoscaling configs of an app"
12
+ option :app, type: :string, aliases: "-a", required: true, desc: "App slug"
13
+ def list
14
+ List.new(options:).run
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+
5
+ module NeetoDeploy
6
+ class CLI
7
+ module AutoscalingConfig
8
+ class List < CLI::Base
9
+ include Session
10
+
11
+ attr_reader :app_slug
12
+
13
+ def initialize(options:)
14
+ super()
15
+ @app_slug = options[:app]
16
+ end
17
+
18
+ def run
19
+ response = send_get_request(
20
+ "#{NEETO_DEPLOY_CLI_API_BASE_URL}/autoscaling_configs/#{app_slug}", {
21
+ app_slug:
22
+ }
23
+ )
24
+
25
+ ui.error(response) and return unless response.success?
26
+
27
+ ui.success(JSON.parse(response.body)["autoscaling_status"])
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -4,7 +4,7 @@ require_relative "ui"
4
4
  require_relative "../version"
5
5
 
6
6
  module NeetoDeploy
7
- class CLI
7
+ class CLI
8
8
  NEETO_DEPLOY_HOST = ENV["NEETO_DEPLOY_HOST"] || "https://app.neetodeploy.com"
9
9
  NEETO_DEPLOY_CLI_API_BASE_URL = "#{NEETO_DEPLOY_HOST}/api/cli/#{CLI_API_VERSION}"
10
10
 
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+
5
+ module NeetoDeploy
6
+ class CLI
7
+ class DynoConsoleManager < Base
8
+ DYNO_CONSOLE_MANAGER_URL = "wss://neeto-deploy-lc.neetodeployapp.com"
9
+
10
+ def initialize
11
+ super()
12
+ @prompt = ""
13
+ end
14
+
15
+ def run_console
16
+ start_spinner
17
+ send_console_session_request
18
+ ui.error(response) and return unless @response.success?
19
+
20
+ send_websocket_request
21
+ define_websocket_blocks
22
+ end
23
+
24
+ private
25
+
26
+ def start_spinner
27
+ @spinner = TTY::Spinner.new("[:spinner] Connecting to #{@instance_name}", format: :classic)
28
+ @spinner.auto_spin
29
+ end
30
+
31
+ def define_websocket_blocks
32
+ stop_spinner = lambda do
33
+ @spinner.stop unless @connection_established
34
+ end
35
+
36
+ cleanup = lambda do
37
+ connection_cleanup
38
+ end
39
+
40
+ @ws.on :message do |msg|
41
+ message = msg.data
42
+ if message.to_s.eql?("{\"exitCode\":0,\"signal\":0}")
43
+ cleanup.call
44
+ exit 0
45
+ end
46
+ cmd = message[0]
47
+ if cmd == "1"
48
+ extracted_message = message.delete_prefix("1")
49
+ stop_spinner.call && @connection_established = true unless extracted_message == ""
50
+ @prompt = "\u001b[2K\u001b[0G#{extracted_message.split("\r\n").last}"
51
+ print extracted_message
52
+ end
53
+ end
54
+
55
+ @ws.on :open do
56
+ end
57
+
58
+ @ws.on :close do |e|
59
+ puts e
60
+ exit 1
61
+ end
62
+
63
+ @ws.on :error do |e|
64
+ puts e
65
+ puts "MyserverBackend>> Close entered. Last error:#{$!.class}:#{$!.to_s};Module:#{$0};"
66
+ $@.each { |backtrace| puts backtrace }
67
+ exit 1
68
+ end
69
+
70
+ trap("SIGINT") do
71
+ Thread.new { @ws.send "4" }
72
+ end
73
+
74
+ loop do
75
+ sleep 0.1
76
+ input = Readline.readline(@prompt, true)
77
+ @ws.send "1" + input
78
+ end
79
+ end
80
+
81
+ def connection_cleanup
82
+ end
83
+ end
84
+ end
85
+ end
@@ -12,6 +12,7 @@ module NeetoDeploy
12
12
  class Commands < Thor
13
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
+ option :json, type: :boolean, aliases: "-j", desc: "Output config vars in json format"
15
16
  def list
16
17
  List.new(options:).run
17
18
  end
@@ -13,11 +13,12 @@ module NeetoDeploy
13
13
  include Constants
14
14
  include Session
15
15
 
16
- attr_reader :app_slug
16
+ attr_reader :app_slug, :is_json_format
17
17
 
18
18
  def initialize(options:)
19
19
  super()
20
20
  @app_slug = options[:app]
21
+ @is_json_format = options[:json]
21
22
  end
22
23
 
23
24
  def run
@@ -29,8 +30,8 @@ module NeetoDeploy
29
30
 
30
31
  ui.error(response) and return unless response.success?
31
32
 
32
- table = Terminal::Table.new(headings: table_columns, rows: table_rows(response["environment_variables"]))
33
- ui.success(table)
33
+ data = is_json_format ? json_data(response["environment_variables"]) : table_data(response["environment_variables"])
34
+ ui.success(data)
34
35
  end
35
36
 
36
37
  private
@@ -44,6 +45,18 @@ module NeetoDeploy
44
45
  [environment_variable["key"], environment_variable["value"].gsub("\\n", "\n")]
45
46
  end
46
47
  end
48
+
49
+ def table_data(envs)
50
+ Terminal::Table.new(headings: table_columns, rows: table_rows(envs))
51
+ end
52
+
53
+ def json_data(envs)
54
+ resulting_hash = envs.each_with_object({}) do |item, hash|
55
+ hash[item["key"]] = item["value"]
56
+ end
57
+ JSON.pretty_generate(resulting_hash)
58
+ end
59
+
47
60
  end
48
61
  end
49
62
  end
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "websocket-client-simple"
3
4
  require "thor"
4
5
  require "readline"
5
6
 
6
7
  require_relative "../session"
7
8
  require_relative "./constants"
9
+ require_relative "../dyno_console_manager"
8
10
 
9
11
  module NeetoDeploy
10
12
  class CLI
@@ -21,74 +23,49 @@ module NeetoDeploy
21
23
  end
22
24
 
23
25
  def process!
24
- puts "Opening console for #{app_name}"
25
-
26
- response = send_post_request(
27
- console_session_base_url, {
28
- # TODO refactor app_slug to app_name in dashboard app
29
- app_slug: app_name,
30
- }
31
- )
32
-
33
- ui.error(response) and return unless response.success?
34
-
35
- console_token = response.parsed_response["console_token"]
36
- pubsub_token = response.parsed_response["console_pubsub_token"]
37
- deployment_name = "#{app_name}-#{pubsub_token}-console-deployment"
26
+ start_spinner
27
+ send_console_session_request
28
+ ui.error("\n#{@response.body}") and return unless @response.success?
38
29
 
39
- ws = WebSocket::Client::Simple.connect "wss://neeto-deploy-lc.neetodeployapp.com/cli_console?app_name=#{app_name}&deployment_name=#{deployment_name}&console_token=#{console_token}"
40
30
 
41
- prompt = ''
31
+ buffer_wait_block
32
+ start_console
33
+ connection_cleanup_callback
34
+ end
42
35
 
43
- delete_url = "#{console_session_base_url}/#{console_token}"
44
- app_slug = app_name
45
-
46
- send_delete_request = lambda do |url, body|
47
- send_delete_request(url, body)
48
- end
36
+ private
49
37
 
50
- ws.on :message do |msg|
51
- message = msg.data
52
- if message.to_s.eql?("{\"exitCode\":0,\"signal\":0}")
53
- send_delete_request.call(
54
- delete_url, {
55
- app_slug:
56
- }
57
- )
58
- exit 0
59
- end
60
- cmd = message[0]
61
- if cmd == "1"
62
- prompt = "\u001b[2K\u001b[0G#{message.delete_prefix("1").split("\r\n").last}"
63
- print message.delete_prefix("1")
64
- end
38
+ def console_executable_path
39
+ gem_spec = Gem::Specification.find_by_name("neetodeploy")
40
+ gem_dir = gem_spec.gem_dir
41
+ executable_path = File.join(gem_dir, "exe", "console")
65
42
  end
66
43
 
67
- ws.on :open do
44
+ def start_console
45
+ @pubsub_token = @response.parsed_response["console_pubsub_token"]
46
+ console_access_token = @response.parsed_response["console_access_token"]
47
+ pod_name = "#{app_name}-#{@pubsub_token}-console-deployment"
48
+ system("#{console_executable_path} #{pod_name} #{console_access_token}")
68
49
  end
69
50
 
70
- ws.on :close do |e|
71
- puts e
72
- exit 1
51
+ def send_console_session_request
52
+ @response = send_post_request(console_session_base_url, { app_slug: @app_name })
73
53
  end
74
54
 
75
- ws.on :error do |e|
76
- puts e
77
- puts "MyserverBackend>> Close entered. Last error:#{$!.class}:#{$!.to_s};Module:#{$0};"
78
- $@.each { |backtrace| puts backtrace }
79
- exit 1
55
+ def connection_cleanup_callback
56
+ url = "#{console_session_base_url}/#{app_name}"
57
+ send_delete_request(url, { pubsub_token: @pubsub_token })
80
58
  end
81
59
 
82
- trap("SIGINT") do
83
- Thread.new { ws.send "4" }
60
+ def start_spinner
61
+ @spinner = TTY::Spinner.new("[:spinner] Connecting to #{app_name}", format: :classic)
62
+ @spinner.auto_spin
84
63
  end
85
64
 
86
- loop do
87
- sleep 0.1
88
- input = Readline.readline(prompt, true)
89
- ws.send "1" + input
65
+ def buffer_wait_block
66
+ sleep 5
67
+ @spinner.stop
90
68
  end
91
- end
92
69
  end
93
70
  end
94
71
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./console"
4
+
5
+ module NeetoDeploy
6
+ class CLI
7
+ module Pg
8
+ class Commands < Thor
9
+ # desc "cli", "Connect to postgresql console"
10
+ # option :addon_name, type: :string, aliases: "-n", required: true, desc: "Addon name"
11
+
12
+ # def cli
13
+ # Console.new(options).run
14
+ # end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require_relative "../session"
5
+ require_relative "./constants"
6
+ require_relative "../dyno_console_manager"
7
+
8
+ module NeetoDeploy
9
+ class CLI
10
+ module Pg
11
+ class Console < CLI::DynoConsoleManager
12
+ include Constants
13
+ include Session
14
+
15
+ attr_reader :addon_name
16
+
17
+ def initialize(options)
18
+ super()
19
+ @addon_name = options[:addon_name]
20
+ @instance_name = options[:addon_name]
21
+ @connection_established = false
22
+ end
23
+
24
+ def run
25
+ run_console
26
+ end
27
+
28
+ private
29
+
30
+ def send_console_session_request
31
+ @response = send_post_request(console_session_base_url(addon_name), {})
32
+ end
33
+
34
+ def send_websocket_request
35
+ console_token = @response.parsed_response["console_token"]
36
+ database_url = @response.parsed_response["url"]
37
+ deployment_name = @response.parsed_response["internal_name"]
38
+ app_name = @response.parsed_response["app_name"]
39
+
40
+ @ws = WebSocket::Client::Simple.connect "#{DYNO_CONSOLE_MANAGER_URL}/cli_console?app_name=#{app_name}&deployment_name=#{deployment_name}&console_token=#{console_token}&database_url=#{database_url}&kind=postgres"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoDeploy
4
+ class CLI
5
+ module Pg
6
+ module Constants
7
+ def console_session_base_url(addon_name)
8
+ "#{NEETO_DEPLOY_CLI_API_BASE_URL}/addons/#{addon_name}/console_session"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -13,7 +13,9 @@ module NeetoDeploy
13
13
  require_relative "cli/logs/base"
14
14
  require_relative "cli/env/commands"
15
15
  require_relative "cli/redis/commands"
16
+ require_relative "cli/pg/commands"
16
17
  require_relative "cli/addon/commands"
18
+ require_relative "cli/autoscaling_config/commands"
17
19
 
18
20
  def self.start(*)
19
21
  super
@@ -43,7 +45,13 @@ module NeetoDeploy
43
45
  desc "redis", "Manage redis addons"
44
46
  subcommand "redis", Redis::Commands
45
47
 
48
+ desc "pg", "Manage postgresql addons"
49
+ subcommand "pg", Pg::Commands
50
+
46
51
  desc "addon", "Manage addons"
47
52
  subcommand "addon", Addon::Commands
53
+
54
+ desc "autoscaling_config", "Manage autoscaling"
55
+ subcommand "autoscaling_config", AutoscalingConfig::Commands
48
56
  end
49
57
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NeetoDeploy
4
- VERSION = "1.1.5"
4
+ VERSION = "1.1.7"
5
5
  CLI_API_VERSION = "v1"
6
6
  end
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.5
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Subin Siby
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-16 00:00:00.000000000 Z
11
+ date: 2024-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -126,6 +126,7 @@ description: Manage neetoDeploy apps with CLI
126
126
  email:
127
127
  - subin.siby@bigbinary.com
128
128
  executables:
129
+ - console
129
130
  - neetodeploy
130
131
  extensions: []
131
132
  extra_rdoc_files: []
@@ -133,13 +134,18 @@ files:
133
134
  - ".ruby-version"
134
135
  - Gemfile
135
136
  - Gemfile.lock
137
+ - exe/console
136
138
  - exe/neetodeploy
137
139
  - lib/neeto_deploy.rb
138
140
  - lib/neeto_deploy/cli.rb
139
141
  - lib/neeto_deploy/cli/addon/commands.rb
140
142
  - lib/neeto_deploy/cli/addon/constants.rb
141
143
  - lib/neeto_deploy/cli/addon/info.rb
144
+ - lib/neeto_deploy/cli/addon/scheduled_exports_settings.rb
145
+ - lib/neeto_deploy/cli/autoscaling_config/commands.rb
146
+ - lib/neeto_deploy/cli/autoscaling_config/list.rb
142
147
  - lib/neeto_deploy/cli/base.rb
148
+ - lib/neeto_deploy/cli/dyno_console_manager.rb
143
149
  - lib/neeto_deploy/cli/env/commands.rb
144
150
  - lib/neeto_deploy/cli/env/constants.rb
145
151
  - lib/neeto_deploy/cli/env/list.rb
@@ -151,6 +157,9 @@ files:
151
157
  - lib/neeto_deploy/cli/login/constants.rb
152
158
  - lib/neeto_deploy/cli/logs/base.rb
153
159
  - lib/neeto_deploy/cli/logs/constants.rb
160
+ - lib/neeto_deploy/cli/pg/commands.rb
161
+ - lib/neeto_deploy/cli/pg/console.rb
162
+ - lib/neeto_deploy/cli/pg/constants.rb
154
163
  - lib/neeto_deploy/cli/redis/commands.rb
155
164
  - lib/neeto_deploy/cli/redis/constants.rb
156
165
  - lib/neeto_deploy/cli/redis/get.rb