Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1295 from brightbox/account_updates

[Brightbox] Account updates
  • Loading branch information...
commit 3ef5a61edaa97eb6356e60ff92a91d6877dfb025 2 parents 87f6251 + 4b79b6b
@tokengeek tokengeek authored
View
36 lib/fog/brightbox/compute.rb
@@ -106,6 +106,7 @@ class Brightbox < Fog::Service
request :remove_nodes_load_balancer
request :remove_servers_server_group
request :reset_ftp_password_account
+ request :reset_ftp_password_scoped_account
request :reset_secret_api_client
request :reset_secret_application
request :shutdown_server
@@ -164,16 +165,19 @@ class Real
def initialize(options)
# Currently authentication and api endpoints are the same but may change
- @auth_url = options[:brightbox_auth_url] || Fog.credentials[:brightbox_auth_url] || API_URL
- @api_url = options[:brightbox_api_url] || Fog.credentials[:brightbox_api_url] || API_URL
- @connection_options = options[:connection_options] || {}
- @brightbox_client_id = options[:brightbox_client_id] || Fog.credentials[:brightbox_client_id]
- @brightbox_secret = options[:brightbox_secret] || Fog.credentials[:brightbox_secret]
- @brightbox_username = options[:brightbox_username] || Fog.credentials[:brightbox_username]
- @brightbox_password = options[:brightbox_password] || Fog.credentials[:brightbox_password]
- @brightbox_account = options[:brightbox_account] || Fog.credentials[:brightbox_account]
- @persistent = options[:persistent] || false
- @connection = Fog::Connection.new(@api_url, @persistent, @connection_options)
+ @auth_url = options[:brightbox_auth_url] || Fog.credentials[:brightbox_auth_url] || API_URL
+ @api_url = options[:brightbox_api_url] || Fog.credentials[:brightbox_api_url] || API_URL
+ @connection_options = options[:connection_options] || {}
+ @persistent = options[:persistent] || false
+ @connection = Fog::Connection.new(@api_url, @persistent, @connection_options)
+
+ # Authentication options
+ @brightbox_client_id = options[:brightbox_client_id] || Fog.credentials[:brightbox_client_id]
+ @brightbox_secret = options[:brightbox_secret] || Fog.credentials[:brightbox_secret]
+
+ @brightbox_username = options[:brightbox_username] || Fog.credentials[:brightbox_username]
+ @brightbox_password = options[:brightbox_password] || Fog.credentials[:brightbox_password]
+ @brightbox_account = options[:brightbox_account] || Fog.credentials[:brightbox_account]
end
# Makes an API request to the given path using passed options or those
@@ -211,15 +215,23 @@ def request(method, path, expected_responses, parameters = {})
# @return [Fog::Compute::Brightbox::Account]
#
def account
- Fog::Compute::Brightbox::Account.new(get_scoped_account)
+ Fog::Compute::Brightbox::Account.new(get_scoped_account).tap do |acc|
+ # Connection is more like the compute 'service'
+ acc.connection = self
+ end
end
+ # Returns true if authentication is being performed as a user
+ # @return [Boolean]
+ def authenticating_as_user?
+ @brightbox_username && @brightbox_password
+ end
private
def get_oauth_token(options = {})
auth_url = options[:brightbox_auth_url] || @auth_url
connection = Fog::Connection.new(auth_url)
- authentication_body_hash = if @brightbox_username && @brightbox_password
+ authentication_body_hash = if authenticating_as_user?
{
'client_id' => @brightbox_client_id,
'grant_type' => 'password',
View
12 lib/fog/brightbox/models/compute/account.rb
@@ -32,7 +32,7 @@ class Account < Fog::Model
attribute :load_balancers_used
attribute :library_ftp_host
attribute :library_ftp_user
- # This is always returned as null/nil unless performing a reset_ftp_password request
+ # This is always returned as nil unless after a call to reset_ftp_password
attribute :library_ftp_password
# Boolean flags
@@ -51,13 +51,19 @@ class Account < Fog::Model
attribute :users
attribute :zones
+ # Resets the account's image library FTP password returning the new value
+ #
+ # @return [String] Newly issue FTP password
+ #
def reset_ftp_password
requires :identity
- connection.reset_ftp_password_account["library_ftp_password"]
+ data = connection.reset_ftp_password_account(identity)
+ merge_attributes(data)
+ library_ftp_password
end
end
end
end
-end
+end
View
17 lib/fog/brightbox/requests/compute/reset_ftp_password_account.rb
@@ -5,16 +5,25 @@ class Real
# Reset the image library ftp password for the account.
#
- # The response is the only time the new password is available in plaintext.
+ # @note The response is the only time the new password is available in plaintext.
#
- # @param [String] identifier Unique reference to identify the resource
+ # @overload reset_ftp_password_account(identifier)
+ # @param [String] identifier Unique reference to identify the resource
+ #
+ # @overload reset_ftp_password_account()
+ # @deprecated Use {Fog::Compute::Brightbox::Real#get_scoped_account} instead
#
# @return [Hash] The JSON response parsed to a Hash
#
# @see https://api.gb1.brightbox.com/1.0/#account_reset_ftp_password_account
#
- def reset_ftp_password_account
- request("post", "/1.0/account/reset_ftp_password", [200])
+ def reset_ftp_password_account(identifier = nil)
+ if identifier.nil? || identifier.empty?
+ Fog::Logger.deprecation("reset_ftp_password_account() without a parameter is deprecated, use reset_ftp_password_scoped_account instead [light_black](#{caller.first})[/]")
+ reset_ftp_password_scoped_account
+ else
+ request("post", "/1.0/accounts/#{identifier}/reset_ftp_password", [200])
+ end
end
end
View
18 lib/fog/brightbox/requests/compute/reset_ftp_password_scoped_account.rb
@@ -0,0 +1,18 @@
+module Fog
+ module Compute
+ class Brightbox
+ class Real
+ # Resets the image library ftp password for the scoped account
+ #
+ # @note The response is the only time the new password is available in plaintext.
+ #
+ # @return [Hash] The JSON response parsed to a Hash
+ #
+ def reset_ftp_password_scoped_account
+ request("post", "/1.0/account/reset_ftp_password", [200])
+ end
+ end
+
+ end
+ end
+end
View
15 tests/brightbox/models/compute/account_tests.rb
@@ -0,0 +1,15 @@
+Shindo.tests("Fog::Compute[:brightbox] | Account model", ["brightbox"]) do
+
+ @account = Fog::Compute[:brightbox].account
+
+ tests("success") do
+
+ tests("#reset_ftp_password") do
+ pending if Fog.mocking?
+ test("original ftp password is blanked") { @account.library_ftp_password.nil? }
+ @new_password = @account.reset_ftp_password
+ test("new ftp password was not nil") { !@new_password.nil? }
+ test("new ftp password is set") { @account.library_ftp_password == @new_password }
+ end
+ end
+end
View
11 tests/brightbox/requests/compute/account_tests.rb
@@ -36,9 +36,16 @@
formats(Brightbox::Compute::Formats::Full::ACCOUNT, false) { result }
end
- tests("#reset_ftp_password_account") do
+ tests("#reset_ftp_password_scoped_account") do
pending if Fog.mocking?
- result = Fog::Compute[:brightbox].reset_ftp_password_account
+ result = Fog::Compute[:brightbox].reset_ftp_password_scoped_account
+ formats(Brightbox::Compute::Formats::Full::ACCOUNT, false) { result }
+ test("new ftp password is visible") { ! result["library_ftp_password"].nil? }
+ end
+
+ tests("#reset_ftp_password_account(#{@scoped_account_identifier})") do
+ pending if Fog.mocking?
+ result = Fog::Compute[:brightbox].reset_ftp_password_account(@scoped_account_identifier)
formats(Brightbox::Compute::Formats::Full::ACCOUNT, false) { result }
test("new ftp password is visible") { ! result["library_ftp_password"].nil? }
end
Please sign in to comment.
Something went wrong with that request. Please try again.