cardano-up 0.1.1 → 0.1.2

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: ffd6230a971acea78415e9789e6b605ad493dee667afe4acd5f123759df90867
4
- data.tar.gz: 20af817f4b0918d29b5b75dc6bea54d59fc3e5e6ee61d974888a69ffd8dce357
3
+ metadata.gz: 7dc6e5153ea10a283c8076a763034d89334e0ec285265ce8fa47cb7d41dddbaa
4
+ data.tar.gz: fc58a1646113ff3c52faaadb6807f1147029a4716d06b750f07783041eac4149
5
5
  SHA512:
6
- metadata.gz: 46d6f2e0f2398aa1416ab61e1f49684aa5b07389efce583f00ab973b46f5c91246aea9a71f27bb03717ed0101ef27cff9547adf366469650d9b03d25ff7dd8b9
7
- data.tar.gz: bcc306a1b9ac5a7debee61df90fe659bfc3df4f4cc309317ba334193c6cf421c9810a88c5100639994bc9e5494c678fc171cf9fd308cd7c3937e4e658b516270
6
+ metadata.gz: e098510d7c479a9d1570c1f9ba803875908b509365b556045c8530f1548e13356593592c3985c30d6711c84c2afd077b54cd417bf5eba0505590bb9b1b6fb30d
7
+ data.tar.gz: 54d8a545a3f1ebdea7cca06829672c337de7eac3403469d6ed33033869e7e08431b86dd495be49def0359063d004c0a363fdba397a8cd69ef4852d852582aa92
data/README.md CHANGED
@@ -29,21 +29,26 @@ This Ruby gem provides easy way for:
29
29
 
30
30
  It only takes a single command to start node and wallet on your system. Say, on `mainnet`?
31
31
 
32
- $ cardano-up mainnet node-wallet up
32
+ $ cardano-up mainnet up
33
33
 
34
34
  That's it! 🎉
35
35
 
36
36
  If any configs are missing cardano-up will download them. If any binaries are missing cardano-up will get ones from latest release.
37
37
 
38
- Call `$ cardano-up --help` to explore more options.
38
+ To explore more options call:
39
+
40
+ $ cardano-up --help
41
+ $ cardano-up --examples
39
42
 
40
43
  ## Documentation
41
44
 
42
45
  | Link | Description |
43
46
  |--|--|
47
+ | [Usage examples](https://github.com/piotr-iohk/cardano-up/wiki/Usage-Examples) | Also available in `$ cardano-up --examples` |
44
48
  | [Ruby API (edge)](https://piotr-iohk.github.io/cardano-up/master/) | cardano-up API doc |
45
49
 
46
50
  ## How it works
51
+ By default cardano-up keeps all files at `$HOME/.cardano-up/` however this can be configured by editing `$HOME/.cardano-up/.cardano-up.json` directly or via `config` sub-command. One can check the contents of this internal config file by calling `$ cardano-up config`.
47
52
 
48
53
  **Configurations** for the networks are downloaded from [Cardano Book](https://book.world.dev.cardano.org/environments.html).
49
54
 
@@ -65,8 +70,8 @@ In case of Windows it will attempt to install cardano-node and cardano-wallet as
65
70
 
66
71
  > :warning: nssm requires administrator permissions to register Windows services, therefore you need to start your cmd as an administrator.
67
72
 
68
- By default cardano-up keeps all files at `$HOME/.cardano-up/` however this can be configured by editing `$HOME/.cardano-up/.cardano-up.json` directly or via `config` sub-command. One can check the contents of this internal config file by calling `$ cardano-up config`.
73
+ There is also basic **session management** in cardano-up. In a single session you can have at most 1 node and 1 wallet for particular network. Because of the sessions you can quickly check details of your running components (like where are the log or database files or what ports are used) and you have some basic tools to monitor them (via `tail` and `ping` subcommands).
69
74
 
70
75
  ## License
71
76
 
72
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
77
+ The gem is available as open source under the terms of the [MIT License](https://github.com/piotr-iohk/cardano-up/blob/master/LICENSE.txt).
data/bin/cardano-up CHANGED
@@ -11,16 +11,17 @@ doc = <<~DOCOPT
11
11
  Usage:
12
12
  #{File.basename(__FILE__)} install [<release>]
13
13
  #{File.basename(__FILE__)} get-configs <env>
14
- #{File.basename(__FILE__)} <env> (node|wallet|node-wallet) up [--port <port>]
15
- #{File.basename(__FILE__)} <env> (node|wallet|node-wallet) down
16
- #{File.basename(__FILE__)} <env> (node|wallet) tail
14
+ #{File.basename(__FILE__)} ls
17
15
  #{File.basename(__FILE__)} config [--set-default] [--bindir <path>] [--configdir <path>] [--logdir <path>] [--statedir <path>]
16
+ #{File.basename(__FILE__)} <env> [(node|wallet)] [(up|down|ping)] [--port <port>] [--session <name>]
17
+ #{File.basename(__FILE__)} <env> (node|wallet) tail [--session <name>]
18
18
  #{File.basename(__FILE__)} -v | --version
19
+ #{File.basename(__FILE__)} -e | --examples
19
20
  #{File.basename(__FILE__)} -h | --help
20
21
 
21
22
  Options:
22
23
  install Install cardano-node, cardano-cli, cardano-wallet, cardano-addresses and bech32.
23
- <release> latest | release tag | master | pr num [default: latest]
24
+ <release> latest | release tag | master | pr num. [default: latest]
24
25
  get-configs Get configs for particular Cardano environment.
25
26
  <env> mainnet | preview | preprod etc.
26
27
  up Start particular service. If any configs are missing #{File.basename(__FILE__)}
@@ -28,7 +29,11 @@ doc = <<~DOCOPT
28
29
  ones from latest release.
29
30
  down Stop particular service.
30
31
  tail Follow logs for particular service.
31
- --port <port> Specify wallet port. [default: 8090]
32
+ ping Ping service to check its status.
33
+ ls List sessions.
34
+ -p --port <port> Specify wallet port. [default: 8090]
35
+ -s --session <name> Set session name. In single session you can have
36
+ at most 1 node and 1 wallet for particular <env>. [default: 0]
32
37
 
33
38
  config Internal config for #{File.basename(__FILE__)}
34
39
  --set-default Overwrite config with default values.
@@ -39,31 +44,105 @@ doc = <<~DOCOPT
39
44
 
40
45
  -v --version Check #{File.basename(__FILE__)} version and versions of
41
46
  installed binaries if available.
47
+ -e --examples Show some usage examples.
42
48
  -h --help This help.
43
49
  DOCOPT
44
50
 
45
51
  def pretty_json(c)
46
- puts JSON.pretty_generate(c)
52
+ if c.is_a?(Hash)
53
+ puts JSON.pretty_generate(c)
54
+ else
55
+ warn c
56
+ end
47
57
  end
48
58
 
49
59
  def ok
50
60
  warn 'Ok.'
51
61
  end
52
62
 
63
+ def not_ok
64
+ warn '⚠️ Not ok.'
65
+ end
66
+
53
67
  begin
54
68
  CardanoUp.configure_default unless CardanoUp.configured?
55
69
  o = Docopt.docopt(doc)
70
+ # pretty_json o
71
+
72
+ # EXAMPLES
73
+ if o['--examples'] == true
74
+ warn %(INTERNAL CONFIG:
75
+ ------------------------------
76
+ Check internal config file contents:
77
+
78
+ $ #{File.basename(__FILE__)} config
79
+
80
+ BINARIES AND NETWORK CONFIGS:
81
+ ------------------------------
82
+ Get latest release binaries and verify versions:
83
+
84
+ $ #{File.basename(__FILE__)} install latest
85
+ $ #{File.basename(__FILE__)} -v
86
+
87
+ Get configuration for 'preview' network:
88
+
89
+ $ #{File.basename(__FILE__)} get-configs preview
90
+
91
+ SERVICE MANAGEMENT:
92
+ ------------------------------
93
+ > Note: If you have no configs for particular env 'up'
94
+ subcommand will download them on the fly. If no binaries,
95
+ latest release will be installed, otherwise it will use
96
+ what is in the 'bin_dir'.
97
+
98
+ Start node and wallet on mainnet:
99
+
100
+ $ #{File.basename(__FILE__)} mainnet up
101
+
102
+ Start node on preprod:
103
+
104
+ $ #{File.basename(__FILE__)} preprod node up
105
+
106
+ Check active sessions:
107
+
108
+ $ #{File.basename(__FILE__)} ls
109
+
110
+ Check details of what is running on mainnet and preprod or details of given component:
111
+
112
+ $ #{File.basename(__FILE__)} mainnet
113
+ $ #{File.basename(__FILE__)} preprod
114
+ $ #{File.basename(__FILE__)} mainnet wallet
115
+ $ #{File.basename(__FILE__)} preprod node
116
+
117
+ Check health of node and wallet on mainnet:
118
+
119
+ $ #{File.basename(__FILE__)} mainnet node ping
120
+ $ #{File.basename(__FILE__)} mainnet wallet ping
56
121
 
122
+ Monitor mainnet wallet and node logs (Ctrl + c to stop):
123
+
124
+ $ #{File.basename(__FILE__)} mainnet node tail
125
+ $ #{File.basename(__FILE__)} mainnet wallet tail
126
+
127
+ Stop preprod node:
128
+
129
+ $ #{File.basename(__FILE__)} preprod node down
130
+
131
+ Stop mainnet node and wallet:
132
+
133
+ $ #{File.basename(__FILE__)} mainnet down
134
+ )
135
+ end
57
136
  # VERSION
58
137
  if o['--version'] == true
59
138
  warn "#{File.basename(__FILE__)}: #{CardanoUp::VERSION}"
60
139
  $stderr.puts
61
140
  begin
62
- pretty_json CardanoUp::Install.return_versions
141
+ pretty_json CardanoUp::Bins.return_versions
63
142
  rescue StandardError => e
64
143
  warn 'Nothing installed? To fix run:'
65
144
  warn " $ #{File.basename(__FILE__)} install"
66
- warn e
145
+ warn "⚠️ #{e}"
67
146
  end
68
147
  end
69
148
 
@@ -103,16 +182,20 @@ begin
103
182
 
104
183
  # INSTALL
105
184
  if o['install'] == true
106
- release = o['<release>']
185
+ release = o['<release>'] || 'latest'
107
186
  begin
108
187
  $stderr.print "Installing '#{release}'... "
109
- versions = CardanoUp::Install.install_bins(release)
188
+ versions = CardanoUp::Bins.install(release)
110
189
  ok
111
190
  rescue CardanoUp::VersionNotSupportedError => e
112
191
  warn(e.message)
113
192
  exit 1
193
+ rescue Errno::ETXTBSY => e
194
+ warn("Couldn't unpack binaries, perhaps some file is in use?")
195
+ warn(e.message)
196
+ exit 1
114
197
  end
115
- warn "Install dir: #{CardanoUp.config['bin_dir']}"
198
+ warn "Install dir: #{CardanoUp.config[:bin_dir]}"
116
199
  $stderr.puts
117
200
  pretty_json(versions)
118
201
  exit
@@ -122,13 +205,13 @@ begin
122
205
  if o['get-configs'] == true
123
206
  env = o['<env>']
124
207
  begin
125
- configs = CardanoUp::Install.install_configs(env)
208
+ configs = CardanoUp::Configs.get(env)
126
209
  rescue CardanoUp::EnvNotSupportedError => e
127
210
  warn(e.message)
128
211
  exit 1
129
212
  end
130
213
  warn "Downloaded configs for '#{env}' environment."
131
- warn "Config dir: #{File.join(CardanoUp.config['config_dir'], env)}"
214
+ warn "Config dir: #{File.join(CardanoUp.config[:config_dir], env)}"
132
215
  $stderr.puts
133
216
  pretty_json(configs)
134
217
  exit
@@ -138,80 +221,103 @@ begin
138
221
  if o['up'] == true
139
222
  env = o['<env>']
140
223
  port = o['--port']
224
+ session_name = o['--session']
141
225
 
142
226
  begin
143
227
  $stderr.print 'Configs: '
144
- unless CardanoUp::Install.configs_exist?(env)
228
+ unless CardanoUp::Configs.exist?(env)
145
229
  $stderr.print "installing configs for #{env}... "
146
- CardanoUp::Install.install_configs(env)
230
+ CardanoUp::Configs.get(env)
147
231
  end
148
232
  ok
149
233
 
150
234
  $stderr.print 'Binaries: '
151
235
  begin
152
- CardanoUp::Install.return_versions
236
+ CardanoUp::Bins.return_versions
153
237
  ok
154
238
  rescue StandardError
155
239
  $stderr.print 'installing latest release binaries... '
156
- CardanoUp::Install.install_bins('latest')
240
+ CardanoUp::Bins.install('latest')
157
241
  ok
158
242
  end
159
243
 
160
244
  $stderr.puts
161
245
  warn 'Starting...'
162
246
  $stderr.puts
163
- c = CardanoUp::Start.prepare_configuration({ env: env, wallet_port: port })
164
- rescue CardanoUp::EnvNotSupportedError => e
165
- warn(e.message)
166
- exit 1
167
- end
168
- begin
247
+ c = CardanoUp::Launcher.setup({ env: env, wallet_port: port, session_name: session_name })
248
+
169
249
  if o['node']
170
- pretty_json CardanoUp::Start.start_node(c)
250
+ pretty_json CardanoUp::Launcher.node_up(c)
171
251
  $stderr.puts
172
252
  warn "Congratulations! You've just started cardano-node!"
173
253
  elsif o['wallet']
174
- pretty_json CardanoUp::Start.start_wallet(c)
254
+ pretty_json CardanoUp::Launcher.wallet_up(c)
175
255
  $stderr.puts
176
256
  warn "Congratulations! You've just started cardano-wallet!"
177
- elsif o['node-wallet']
178
- pretty_json CardanoUp::Start.start_node_and_wallet(c)
257
+ else
258
+ n = CardanoUp::Launcher.node_up(c)
259
+ w = CardanoUp::Launcher.wallet_up(c)
260
+ pretty_json(n.merge(w))
179
261
  $stderr.puts
180
262
  warn "Congratulations! You've just started cardano-node and cardano-wallet!"
181
263
  end
264
+ rescue CardanoUp::EnvNotSupportedError => e
265
+ warn "⚠️ #{e}"
266
+ exit 1
267
+ rescue CardanoUp::SessionHasNodeError => e
268
+ warn "⚠️ #{e}"
269
+ $stderr.puts
270
+ warn "If you'd like to start another node instance after all:"
271
+ warn " $ #{File.basename(__FILE__)} #{env} node up -s <some_name>"
272
+ exit 1
273
+ rescue CardanoUp::SessionHasWalletError, CardanoUp::WalletPortUsedError => e
274
+ warn "⚠️ #{e}"
275
+ $stderr.puts
276
+ warn "If you'd like to start another wallet instance after all:"
277
+ warn " $ #{File.basename(__FILE__)} #{env} wallet up -s <some_name> --port <different_port>"
278
+ exit 1
182
279
  rescue StandardError => e
183
280
  warn 'Either you miss configs or binaries... To fix that try running:'
184
281
  warn " $ #{File.basename(__FILE__)} get-configs #{env}"
185
282
  warn " $ #{File.basename(__FILE__)} install"
186
- warn e
283
+ warn "⚠️ #{e}"
187
284
  exit 1
188
285
  end
189
- end
190
286
 
191
- # STOP
192
- if o['down'] == true
287
+ # DOWN
288
+ elsif o['down'] == true
193
289
  env = o['<env>']
194
-
290
+ session_name = o['--session']
291
+ warn "Stopping service on '#{env}' in session '#{session_name}'..."
195
292
  begin
196
293
  if o['node']
197
- CardanoUp::Start.stop_node(env)
294
+ CardanoUp::Launcher.node_down(env, session_name)
295
+ warn 'Node stopped.'
198
296
  elsif o['wallet']
199
- CardanoUp::Start.stop_wallet(env)
200
- elsif o['node-wallet']
201
- CardanoUp::Start.stop_node_and_wallet(env)
297
+ CardanoUp::Launcher.wallet_down(env, session_name)
298
+ warn 'Wallet stopped.'
299
+ else
300
+ CardanoUp::Launcher.node_down(env, session_name)
301
+ warn 'Node stopped.'
302
+ begin
303
+ CardanoUp::Launcher.wallet_down(env, session_name)
304
+ rescue CardanoUp::SessionNotExistsError
305
+ # in case node_down kills session (i.e. it was the last service killed)
306
+ exit
307
+ end
308
+ warn 'Wallet stopped.'
202
309
  end
203
- warn 'Stopped.'
204
- rescue CardanoUp::EnvNotSupportedError => e
205
- warn(e.message)
310
+ rescue CardanoUp::EnvNotSupportedError, CardanoUp::SessionNotExistsError => e
311
+ warn "⚠️ #{e}"
206
312
  exit 1
207
313
  end
208
- end
209
314
 
210
315
  # TAIL
211
- if o['tail'] == true
316
+ elsif o['tail'] == true
212
317
  env = o['<env>']
318
+ session_name = o['--session']
213
319
  begin
214
- log_dir = File.join(CardanoUp.config['log_dir'], env)
320
+ log_dir = File.join(CardanoUp.config[:log_dir], session_name, env)
215
321
  if o['node']
216
322
  log_file = File.join(log_dir, 'node.log')
217
323
  CardanoUp::Tail.tail(log_file)
@@ -227,8 +333,123 @@ begin
227
333
  warn(e.message)
228
334
  exit 1
229
335
  rescue Interrupt
336
+ # on ctrl + c don't show stack trace
337
+ $stderr.puts
338
+ end
339
+
340
+ # PING
341
+ elsif o['ping']
342
+ begin
343
+ session_name = o['--session']
344
+ env = o['<env>']
345
+ CardanoUp::Configs.exist?(env)
346
+ sessions = CardanoUp::Session.get(session_name)
347
+ CardanoUp::Session.network_or_raise?(session_name, env.to_sym)
348
+ warn "Ping {env: #{env}, session: #{session_name}}:"
349
+
350
+ if o['node']
351
+ CardanoUp::Session.node_or_raise?(session_name, env.to_sym)
352
+ $stderr.print 'Node ping... '
353
+ r, c = CardanoUp::Ping.node(session_name, env)
354
+ c == 200 ? ok : not_ok
355
+ pretty_json r
356
+ elsif o['wallet']
357
+ CardanoUp::Session.wallet_or_raise?(session_name, env.to_sym)
358
+ url = sessions[env.to_sym][:wallet][:url]
359
+ $stderr.print "Wallet ping (url: #{url})... "
360
+ r, c = CardanoUp::Ping.wallet(session_name, env)
361
+ c == 200 ? ok : not_ok
362
+ pretty_json r
363
+ else
364
+ warn 'Use: '
365
+ warn " $ #{File.basename(__FILE__)} #{env} node ping -s #{session_name}"
366
+ warn " $ #{File.basename(__FILE__)} #{env} wallet ping -s #{session_name}"
367
+ end
368
+ rescue Errno::ECONNREFUSED,
369
+ CardanoUp::EnvNotSupportedError => e
370
+ warn "⚠️ #{e}"
371
+ exit 1
372
+ rescue CardanoUp::SessionNotExistsError,
373
+ CardanoUp::SessionEnvNotUpError,
374
+ CardanoUp::SessionServiceNotUpError => e
375
+ warn "⚠️ #{e}"
376
+ warn 'To list active sessions call: '
377
+ warn " $ #{File.basename(__FILE__)} ls"
378
+ exit 1
379
+ rescue Interrupt
380
+ # on ctrl + c don't show stack trace
381
+ $stderr.puts
230
382
  exit
231
383
  end
384
+
385
+ # Session STATUS
386
+ elsif o['<env>']
387
+ session_name = o['--session']
388
+ env = o['<env>']
389
+ begin
390
+ CardanoUp::Configs.exist?(env)
391
+ sessions = CardanoUp::Session.get(session_name)
392
+ CardanoUp::Session.network_or_raise?(session_name, env.to_sym)
393
+
394
+ if o['node']
395
+ CardanoUp::Session.node_or_raise?(session_name, env.to_sym)
396
+ warn "Node details {env: #{env}, session: #{session_name}}:"
397
+ warn "For health-check: $ #{File.basename(__FILE__)} #{env} node ping -s #{session_name}"
398
+ $stderr.puts
399
+ node = sessions[env.to_sym][:node]
400
+ pretty_json node
401
+ elsif o['wallet']
402
+ CardanoUp::Session.wallet_or_raise?(session_name, env.to_sym)
403
+ warn "Wallet details {env: #{env}, session: #{session_name}}:"
404
+ warn "For health-check: $ #{File.basename(__FILE__)} #{env} wallet ping -s #{session_name}"
405
+ $stderr.puts
406
+ wallet = sessions[env.to_sym][:wallet]
407
+ pretty_json wallet
408
+ else
409
+ warn "Details {env: #{env}, session: #{session_name}}:"
410
+ $stderr.puts
411
+ pretty_json sessions[env.to_sym]
412
+ end
413
+ rescue CardanoUp::EnvNotSupportedError => e
414
+ warn "⚠️ #{e}"
415
+ exit 1
416
+ rescue CardanoUp::SessionNotExistsError,
417
+ CardanoUp::SessionEnvNotUpError,
418
+ CardanoUp::SessionServiceNotUpError => e
419
+ warn "⚠️ #{e}"
420
+ warn 'To list active sessions call: '
421
+ warn " $ #{File.basename(__FILE__)} ls"
422
+ exit 1
423
+ end
424
+ end
425
+
426
+ # LS
427
+ if o['ls']
428
+ sessions = CardanoUp::Session.list_all
429
+
430
+ def list_extended(sessions)
431
+ sessions.map do |s|
432
+ session_name = File.basename(s)[/.session-(.+).json/, 1]
433
+ s_det = CardanoUp::Session.get(session_name)
434
+ warn " #{session_name}:"
435
+ s_det.each_key do |env|
436
+ warn " #{env}:"
437
+ s_det[env].each_key do |service|
438
+ warn " #{service} (#{s_det[env][service][:service]})" if service == :node
439
+ if service == :wallet
440
+ warn " #{service} (#{s_det[env][service][:service]}, port: #{s_det[env][service][:port]})"
441
+ end
442
+ end
443
+ end
444
+ end
445
+ end
446
+
447
+ if sessions.empty?
448
+ warn 'No active sessions.'
449
+ else
450
+ warn 'Sessions:'
451
+ list_extended(sessions)
452
+ end
232
453
  end
233
454
  rescue Docopt::Exit => e
234
455
  puts e.message
@@ -1,49 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CardanoUp
4
- # Installing configs for Cardano environments and binaries
5
- module Install
6
- # Check all necessary config files for particular environment exist.
7
- # @param env [String] - one of {ENVS}
8
- # @raise CardanoUp::EnvNotSupportedError
9
- def self.configs_exist?(env)
10
- CardanoUp.configure_default unless CardanoUp.configured?
11
- raise CardanoUp::EnvNotSupportedError, env unless CardanoUp::ENVS.include?(env)
12
-
13
- configs = CardanoUp.config
14
- config_dir_env = FileUtils.mkdir_p(File.join(configs['config_dir'], env))
15
- config_files = CardanoUp::CONFIG_FILES
16
- not_existing = []
17
- config_files.each do |file|
18
- conf_file_path = File.join(config_dir_env, file)
19
- not_existing << conf_file_path unless File.exist?(conf_file_path)
20
- end
21
- not_existing.empty?
22
- end
23
-
24
- # Get all necessary config files for particular environment.
25
- # @param env [String] - one of {ENVS}
26
- # @raise CardanoUp::EnvNotSupportedError
27
- def self.install_configs(env)
28
- CardanoUp.configure_default unless CardanoUp.configured?
29
- raise CardanoUp::EnvNotSupportedError, env unless CardanoUp::ENVS.include?(env)
30
-
31
- configs = CardanoUp.config
32
- config_urls = CardanoUp::Utils.config_urls(env)
33
- config_dir_env = FileUtils.mkdir_p(File.join(configs['config_dir'], env))
34
- config_urls.each do |url|
35
- CardanoUp::Utils.wget(url, File.join(config_dir_env, File.basename(url)))
36
- end
37
- end
38
-
4
+ # Installing binaries for Cardano
5
+ module Bins
39
6
  # Get cardano-wallet bundle binaries to your computer.
40
7
  # @param release [String] - 'latest' | /^v20.{2}-.{2}-.{2}/ | 'master' | '3341'
41
8
  # @raise CardanoUp::VersionNotSupportedError
42
- def self.install_bins(release)
9
+ def self.install(release)
43
10
  CardanoUp.configure_default unless CardanoUp.configured?
44
11
  configs = CardanoUp.config
45
12
  url = CardanoUp::Utils.get_binary_url(release)
46
- bin_dir_env = FileUtils.mkdir_p(configs['bin_dir']).first
13
+ bin_dir_env = FileUtils.mkdir_p(configs[:bin_dir]).first
47
14
  file_to_unpack = File.join(bin_dir_env, 'binary-dist')
48
15
  CardanoUp::Utils.wget(url, file_to_unpack)
49
16
 
@@ -51,6 +18,23 @@ module CardanoUp
51
18
  return_versions(bin_dir_env)
52
19
  end
53
20
 
21
+ # Return versions of installed components
22
+ # @raise CardanoUp::ConfigNotSetError
23
+ def self.return_versions(bin_dir = nil)
24
+ bindir = bin_dir.nil? ? CardanoUp.config[:bin_dir] : bin_dir
25
+ exe = CardanoUp::Utils.win? ? '.exe' : ''
26
+ cn = CardanoUp::Utils.cmd "#{bindir}/cardano-node#{exe} version"
27
+ cli = CardanoUp::Utils.cmd "#{bindir}/cardano-cli#{exe} version"
28
+ cw = CardanoUp::Utils.cmd "#{bindir}/cardano-wallet#{exe} version"
29
+ ca = CardanoUp::Utils.cmd "#{bindir}/cardano-address#{exe} version"
30
+ b32 = CardanoUp::Utils.cmd "#{bindir}/bech32#{exe} --version"
31
+ { 'cardano-node' => cn,
32
+ 'cardano-cli' => cli,
33
+ 'cardano-wallet' => cw,
34
+ 'cardano-address' => ca,
35
+ 'bech32' => b32 }
36
+ end
37
+
54
38
  def unpack_binary(file_path, destination)
55
39
  if CardanoUp::Utils.win?
56
40
  CardanoUp::Tar.unzip(file_path, destination)
@@ -68,22 +52,5 @@ module CardanoUp
68
52
  end
69
53
  module_function :unpack_binary
70
54
  private_class_method :unpack_binary
71
-
72
- # Return versions of installed components
73
- # @raise CardanoUp::ConfigNotSetError
74
- def self.return_versions(bin_dir = nil)
75
- bindir = bin_dir.nil? ? CardanoUp.config['bin_dir'] : bin_dir
76
- exe = CardanoUp::Utils.win? ? '.exe' : ''
77
- cn = CardanoUp::Utils.cmd "#{bindir}/cardano-node#{exe} version"
78
- cli = CardanoUp::Utils.cmd "#{bindir}/cardano-cli#{exe} version"
79
- cw = CardanoUp::Utils.cmd "#{bindir}/cardano-wallet#{exe} version"
80
- ca = CardanoUp::Utils.cmd "#{bindir}/cardano-address#{exe} version"
81
- b32 = CardanoUp::Utils.cmd "#{bindir}/bech32#{exe} --version"
82
- { 'cardano-node' => cn,
83
- 'cardano-cli' => cli,
84
- 'cardano-wallet' => cw,
85
- 'cardano-address' => ca,
86
- 'bech32' => b32 }
87
- end
88
55
  end
89
56
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CardanoUp
4
+ # Installing configs Cardano environments
5
+ module Configs
6
+ # Check all necessary config files for particular environment exist.
7
+ # @param env [String] - one of {ENVS}
8
+ # @raise CardanoUp::EnvNotSupportedError
9
+ def self.exist?(env)
10
+ CardanoUp.configure_default unless CardanoUp.configured?
11
+ raise CardanoUp::EnvNotSupportedError, env unless CardanoUp::ENVS.include?(env)
12
+
13
+ configs = CardanoUp.config
14
+ config_dir_env = FileUtils.mkdir_p(File.join(configs[:config_dir], env))
15
+ config_files = CardanoUp::CONFIG_FILES
16
+ not_existing = []
17
+ config_files.each do |file|
18
+ conf_file_path = File.join(config_dir_env, file)
19
+ not_existing << conf_file_path unless File.exist?(conf_file_path)
20
+ end
21
+ not_existing.empty?
22
+ end
23
+
24
+ # Get all necessary config files for particular environment.
25
+ # @param env [String] - one of {ENVS}
26
+ # @raise CardanoUp::EnvNotSupportedError
27
+ def self.get(env)
28
+ CardanoUp.configure_default unless CardanoUp.configured?
29
+ raise CardanoUp::EnvNotSupportedError, env unless CardanoUp::ENVS.include?(env)
30
+
31
+ configs = CardanoUp.config
32
+ config_urls = CardanoUp::Utils.config_urls(env)
33
+ config_dir_env = FileUtils.mkdir_p(File.join(configs[:config_dir], env))
34
+ config_urls.each do |url|
35
+ CardanoUp::Utils.wget(url, File.join(config_dir_env, File.basename(url)))
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,6 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CardanoUp
4
+ # Thrown when service not exists in session
5
+ class SessionServiceNotUpError < StandardError
6
+ def initialize(session_name, env, service)
7
+ super("Service '#{service}' is not running on '#{env}' in session '#{session_name}'!")
8
+ end
9
+ end
10
+
11
+ # Thrown when env not exists in session
12
+ class SessionEnvNotUpError < StandardError
13
+ def initialize(session_name, env)
14
+ super("Nothing is running on '#{env}' in session '#{session_name}'!")
15
+ end
16
+ end
17
+
18
+ # Thrown when session not exists
19
+ class SessionNotExistsError < StandardError
20
+ def initialize(session_name)
21
+ super("Session '#{session_name}' does not exist!")
22
+ end
23
+ end
24
+
25
+ # Thrown when there is already a node running in the session
26
+ class SessionHasNodeError < StandardError
27
+ def initialize(session_name, network)
28
+ super("Session '#{session_name}' already has node running on '#{network}'!")
29
+ end
30
+ end
31
+
32
+ # Thrown when there is already a wallet running in the session
33
+ class SessionHasWalletError < StandardError
34
+ def initialize(session_name, network)
35
+ super("Session '#{session_name}' already has wallet running on '#{network}'!")
36
+ end
37
+ end
38
+
4
39
  # Thrown when env is not supported
5
40
  class EnvNotSupportedError < StandardError
6
41
  def initialize(env)
@@ -22,6 +57,13 @@ module CardanoUp
22
57
  end
23
58
  end
24
59
 
60
+ # Thrown when wallet port is not set
61
+ class WalletPortUsedError < StandardError
62
+ def initialize(port)
63
+ super("The port #{port} is already in use!")
64
+ end
65
+ end
66
+
25
67
  # Thrown when version of bundle to download is not supported
26
68
  class VersionNotSupportedError < StandardError
27
69
  def initialize(ver)