envoy-cli 1.0.0rc2 → 1.0.0rc3

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
  SHA1:
3
- metadata.gz: 09cc0766e2fbb6a44d96f4cd2ad4e7a3b8012f36
4
- data.tar.gz: b152d8336231821b31d49c66ef5c647004013f12
3
+ metadata.gz: 84db9ede07c7b6cbb7c3157af51a7a7c0bde416e
4
+ data.tar.gz: 87d68a89972eda6528490f9c2892c050fdac1185
5
5
  SHA512:
6
- metadata.gz: e6bd6788c27b249f1a7e33370f7cb400d2a1fd88600bdcd27fe443c6d20e6484f55431867395b4cd08b09f5fc55756e17baf3e9153e6f9d1b7b7ab685ea3ff39
7
- data.tar.gz: d94b22579d54c2e21d04d8618f0dc814e060a4e2825faba6b54852ec8adcf81f1837f91e796622ad048a190504832f9f14d3919490a9cddd62aba3e0d6d562bf
6
+ metadata.gz: 4f5f1dcae476d333e5970571cec0989ec89ecd718b49b4f11806f8e9b55a42340060b8f1b42666d27b7c1bdf19ad3b3ae6a6bc0efebe97a712071ad2de75ece4
7
+ data.tar.gz: e41d62783547a6b6e232a95cc2383fca23243e17a5001ab235e5129e62189b163153ad0001b3d02663deb14cbb4b66c1e3dac04d9c97b0bfe2e5b3a64cb5ee6e
@@ -1,6 +1,3 @@
1
- require:
2
- - rubocop-rspec
3
-
4
1
  AllCops:
5
2
  TargetRubyVersion: 2.3
6
3
  Exclude:
@@ -21,11 +21,13 @@ module Envoy
21
21
  # Authenticates the user by storing their auth_token in ~/.envoy-cfg
22
22
  # @param --local [String] will use localhost:3000 as the API url
23
23
  # @param --endpoint [String] can be used to override the endpoint for this profile
24
+ # @param --production [Boolean] determine if this should be a production release
24
25
  # @param --profile NAME [String] will save the login information for that profile, in order
25
26
  # to use that info, you must specify the same profile name on other requests
26
27
 
27
28
  desc "login", "Login to your account"
28
29
  option :endpoint, type: :string
30
+ option :production, type: :boolean
29
31
 
30
32
  def login
31
33
  # collect login information
@@ -54,9 +56,20 @@ module Envoy
54
56
  'email' => email,
55
57
  'access_token' => res['access_token']
56
58
  }
57
- conf['local'] = true if options.local
59
+ conf['local'] = true if options.local
58
60
  conf['api_path'] = options.endpoint if options.endpoint
59
61
 
62
+ unless options.production || options.local
63
+ say "In order to build plugins for the sandbox server you must provide a tunnel to your localhost.\n"\
64
+ "Once releasing your plugin you will need run `envoy plugin:serve` which defaults to localhost:7722\n"\
65
+ "so if you configure Finch to point my-envoy-plugin.meetfinch.com -> localhost:7722 you would input\n"\
66
+ "https://my-envoy-plugin.meetfinch.com below. Read more at:\n"\
67
+ "https://envoy.gitbooks.io/envoy-plugin/content/local_development.html"
68
+ tunnel_url = prompt.ask "Public Access to Localhost:"
69
+ conf['sandbox'] = true
70
+ conf['tunnel_url'] = tunnel_url
71
+ end
72
+
60
73
  config.params[profile(options)] = conf
61
74
 
62
75
  write_config!
@@ -1,4 +1,6 @@
1
1
  require 'net/http/uploadprogress'
2
+ require 'webrick'
3
+
2
4
  module Envoy
3
5
  class Plugin < Commands
4
6
  include Mixins
@@ -31,7 +33,7 @@ module Envoy
31
33
  end
32
34
 
33
35
  # ask for release notes unless deploying release to local
34
- unless options.local || config[profile]['local']
36
+ unless options.local || config[profile]['local'] || config[profile]['sandbox']
35
37
  notes = ask "Release Notes:"
36
38
  if notes.empty?
37
39
  error "Please provide at least a couple words about what this release is for."
@@ -44,9 +46,9 @@ module Envoy
44
46
  type: 'platform-releases',
45
47
  attributes: {
46
48
  manifest: manifest,
47
- path: options.local ? Dir.pwd : nil,
49
+ path: options.local ? (config[profile]['sandbox'] ? config[profile]['tunnel_url'] : Dir.pwd) : nil,
48
50
  notes: notes || '',
49
- provider: options.local && 'local' || 'lambda',
51
+ provider: options.local && (config[profile]['sandbox'] ? 'webhook' : 'local') || 'lambda',
50
52
  version_type: release_type,
51
53
  version_base: base || nil
52
54
  },
@@ -130,13 +132,53 @@ module Envoy
130
132
  run 'npm i --global-style'
131
133
  end
132
134
 
135
+ desc 'serve', 'Run your plugin localy'
136
+ option :port, type: :string
137
+ def serve
138
+ server = WEBrick::HTTPServer.new Port: options.port || 7722
139
+
140
+ say "✔ Running a dev server at #{options.port || 7722}"
141
+ path = Dir.pwd
142
+ server.mount_proc '/' do |req, res|
143
+ debug("ℹ Request Received", req.body.to_s)
144
+ output = `APP_ROOT_PATH=#{path} #{path}/node_modules/envoy-platform-sdk/bin/invoke local #{req.body} 2>&1`
145
+ debug("ℹ Response Processed", output)
146
+ res.body = output
147
+ end
148
+ server.start
149
+ trap 'INT' do server.shutdown end
150
+ end
151
+
152
+ desc 'tail', 'Tail plugin events live'
153
+ def tail
154
+ since = nil
155
+ entries = false
156
+ loop do
157
+ res = jsonapi_get('Polling Events', './platform/events', {
158
+ plugin_id: plugin_uuid,
159
+ 'filter[since]': since
160
+ })
161
+ unless res['data'].empty?
162
+ since = res['data'][0]['attributes']['created-at']
163
+ end
164
+ res['data'].reverse.each do |event|
165
+ if entries
166
+ puts "\n\n\n\n"
167
+ end
168
+ entries = true
169
+ print_event event
170
+ end
171
+ sleep(3)
172
+ end
173
+ end
174
+
133
175
  desc 'init <dir>', 'Initialize your plugin'
134
176
  option :bootstrap, type: :boolean
135
177
  def init(dir = false)
136
178
  bootstrap = options.bootstrap
137
179
  if dir
138
180
  # @TODO create dir if it doesn't already exist
139
- unless Dir.exists? dir
181
+ unless Dir.exist? dir
140
182
  Dir.mkdir dir
141
183
  end
142
184
  Dir.chdir dir
@@ -1,3 +1,3 @@
1
1
  module Envoy
2
- VERSION = "1.0.0rc2".freeze
2
+ VERSION = "1.0.0rc3".freeze
3
3
  end
@@ -42,6 +42,40 @@ module Envoy
42
42
  post(info, path, { data: body }.to_json, headers)
43
43
  end
44
44
 
45
+ def get!(path, params = {}, headers = {})
46
+ debug('Start', "GET #{base_url(path)}")
47
+ debug('Params', CodeRay.scan(JSON.pretty_generate(params.is_a?(Hash) && params || JSON.parse(params)), :json).terminal)
48
+ res = Unirest.get(base_url(path), parameters: params, headers: headers)
49
+ debug("End", res.code.to_s)
50
+ if res.body.instance_of?(Hash)
51
+ debug("Body", CodeRay.scan(JSON.pretty_generate(res.body), :json).terminal)
52
+ else
53
+ debug("Body", res.body.to_s)
54
+ end
55
+ res
56
+ rescue => e
57
+ # puts e.message
58
+ error(e.message)
59
+ exit
60
+ end
61
+
62
+ def get(info, *args)
63
+ spin("Network: #{info}")
64
+ res = get!(*args)
65
+ if res.code.between?(200, 299)
66
+ spin_success
67
+ else
68
+ handle_errors(res)
69
+ end
70
+ res.body
71
+ end
72
+
73
+ def jsonapi_get(info, path, params = {}, headers = {})
74
+ headers[:'Content-Type'] = 'application/json'
75
+ headers[:Authorization] = "Bearer #{config[profile]['access_token']}"
76
+ get(info, path, params, headers)
77
+ end
78
+
45
79
  def error(msg)
46
80
  if spinner
47
81
  spin_error msg
@@ -93,15 +127,21 @@ module Envoy
93
127
  local = true
94
128
  end
95
129
  if local
96
- if cfg && cfg['api_path_local']
130
+ if cfg && cfg['sandbox']
131
+ base = cfg['api_path'] || 'https://sandbox-app.envoy.com'
132
+ elsif cfg && cfg['api_path_local']
97
133
  base = cfg['api_path_local']
98
134
  else
99
135
  base = 'http://localhost:3000'
100
136
  end
101
- elsif ignore_profile && options.path
102
- base = options.path
137
+ elsif ignore_profile && options.endpoint
138
+ base = options.endpoint
139
+ elsif ignore_profile && !options.production
140
+ base = 'https://sandbox-app.envoy.com'
103
141
  elsif cfg && cfg['api_path']
104
142
  base = cfg['api_path']
143
+ elsif cfg && cfg['sandbox']
144
+ base = 'https://sandbox-app.envoy.com'
105
145
  else
106
146
  base = 'https://app.envoy.com'
107
147
  end
@@ -176,19 +216,19 @@ module Envoy
176
216
  say "Execution Time =>".yellow + " #{data['process-time']}ms"
177
217
  say "\n"
178
218
  say "REQUEST META"
179
- req_h = JSON.pretty_generate Envoy.min_json(data['request-meta'] || {})
219
+ req_h = JSON.pretty_generate min_json(data['request-meta'] || {})
180
220
  say CodeRay.scan(req_h, :json).terminal(line_numbers: :table)
181
221
  say "\n"
182
222
  say "REQUEST BODY"
183
- req_h = JSON.pretty_generate Envoy.min_json(data['request-body'] || {})
223
+ req_h = JSON.pretty_generate min_json(data['request-body'] || {})
184
224
  say CodeRay.scan(req_h, :json).terminal(line_numbers: :table)
185
225
  say "\n"
186
226
  say "REPONSE META"
187
- req_h = JSON.pretty_generate Envoy.min_json(data['response-meta'] || {})
227
+ req_h = JSON.pretty_generate min_json(data['response-meta'] || {})
188
228
  say CodeRay.scan(req_h, :json).terminal(line_numbers: :table)
189
229
  say "\n"
190
230
  say "RESPONSE BODY"
191
- req_h = JSON.pretty_generate Envoy.min_json(data['response-body'] || {})
231
+ req_h = JSON.pretty_generate min_json(data['response-body'] || {})
192
232
  say CodeRay.scan(req_h, :json).terminal(line_numbers: :table)
193
233
  say "\n"
194
234
  say "LOG ENTRIES"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envoy-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0rc2
4
+ version: 1.0.0rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Boskovic
@@ -269,9 +269,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
269
  version: 1.3.1
270
270
  requirements: []
271
271
  rubyforge_project:
272
- rubygems_version: 2.6.4
272
+ rubygems_version: 2.5.1
273
273
  signing_key:
274
274
  specification_version: 4
275
275
  summary: Envoy platform command line interface.
276
276
  test_files: []
277
- has_rdoc: