mtncloud-cli 1.0.1 → 1.0.2

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: c74ca2c70a2b0a12b972e2c0d9837321807c6c50e083850f7750cb8d236af074
4
- data.tar.gz: 4ea3f71ff8652b53c20c067f08e4fe7ce3cf4729a4716b8246a279312d6b721c
3
+ metadata.gz: b3a5dc76695dc9b45484493d57dc18f76a6421b860734528495d877ac6d19d4a
4
+ data.tar.gz: e8c2396dc112b8cd25ba5887caf3bbc259a9ab77b04f3f828d546918dbaf111c
5
5
  SHA512:
6
- metadata.gz: 3c9c7c54b4ab29be0a10e94371819b762e8620d0f54c04225ac501c31c72dd182f70b3796e3da7e11d0a0f8a38f18920464c64f997c21638a6176aea8fc1d081
7
- data.tar.gz: 992d76ed72f096181b68682f01926dc88c3742754426efb5ffa8f08a785181e8e59ac46c6f1ab7bb886d1ba312fc0de96620ad0c1372cbe26ff6be39df50473a
6
+ metadata.gz: 322918f434dfde44a63ce4e5dbfc430cb0d8a1a78fe41ecaafc67c2c44269012f39f43edbcec799b26e9b5b1236b545eeb5a70602236ce3e0bd61ffe0e723f9e
7
+ data.tar.gz: bf2e4aaa891fa291376f7c0bd03106ab12fa5ec90b6bf773b9a8a957043a5de02b6f29716b5b008e6c5a8363f65d2a0d8f62499dbac976b5e0ad5c9b21a84983
data/README.md CHANGED
@@ -65,6 +65,13 @@ mtncloud remote add mtncloud https://console.cloud.mtn.ng
65
65
  mtncloud login
66
66
  ```
67
67
 
68
+ When prompted for your username:
69
+
70
+ - Master tenant users enter only their username, for example `neo`.
71
+ - Sub-tenant users prefix it with their tenant's subdomain or account ID: `subdomain\username` or `accountID\username`, for example `acme\neo` or `2\neo`.
72
+
73
+ Your password is not saved. The CLI saves an access token in `~/.mtncloud/credentials` and refreshes it when it expires. To log in from a script without a prompt, use `--password-file FILE` or `--token ACCESS_TOKEN`. See `mtncloud login --help`.
74
+
68
75
  Then run commands, for example:
69
76
 
70
77
  ```shell
@@ -152,7 +159,7 @@ The other tests run against a live appliance. Create a `test_config.yaml` in the
152
159
 
153
160
  ```yaml
154
161
  url: 'https://console.cloud.mtn.ng'
155
- username: (accountID/Subdomain)\testrunner
162
+ username: (accountID/subdomain)\testrunner
156
163
  password: 'SecretPassword123$'
157
164
  ```
158
165
 
@@ -25,7 +25,7 @@ class MtnCloud::Cli::Login
25
25
  username, password = nil, nil
26
26
  optparse = MtnCloud::Cli::OptionParser.new do |opts|
27
27
  opts.banner = usage
28
- opts.on( '-u', '--username USERNAME', "Username. Sub-tenant users must format their username with a prefix like {subdomain}\\{username}" ) do |val|
28
+ opts.on( '-u', '--username USERNAME', "Username. Sub-tenant users prefix it with their subdomain or account ID: {subdomain}\\{username} or {accountID}\\{username}" ) do |val|
29
29
  username = val
30
30
  end
31
31
  opts.on( '-p', '--password PASSWORD', "Password" ) do |val|
@@ -54,8 +54,13 @@ Login to a remote appliance with a username and password or using an access toke
54
54
  Logging in with username and password will make an authentication api request to obtain an access token.
55
55
  [username] is required, this is the username of the MTN Cloud user
56
56
  [password] is required, this is the password of the MTN Cloud user
57
- Sub-tenant users will need to pass their tenant subdomain prefix. ie. {subdomain}\\{username}
58
- By default, the subdomain is the tenant account ID. Example: 2\\neo
57
+ Username format:
58
+ Master tenant users enter only their username. Example: neo
59
+ Sub-tenant users prefix their username with their tenant's subdomain or account ID:
60
+ {subdomain}\\{username} Example: acme\\neo
61
+ {accountID}\\{username} Example: 2\\neo
62
+ A tenant's subdomain is its account ID unless a custom subdomain is set.
63
+ In bash or zsh, quote a username that contains a backslash: '2\\neo'
59
64
  The --token option can be used to login with a valid access token instead of username and password.
60
65
  The specified token will be verified by making a whoami api request
61
66
  If successful, the access token will be saved with the active session for the remote appliance.
@@ -11,6 +11,10 @@ module MtnCloud
11
11
  class Credentials
12
12
  include MtnCloud::Cli::PrintHelper
13
13
 
14
+ # How sub-tenant users format their username, shown in the login prompt.
15
+ # login --help explains the same formats in more detail.
16
+ USERNAME_FORMAT = "sub-tenant users: subdomain\\username or accountID\\username"
17
+
14
18
  @@appliance_credentials_map = nil
15
19
 
16
20
  def initialize(appliance_name, appliance_url)
@@ -118,7 +122,7 @@ module MtnCloud
118
122
  Readline.basic_word_break_characters = ''
119
123
  Readline.completer_word_break_characters = '' rescue nil
120
124
  Readline.completion_proc = nil
121
- username = Readline.readline("Username: #{required_blue_prompt} ", false).to_s.chomp
125
+ username = Readline.readline("Username (#{USERNAME_FORMAT}): #{required_blue_prompt} ", false).to_s.chomp
122
126
  else
123
127
  print "Username: #{required_blue_prompt} #{username}\n"
124
128
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
  module MtnCloud
3
3
  module Cli
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
5
5
  end
6
6
  end
@@ -0,0 +1,47 @@
1
+ require 'test/unit'
2
+ require 'stringio'
3
+ require 'mtncloud'
4
+
5
+ # Offline tests for how login explains the username format.
6
+ # Sub-tenant users log in as {subdomain}\{username} or {accountID}\{username}.
7
+ class LoginHelpTest < Test::Unit::TestCase
8
+
9
+ def capture_stdout
10
+ saved = $stdout
11
+ $stdout = StringIO.new
12
+ yield
13
+ $stdout.string
14
+ ensure
15
+ $stdout = saved
16
+ end
17
+
18
+ # Captured once: the CLI keeps the stdout it first printed to, so a second
19
+ # --help in the same process would print to the first test's StringIO.
20
+ def login_help
21
+ @@login_help ||= capture_stdout do
22
+ error = assert_raise(SystemExit) { MtnCloud::Cli::Login.new.handle(['--help']) }
23
+ assert_equal 0, error.status
24
+ end
25
+ end
26
+
27
+ def test_help_documents_both_sub_tenant_username_formats
28
+ output = login_help
29
+ assert_include output, '{subdomain}\\{username}'
30
+ assert_include output, '{accountID}\\{username}'
31
+ assert_include output, 'Example: acme\\neo'
32
+ assert_include output, 'Example: 2\\neo'
33
+ assert_include output, 'Master tenant users enter only their username.'
34
+ end
35
+
36
+ def test_username_option_mentions_subdomain_and_account_id
37
+ output = login_help
38
+ assert_include output, '--username USERNAME'
39
+ assert_include output, 'Sub-tenant users prefix it with their subdomain or account ID'
40
+ end
41
+
42
+ def test_prompt_hint_names_both_formats
43
+ hint = MtnCloud::Cli::Credentials::USERNAME_FORMAT
44
+ assert_include hint, 'subdomain\\username'
45
+ assert_include hint, 'accountID\\username'
46
+ end
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtncloud-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Henry
@@ -728,6 +728,7 @@ files:
728
728
  - test/cli/host_vm_groups_test.rb
729
729
  - test/cli/infrastructure_helper_cluster_resolver_test.rb
730
730
  - test/cli/instances_test.rb
731
+ - test/cli/login_help_test.rb
731
732
  - test/cli/man_test.rb
732
733
  - test/cli/migrations_test.rb
733
734
  - test/cli/network_routers_test.rb
@@ -795,6 +796,7 @@ test_files:
795
796
  - test/cli/host_vm_groups_test.rb
796
797
  - test/cli/infrastructure_helper_cluster_resolver_test.rb
797
798
  - test/cli/instances_test.rb
799
+ - test/cli/login_help_test.rb
798
800
  - test/cli/man_test.rb
799
801
  - test/cli/migrations_test.rb
800
802
  - test/cli/network_routers_test.rb