Skip to content

Commit

Permalink
Updated the tenant attribute to domain (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashiqueps authored Dec 17, 2022
1 parent 8b8d31d commit 8ccf794
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 23 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ require 'vra'
=> true
```

Then, set up your client object. You will need to know your tenant ID from your vRA administrator.
Then, set up your client object. You will need to know your domain from your vRA administrator.

```shell
client = Vra::Client.new(username: '[email protected]', password: 'mypassword', tenant: 'mytenant', base_url: 'https://vra.corp.local', verify_ssl: true)
client = Vra::Client.new(username: '[email protected]', password: 'mypassword', domain: 'domain.corp.local', base_url: 'https://vra.corp.local', verify_ssl: true)
=> #<Vra::Client:0x000000034c0df8 ... >
```

Expand Down Expand Up @@ -234,7 +234,7 @@ deployment.requests
vRA paginates API requests where lists of items are returned. By default, this gem will ask vRA to provide items in groups of 20. However, as reported in [Issue 10](https://github.com/chef-partners/vmware-vra-gem/issues/10), it appears vRA may have a pagination bug. You can change the default page size from 20 to a value of your choice by passing in a `page_size` option when setting up the client:
```ruby
vra = Vra::Client.new(username: '[email protected]', password: 'mypassword', tenant: 'mytenant', base_url: 'https://vra.corp.local', verify_ssl: true, page_size: 100)
vra = Vra::Client.new(username: '[email protected]', password: 'mypassword', domain: 'domain.corp.local', base_url: 'https://vra.corp.local', verify_ssl: true, page_size: 100)
```
... or setting `page_size` on the client object after you've created it:
Expand Down
17 changes: 14 additions & 3 deletions lib/vra/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def initialize(opts)
@base_url = opts[:base_url]
@username = opts[:username]
@password = PasswordMasker.new(opts[:password])
@tenant = opts[:tenant]
@domain = fetch_domain(opts)

@verify_ssl = opts.fetch(:verify_ssl, true)
@refresh_token = PasswordMasker.new(nil)
@access_token = PasswordMasker.new(nil)
Expand Down Expand Up @@ -80,7 +81,7 @@ def token_params
{
'username': @username,
'password': @password.value,
'domain': @tenant,
'domain': @domain,
}
end

Expand Down Expand Up @@ -231,7 +232,7 @@ def raise_http_exception(caught_exception, path)

def validate_client_options!
raise ArgumentError, "Username and password are required" if @username.nil? || @password.value.nil?
raise ArgumentError, "A tenant is required" if @tenant.nil?
raise ArgumentError, "A domain is required" if @domain.nil?
raise ArgumentError, "A base URL is required" if @base_url.nil?
raise ArgumentError, "Base URL #{@base_url} is not a valid URI." unless valid_uri?(@base_url)
end
Expand All @@ -242,5 +243,15 @@ def valid_uri?(uri)
rescue URI::InvalidURIError
false
end

private

# This is for backward compatibility, if someone still uses tenant key to pass the domain,
# it should also work.
def fetch_domain(opts)
return opts[:tenant] if opts.key?(:tenant) && !opts.key?(:domain)

opts[:domain]
end
end
end
4 changes: 4 additions & 0 deletions lib/vra/deployment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def failed?
status == "CREATE_FAILED"
end

def completion_details
requests.last.details
end

def completed?
successful? || failed?
end
Expand Down
4 changes: 4 additions & 0 deletions lib/vra/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def failed?
status == "FAILED"
end

def details
request_data["details"]
end

private

attr_reader :request_data, :client
Expand Down
2 changes: 1 addition & 1 deletion spec/catalog_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Vra::Client.new(
username: "[email protected]",
password: "password",
tenant: "tenant",
domain: "domain",
base_url: "https://vra.corp.local"
)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/catalog_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Vra::Client.new(
username: "[email protected]",
password: "password",
tenant: "tenant",
domain: "domain",
base_url: "https://vra.corp.local"
)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/catalog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Vra::Client.new(
username: "[email protected]",
password: "password",
tenant: "tenant",
domain: "domain",
base_url: "https://vra.corp.local"
)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/catalog_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Vra::Client.new(
username: "[email protected]",
password: "password",
tenant: "tenant",
domain: "domain",
base_url: "https://vra.corp.local"
)
end
Expand Down
16 changes: 8 additions & 8 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{
username: "[email protected]",
password: "password",
tenant: "tenant",
domain: "domain",
base_url: "https://vra.corp.local",
}
end
Expand Down Expand Up @@ -136,7 +136,7 @@
{
username: "[email protected]",
password: "password",
domain: "tenant",
domain: "domain",
}.to_json
end

Expand Down Expand Up @@ -414,7 +414,7 @@
let(:unverified_client) do
Vra::Client.new(username: "[email protected]",
password: "password",
tenant: "tenant",
domain: "domain",
base_url: "https://vra.corp.local",
verify_ssl: false)
end
Expand Down Expand Up @@ -503,7 +503,7 @@
let(:client) do
described_class.new(
password: "password",
tenant: "tenant",
domain: "domain",
base_url: "https://vra.corp.local"
)
end
Expand All @@ -517,7 +517,7 @@
let(:client) do
described_class.new(
username: "username",
tenant: "tenant",
domain: "domain",
base_url: "https://vra.corp.local"
)
end
Expand All @@ -527,7 +527,7 @@
end
end

context "when tenant is missing" do
context "when domain is missing" do
let(:client) do
described_class.new(
username: "username",
Expand All @@ -546,7 +546,7 @@
described_class.new(
username: "username",
password: "password",
tenant: "tenant"
domain: "domain"
)
end

Expand All @@ -560,7 +560,7 @@
described_class.new(
username: "username",
password: "password",
tenant: "tenant",
domain: "domain",
base_url: "something-that-is-not-a-HTTP-URI"
)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/deployment_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Vra::Client.new(
username: "[email protected]",
password: "password",
tenant: "tenant",
domain: "domain",
base_url: "https://vra.corp.local"
)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/deployment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Vra::Client.new(
username: "[email protected]",
password: "password",
tenant: "tenant",
domain: "domain",
base_url: "https://vra.corp.local"
)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/deployments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Vra::Client.new(
username: "[email protected]",
password: "password",
tenant: "tenant",
domain: "domain",
base_url: "https://vra.corp.local"
)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
Vra::Client.new(
username: "[email protected]",
password: "password",
tenant: "tenant",
domain: "domain",
base_url: "https://vra.corp.local"
)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
Vra::Client.new(
username: "[email protected]",
password: "password",
tenant: "tenant",
domain: "domain",
base_url: "https://vra.corp.local"
)
end
Expand Down

0 comments on commit 8ccf794

Please sign in to comment.