neetodeploy 1.1.3 → 1.1.5

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: 852a444976eabbc736b6ab65c2e93c980fa32281f80d0b99f870ca3c7300ffbb
4
- data.tar.gz: 5cb3f42d7f20af3186a77aef7d2c8d8bf4f0e80cebda965180dbeab17b2a7139
3
+ metadata.gz: 305d6867816ecbca9f4c86d447117ff8fefebac877e6177000cf29f338c2b11b
4
+ data.tar.gz: 97243a423a38b634cb30289dfaf93ca71cb7bc96e9d83e3c9c57e16a54814f64
5
5
  SHA512:
6
- metadata.gz: 651e70c339bb1d36aa29d967357e13e34e1511e6af1b60e50ca6761c988bccbb31b2093589e980cd5bad3837ec842e7da61dbba5d403cf962135e4bdfef05ed4
7
- data.tar.gz: 2c2864829f60f732e64a59fcc406cb6f6a9cbef01866c7af2a101f2f1747526a126a042034054f7099bd53a0cfc6e2740b9970e5746e6a391bdf4f5757a844dc
6
+ metadata.gz: de103bbd5f402dd3903b49f85008299652b7680b7a7a1e0fc8835dc3804cd91a7e204915183497fa020a9eedd7fbae20590af4c833c58e7327e276bf473c4770
7
+ data.tar.gz: 7f13ee1a14bc878f0c8e718d2fa045b3ceea1f44614e78ffbcfad9cdf6fbdeca38793ef2629f33950ceb9e30f2aeb0b226987fbc6e649498bfcda841ac00fa58
data/Gemfile.lock CHANGED
@@ -1,12 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- neetodeploy (1.1.3)
4
+ neetodeploy (1.1.5)
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
10
  thor (~> 1.3.0)
11
+ tty-spinner
10
12
  websocket-client-simple
11
13
 
12
14
  GEM
@@ -15,6 +17,7 @@ GEM
15
17
  addressable (2.8.1)
16
18
  public_suffix (>= 2.0.2, < 6.0)
17
19
  byebug (11.1.3)
20
+ colorize (1.1.0)
18
21
  dotenv (2.8.1)
19
22
  event_emitter (0.2.6)
20
23
  httparty (0.21.0)
@@ -28,6 +31,9 @@ GEM
28
31
  terminal-table (3.0.2)
29
32
  unicode-display_width (>= 1.1.1, < 3)
30
33
  thor (1.3.0)
34
+ tty-cursor (0.7.1)
35
+ tty-spinner (0.9.3)
36
+ tty-cursor (~> 0.7)
31
37
  unicode-display_width (2.4.2)
32
38
  websocket (1.2.9)
33
39
  websocket-client-simple (0.6.1)
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require_relative "./info"
5
+
6
+ module NeetoDeploy
7
+ class CLI
8
+ module Addon
9
+ class Commands < Thor
10
+ desc "info", "Get addon informations"
11
+ option :addon_name, type: :string, aliases: "-n", required: true, desc: "Addon name"
12
+ def info
13
+ Info.new(options).run
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NeetoDeploy
4
+ class CLI
5
+ module Addon
6
+ module Constants
7
+ NEETO_DEPLOY_CLI_API_ADDON_URL = "#{NEETO_DEPLOY_CLI_API_BASE_URL}/addons".freeze
8
+
9
+ def addon_url(addon_name)
10
+ "#{NEETO_DEPLOY_CLI_API_BASE_URL}/addons/#{addon_name}"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,54 @@
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 Info < CLI::Base
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
+ 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 flatten_hash_from(hash)
32
+ hash.each_with_object({}) do |(key, value), memo|
33
+ next flatten_hash_from(value).each do |k, v|
34
+ memo["#{k}".intern] = v
35
+ end if value.is_a? Hash
36
+ memo[key] = value
37
+ end
38
+ end
39
+
40
+ def send_request
41
+ @response = send_get_request(addon_url(addon_name), {})
42
+ end
43
+
44
+ def print_output
45
+ ui.error(@response["error"]) and return unless @response.success?
46
+
47
+ flatten_hash_from(JSON[@response.body]).each do |k, v|
48
+ ui.info("#{k}: #{v}")
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -33,8 +33,10 @@ module NeetoDeploy
33
33
  ui.error(response) and return unless response.success?
34
34
 
35
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"
36
38
 
37
- ws = WebSocket::Client::Simple.connect "wss://neeto-deploy-lc.neetodeployapp.com/cli_console?deployment_name=#{app_name}&console_token=#{console_token}"
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}"
38
40
 
39
41
  prompt = ''
40
42
 
@@ -1,45 +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)
20
+ super()
12
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://loki-gateway.neetodeployapp.com/loki/api/v1/tail?query={container=~\".*#{app_name}.*\"}&start=#{(Time.now - 300).to_i}"
26
+ stream_logs
27
+ end
18
28
 
19
- ws.on :message do |msg|
20
- begin
21
- data = JSON.parse(msg.data)
22
- puts data["streams"].map { |stream| stream["values"][0][1] }
23
- rescue JSON::ParserError => e
24
- end
25
- end
29
+ private
26
30
 
27
- ws.on :open do
31
+ def uri
32
+ "wss://connect.neetodeploy.com/cable"
28
33
  end
29
34
 
30
- ws.on :close do |e|
31
- p e
32
- 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?
33
39
  end
34
40
 
35
- ws.on :error do |e|
36
- p e
37
- exit 1
38
- end
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
39
84
 
40
- loop do
85
+ loop do end
41
86
  end
42
- end
43
87
  end
44
88
  end
45
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
@@ -3,6 +3,7 @@
3
3
  require "thor"
4
4
  require_relative "./set"
5
5
  require_relative "./get"
6
+ require_relative "./reset_stats"
6
7
 
7
8
  module NeetoDeploy
8
9
  class CLI
@@ -23,6 +24,13 @@ module NeetoDeploy
23
24
  def get
24
25
  Get.new(options).run
25
26
  end
27
+
28
+ desc "reset-stats", "Resets the statistics of the Redis instance"
29
+ option :addon_name, type: :string, aliases: "-n", required: true, desc: "Addon name"
30
+ def reset_stats
31
+ ResetStats.new(options).run
32
+ end
33
+
26
34
  end
27
35
  end
28
36
  end
@@ -5,7 +5,7 @@ module NeetoDeploy
5
5
  module Redis
6
6
  module Constants
7
7
  NEETO_DEPLOY_CLI_API_ADDONS_REDIS_URL = "#{NEETO_DEPLOY_CLI_API_BASE_URL}/addons/redis".freeze
8
- AVAILABLE_REDIS_CONFIGS_TO_EDIT = ["maxmemory-policy"]
8
+ AVAILABLE_REDIS_CONFIGS_TO_EDIT = ["maxmemory-policy", "notify-keyspace-events"]
9
9
 
10
10
  def redis_addon_url
11
11
  NEETO_DEPLOY_CLI_API_ADDONS_REDIS_URL
@@ -20,17 +20,28 @@ module NeetoDeploy
20
20
  end
21
21
 
22
22
  def run
23
- response = send_patch_request(
24
- redis_addon_url, {
25
- addon_name:,
26
- command: "CONFIG get #{key}"
27
- }
28
- )
23
+ ui.execute_with_loading("Fetching info...") do
24
+ send_request
25
+ end
26
+ print_output
27
+ end
29
28
 
30
- ui.error(response) and return unless response.success?
29
+ private
31
30
 
32
- ui.success(response["message"])
33
- end
31
+ def send_request
32
+ @response = send_patch_request(
33
+ redis_addon_url, {
34
+ addon_name:,
35
+ command: "CONFIG get #{key}"
36
+ }
37
+ )
38
+ end
39
+
40
+ def print_output
41
+ ui.error(@response["error"]) and return unless @response.success?
42
+
43
+ ui.success(@response["message"])
44
+ end
34
45
  end
35
46
  end
36
47
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require_relative "../session"
5
+ require_relative "./constants"
6
+
7
+ module NeetoDeploy
8
+ class CLI
9
+ module Redis
10
+ class ResetStats < CLI::Base
11
+ include Constants
12
+ include Session
13
+
14
+ attr_reader :addon_name
15
+
16
+ def initialize(options)
17
+ super()
18
+ @addon_name = options[:addon_name]
19
+ end
20
+
21
+ def run
22
+ if ui.yes?("Are you sure you want to reset the statistics (y/n)")
23
+ response = send_patch_request(
24
+ redis_addon_url, {
25
+ addon_name:,
26
+ command: "CONFIG RESETSTAT"
27
+ }
28
+ )
29
+ ui.error(response["error"]) and return unless response.success?
30
+
31
+ ui.success("Stats reset successful.")
32
+ else
33
+ puts "Reset cancelled."
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "thor"
4
- require "byebug"
5
4
 
6
5
  require_relative "../session"
7
6
  require_relative "./constants"
@@ -28,16 +27,10 @@ module NeetoDeploy
28
27
  return
29
28
  end
30
29
 
31
- response = send_patch_request(
32
- redis_addon_url, {
33
- addon_name:,
34
- command: "CONFIG set #{key} #{value}"
35
- }
36
- )
37
-
38
- ui.error(response) and return unless response.success?
39
-
40
- ui.success("Done")
30
+ ui.execute_with_loading("Setting config...") do
31
+ send_request
32
+ end
33
+ print_output
41
34
  end
42
35
 
43
36
  private
@@ -45,6 +38,21 @@ module NeetoDeploy
45
38
  def valid_config?
46
39
  AVAILABLE_REDIS_CONFIGS_TO_EDIT.include?(key)
47
40
  end
41
+
42
+ def send_request
43
+ @response = send_patch_request(
44
+ redis_addon_url, {
45
+ addon_name:,
46
+ command: "CONFIG set #{key} #{value}"
47
+ }
48
+ )
49
+ end
50
+
51
+ def print_output
52
+ ui.error(@response["error"]) and return unless @response.success?
53
+
54
+ ui.success("#{key} config for #{addon_name} set to #{value}")
55
+ end
48
56
  end
49
57
  end
50
58
  end
@@ -34,6 +34,13 @@ module NeetoDeploy
34
34
  def info(statement)
35
35
  shell.say(statement)
36
36
  end
37
+
38
+ def execute_with_loading(msg)
39
+ @spinner = TTY::Spinner.new("[:spinner] #{msg}", format: :classic)
40
+ @spinner.auto_spin
41
+ yield
42
+ @spinner.stop
43
+ end
37
44
  end
38
45
  end
39
46
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "thor"
4
+ require 'tty-spinner'
4
5
 
5
6
  # TODO: make this like neetob
6
7
 
@@ -12,6 +13,7 @@ module NeetoDeploy
12
13
  require_relative "cli/logs/base"
13
14
  require_relative "cli/env/commands"
14
15
  require_relative "cli/redis/commands"
16
+ require_relative "cli/addon/commands"
15
17
 
16
18
  def self.start(*)
17
19
  super
@@ -33,12 +35,15 @@ module NeetoDeploy
33
35
 
34
36
  desc "logs", "Show logs"
35
37
  option :app, type: :string, aliases: "-a", required: true, desc: "App slug"
36
- option :process_type, type: :string, aliases: "-p", desc: "Process type"
38
+ option :process_type, type: :string, aliases: "-p", required: true, desc: "Process type"
37
39
  def logs
38
40
  CLI::Logs::Base.new(options[:app], options[:process_type]).process!
39
41
  end
40
42
 
41
43
  desc "redis", "Manage redis addons"
42
44
  subcommand "redis", Redis::Commands
45
+
46
+ desc "addon", "Manage addons"
47
+ subcommand "addon", Addon::Commands
43
48
  end
44
49
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NeetoDeploy
4
- VERSION = "1.1.3"
4
+ VERSION = "1.1.5"
5
5
  CLI_API_VERSION = "v1"
6
6
  end
data/neetodeploy.gemspec CHANGED
@@ -36,6 +36,8 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "terminal-table", "~> 3.0.2" # for building cli table
37
37
  spec.add_dependency "thor", "~> 1.3.0" # for cli
38
38
  spec.add_dependency "websocket-client-simple"
39
+ spec.add_dependency "colorize"
40
+ spec.add_dependency "tty-spinner"
39
41
 
40
42
  # To add the files from submodules
41
43
  `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.3
4
+ version: 1.1.5
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-03-29 00:00:00.000000000 Z
11
+ date: 2024-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -94,6 +94,34 @@ 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'
111
+ - !ruby/object:Gem::Dependency
112
+ name: tty-spinner
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  description: Manage neetoDeploy apps with CLI
98
126
  email:
99
127
  - subin.siby@bigbinary.com
@@ -108,6 +136,9 @@ files:
108
136
  - exe/neetodeploy
109
137
  - lib/neeto_deploy.rb
110
138
  - lib/neeto_deploy/cli.rb
139
+ - lib/neeto_deploy/cli/addon/commands.rb
140
+ - lib/neeto_deploy/cli/addon/constants.rb
141
+ - lib/neeto_deploy/cli/addon/info.rb
111
142
  - lib/neeto_deploy/cli/base.rb
112
143
  - lib/neeto_deploy/cli/env/commands.rb
113
144
  - lib/neeto_deploy/cli/env/constants.rb
@@ -119,9 +150,11 @@ files:
119
150
  - lib/neeto_deploy/cli/login/base.rb
120
151
  - lib/neeto_deploy/cli/login/constants.rb
121
152
  - lib/neeto_deploy/cli/logs/base.rb
153
+ - lib/neeto_deploy/cli/logs/constants.rb
122
154
  - lib/neeto_deploy/cli/redis/commands.rb
123
155
  - lib/neeto_deploy/cli/redis/constants.rb
124
156
  - lib/neeto_deploy/cli/redis/get.rb
157
+ - lib/neeto_deploy/cli/redis/reset_stats.rb
125
158
  - lib/neeto_deploy/cli/redis/set.rb
126
159
  - lib/neeto_deploy/cli/session.rb
127
160
  - lib/neeto_deploy/cli/ui.rb