1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[Brightbox] Updates to add collaborations

Adds requests and models for collaborations
This commit is contained in:
Hemant Kumar 2012-10-19 21:08:44 +05:30 committed by Paul Thornthwaite
parent f525276936
commit 316618a8c8
19 changed files with 532 additions and 2 deletions

View file

@ -34,6 +34,8 @@ module Fog
model :application
collection :api_clients
model :api_client
collection :collaborations
model :collaboration
collection :servers
model :server
collection :server_groups
@ -54,17 +56,22 @@ module Fog
model :cloud_ip
collection :users
model :user
collection :user_collaborations
model :user_collaboration
request_path 'fog/brightbox/requests/compute'
request :accept_user_collaboration
request :activate_console_server
request :add_listeners_load_balancer
request :add_nodes_load_balancer
request :add_servers_server_group
request :apply_to_firewall_policy
request :accept_user_collaboration
request :remove_firewall_policy
request :create_api_client
request :create_application
request :create_cloud_ip
request :create_collaboration
request :create_firewall_policy
request :create_firewall_rule
request :create_image
@ -74,17 +81,20 @@ module Fog
request :delete_api_client
request :delete_application
request :delete_cloud_ip
request :delete_collaboration
request :delete_firewall_policy
request :delete_firewall_rule
request :delete_image
request :delete_load_balancer
request :delete_server
request :delete_server_group
request :delete_user_collaboration
request :get_account
request :get_api_client
request :get_application
request :get_authenticated_user
request :get_cloud_ip
request :get_collaboration
request :get_firewall_policy
request :get_firewall_rule
request :get_image
@ -95,11 +105,13 @@ module Fog
request :get_server_group
request :get_server_type
request :get_user
request :get_user_collaboration
request :get_zone
request :list_accounts
request :list_api_clients
request :list_applications
request :list_cloud_ips
request :list_collaborations
request :list_firewall_policies
request :list_images
request :list_load_balancers
@ -107,16 +119,21 @@ module Fog
request :list_server_types
request :list_servers
request :list_users
request :list_user_collaborations
request :list_zones
request :map_cloud_ip
request :move_servers_server_group
request :reject_user_collaboration
request :remove_listeners_load_balancer
request :remove_nodes_load_balancer
request :remove_servers_server_group
request :resend_collaboration
request :reset_ftp_password_account
request :reset_ftp_password_scoped_account
request :reset_secret_api_client
request :reset_secret_application
request :resend_collaboration
request :reject_user_collaboration
request :shutdown_server
request :snapshot_server
request :start_server

View file

@ -0,0 +1,43 @@
require 'fog/core/model'
module Fog
module Compute
class Brightbox
class Collaboration < Fog::Model
identity :id
attribute :status
attribute :email
attribute :role
attribute :role_label
attribute :account
attribute :user
attribute :inviter
def account_id
account['id'] || account[:id]
end
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
options = {
:role => role,
:email => email
}.delete_if { |k, v| v.nil? || v == "" }
data = connection.create_collaboration(options)
merge_attributes(data)
true
end
def destroy
requires :identity
connection.destroy_collaboration(identity)
true
end
end
end
end
end

View file

@ -0,0 +1,23 @@
require "fog/core/collection"
require "fog/brightbox/models/compute/collaboration"
module Fog
module Compute
class Brightbox
class Collaborations < Fog::Collection
model Fog::Compute::Brightbox::Collaboration
def all
data = connection.list_collaborations
load(data)
end
def destroy
requires :identity
connection.destroy_collaboration(identity)
true
end
end
end
end
end

View file

@ -0,0 +1,29 @@
require 'fog/core/model'
module Fog
module Compute
class Brightbox
class UserCollaboration < Fog::Model
identity :id
attribute :status
attribute :email
attribute :role
attribute :role_label
attribute :account
attribute :user
attribute :inviter
def account_id
account['id'] || account[:id]
end
def destroy
requires :identity
connection.destroy_user_collaboration(identity)
true
end
end
end
end
end

View file

@ -0,0 +1,23 @@
require "fog/core/collection"
require "fog/brightbox/models/compute/user_collaboration"
module Fog
module Compute
class Brightbox
class UserCollaborations < Fog::Collection
model Fog::Compute::Brightbox::UserCollaboration
def all
data = connection.list_user_collaborations
load(data)
end
def destroy
requires :identity
connection.destroy_user_collaboration(identity)
true
end
end
end
end
end

View file

@ -0,0 +1,21 @@
module Fog
module Compute
class Brightbox
class Real
# Accepts the collaboration and gaining permitted access
#
# @param [String] identifier Unique reference to identify the resource
#
# @return [Hash] if successful Hash version of JSON object
#
# @see https://api.gb1.brightbox.com/1.0/#user_collaboration_accept_user_collaboration
#
def accept_user_collaboration(identifier)
return nil if identifier.nil? || identifier == ""
wrapped_request("post", "/1.0/user/collaborations/#{identifier}/accept", [200])
end
end
end
end
end

View file

@ -0,0 +1,23 @@
module Fog
module Compute
class Brightbox
class Real
# Creates a new collaboration for a user for the account
#
# @param [Hash] options
# @option options [String] :email Email address of user to invite
# @option options [String] :role Role to grant to the user. Currently only `admin`
#
# @return [Hash] if successful Hash version of JSON object
# @return [NilClass] if no options were passed
#
# @see https://api.gb1.brightbox.com/1.0/#collaboration_create_collaboration
#
def create_collaboration(options)
wrapped_request("post", "/1.0/collaborations", [201], options)
end
end
end
end
end

View file

@ -0,0 +1,28 @@
module Fog
module Compute
class Brightbox
class Real
# Cancels or completes the collaboration
#
# @param [String] identifier Unique reference to identify the resource
#
# @return [Hash] if successful Hash version of JSON object
#
# @see https://api.gb1.brightbox.com/1.0/#collaboration_delete_collaboration
#
def delete_collaboration(identifier)
return nil if identifier.nil? || identifier == ""
wrapped_request("delete", "/1.0/collaborations/#{identifier}", [200])
end
# Old format of the delete request.
#
# @deprecated Use +#delete_collaboration+ instead
#
def destroy_collaboration(identifier)
delete_collaboration(identifier)
end
end
end
end
end

View file

@ -0,0 +1,28 @@
module Fog
module Compute
class Brightbox
class Real
# Ends an existing 'accepted' collaboration
#
# @param [String] identifier Unique reference to identify the resource
#
# @return [Hash] if successful Hash version of JSON object
#
# @see https://api.gb1.brightbox.com/1.0/#user_collaboration_delete_user_collaboration
#
def delete_user_collaboration(identifier)
return nil if identifier.nil? || identifier == ""
wrapped_request("delete", "/1.0/user/collaborations/#{identifier}", [200])
end
# Old format of the delete request.
#
# @deprecated Use +#delete_user_collaboration+ instead
#
def destroy_user_collaboration(identifier)
delete_user_collaboration(identifier)
end
end
end
end
end

View file

@ -0,0 +1,21 @@
module Fog
module Compute
class Brightbox
class Real
# Ends an existing 'accepted' collaboration
#
# @param [String] identifier Unique reference to identify the resource
#
# @return [Hash] The JSON response parsed to a Hash
#
# @see https://api.gb1.brightbox.com/1.0/#user_collaboration_destroy_user_collaboration
#
def destroy_user_collaboration(identifier)
return nil if identifier.nil? || identifier == ""
wrapped_request("delete", "/1.0/user/collaborations/#{identifier}", [200])
end
end
end
end
end

View file

@ -0,0 +1,21 @@
module Fog
module Compute
class Brightbox
class Real
# Shows details of one collaboration
#
# @param [String] identifier Unique reference to identify the resource
#
# @return [Hash] if successful Hash version of JSON object
#
# @see https://api.gb1.brightbox.com/1.0/#collaboration_get_collaboration
#
def get_collaboration(identifier)
return nil if identifier.nil? || identifier == ""
wrapped_request("get", "/1.0/collaborations/#{identifier}", [200])
end
end
end
end
end

View file

@ -0,0 +1,21 @@
module Fog
module Compute
class Brightbox
class Real
# Shows details of one collaboration
#
# @param [String] identifier Unique reference to identify the resource
#
# @return [Hash] if successful Hash version of JSON object
#
# @see https://api.gb1.brightbox.com/1.0/#user_collaboration_get_user_collaboration
#
def get_user_collaboration(identifier)
return nil if identifier.nil? || identifier == ""
wrapped_request("get", "/1.0/user/collaborations/#{identifier}", [200])
end
end
end
end
end

View file

@ -0,0 +1,19 @@
module Fog
module Compute
class Brightbox
class Real
# Lists all the account collaborations
#
#
# @return [Hash] if successful Hash version of JSON object
#
# @see https://api.gb1.brightbox.com/1.0/#collaboration_list_collaborations
#
def list_collaborations
wrapped_request("get", "/1.0/collaborations", [200])
end
end
end
end
end

View file

@ -0,0 +1,19 @@
module Fog
module Compute
class Brightbox
class Real
# Lists all collaborations the user is involved with
#
#
# @return [Hash] if successful Hash version of JSON object
#
# @see https://api.gb1.brightbox.com/1.0/#user_collaboration_list_user_collaborations
#
def list_user_collaborations
wrapped_request("get", "/1.0/user/collaborations", [200])
end
end
end
end
end

View file

@ -0,0 +1,21 @@
module Fog
module Compute
class Brightbox
class Real
# Rejects the collaboration and removes the offer
#
# @param [String] identifier Unique reference to identify the resource
#
# @return [Hash] if successful Hash version of JSON object
#
# @see https://api.gb1.brightbox.com/1.0/#user_collaboration_reject_user_collaboration
#
def reject_user_collaboration(identifier)
return nil if identifier.nil? || identifier == ""
wrapped_request("post", "/1.0/user/collaborations/#{identifier}/reject", [200])
end
end
end
end
end

View file

@ -0,0 +1,21 @@
module Fog
module Compute
class Brightbox
class Real
# Resends the invitation email to the collaborator
#
# @param [String] identifier Unique reference to identify the resource
#
# @return [Hash] if successful Hash version of JSON object
#
# @see https://api.gb1.brightbox.com/1.0/#collaboration_resend_collaboration
#
def resend_collaboration(identifier)
return nil if identifier.nil? || identifier == ""
wrapped_request("post", "/1.0/collaborations/#{identifier}/resend", [200])
end
end
end
end
end

View file

@ -0,0 +1,41 @@
Shindo.tests('Fog::Compute[:brightbox] | collaboration requests', ['brightbox']) do
tests('success') do
tests("#create_collaboration") do
pending if Fog.mocking?
collaboration = Fog::Compute[:brightbox].create_collaboration(:email => "paul@example.com", :role => "admin")
@collaboration_id = collaboration['id']
formats(Brightbox::Compute::Formats::Full::COLLABORATION, false) { collaboration }
end
tests("#list_collaborations") do
pending if Fog.mocking?
result = Fog::Compute[:brightbox].list_collaborations
formats(Brightbox::Compute::Formats::Collection::COLLABORATIONS, false) { result }
end
tests("#get_collaboration") do
pending if Fog.mocking?
result = Fog::Compute[:brightbox].get_collaboration(@collaboration_id)
formats(Brightbox::Compute::Formats::Full::COLLABORATION, false) { result }
end
tests("#destroy_collaboration") do
pending if Fog.mocking?
result = Fog::Compute[:brightbox].destroy_collaboration(@collaboration_id)
formats(Brightbox::Compute::Formats::Full::COLLABORATION, false) { result }
end
end
tests("failure") do
tests("get_collaboration('col-abcde')").raises(Excon::Errors::NotFound) do
pending if Fog.mocking?
Fog::Compute[:brightbox].get_collaboration("col-abcde")
end
end
end

View file

@ -8,6 +8,7 @@ module Fog
module LoadBalancer; end
module Server; end
module ServerGroup; end
module User; end
module Zone; end
end
end
@ -34,6 +35,9 @@ NilClass.send :include, Fog::Brightbox::Nullable::Server
Hash.send :include, Fog::Brightbox::Nullable::ServerGroup
NilClass.send :include, Fog::Brightbox::Nullable::ServerGroup
Hash.send :include, Fog::Brightbox::Nullable::User
NilClass.send :include, Fog::Brightbox::Nullable::User
Hash.send :include, Fog::Brightbox::Nullable::Zone
NilClass.send :include, Fog::Brightbox::Nullable::Zone
@ -75,8 +79,8 @@ class Brightbox
raise "No available images!" if images.empty?
images.select { |img| img["official"] && img["virtual_size"] != 0 }.sort_by { |img| img["disk_size"] }.first || images.first
end
end
module Formats
module Struct
CIP_PORT_TRANSLATOR = {
@ -231,6 +235,20 @@ class Brightbox
"email_address" => String
}
COLLABORATION = {
"id" => String,
"resource_type" => String,
"url" => String,
"status" => String,
"email" => Fog::Nullable::String,
"role" => String,
"role_label" => String,
"user" => Fog::Brightbox::Nullable::User,
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT,
"inviter" => Brightbox::Compute::Formats::Nested::USER
}
ZONE = {
"id" => String,
"resource_type" => String,
@ -413,6 +431,19 @@ class Brightbox
"default_account" => NilClass
}
COLLABORATION = {
"id" => String,
"resource_type" => String,
"url" => String,
"status" => String,
"role" => String,
"role_label" => String,
"email" => Fog::Nullable::String,
"user" => Fog::Brightbox::Nullable::User,
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT,
"inviter" => Brightbox::Compute::Formats::Nested::USER
}
ZONE = {
"id" => String,
"resource_type" => String,
@ -656,13 +687,25 @@ class Brightbox
"messaging_pref" => Fog::Boolean
}
COLLABORATION = {
"id" => String,
"resource_type" => String,
"url" => String,
"status" => String,
"role" => String,
"role_label" => String,
"email" => Fog::Nullable::String,
"user" => Fog::Brightbox::Nullable::User,
"account" => Brightbox::Compute::Formats::Nested::ACCOUNT,
"inviter" => Brightbox::Compute::Formats::Nested::USER
}
ZONE = {
"id" => String,
"resource_type" => String,
"url" => String,
"handle" => String
}
end
module Collection
@ -678,6 +721,7 @@ class Brightbox
SERVER_TYPES = [Brightbox::Compute::Formats::Collected::SERVER_TYPE]
USERS = [Brightbox::Compute::Formats::Collected::USER]
ZONES = [Brightbox::Compute::Formats::Collected::ZONE]
COLLABORATIONS = [Brightbox::Compute::Formats::Collected::COLLABORATION]
end
end

View file

@ -0,0 +1,67 @@
Shindo.tests('Fog::Compute[:brightbox] | user collaboration requests', ['brightbox']) do
@service = Fog::Compute[:brightbox]
tests("when accessing with user application") do
pending unless @service.authenticating_as_user?
tests("success") do
tests("#list_user_collaborations") do
pending if Fog.mocking?
result = @service.list_user_collaborations
formats(Brightbox::Compute::Formats::Collection::COLLABORATIONS, false) { result }
end
end
tests("failure") do
tests("get_user_collaboration('col-abcde')").raises(Excon::Errors::NotFound) do
pending if Fog.mocking?
@service.get_user_collaboration('col-abcde')
end
tests("accept_user_collaboration('col-abcde')").raises(Excon::Errors::NotFound) do
pending if Fog.mocking?
@service.accept_user_collaboration('col-abcde')
end
tests("reject_user_collaboration('col-abcde')").raises(Excon::Errors::NotFound) do
pending if Fog.mocking?
@service.reject_user_collaboration('col-abcde')
end
end
end
tests("when accessing with API client") do
pending if @service.authenticating_as_user?
tests("forbidden") do
tests("#list_user_collaborations").raises(Excon::Errors::Forbidden) do
pending if Fog.mocking?
result = @service.list_user_collaborations
formats(Brightbox::Compute::Formats::Collection::COLLABORATIONS, false) { result }
end
tests("get_user_collaboration('col-abcde')").raises(Excon::Errors::Forbidden) do
pending if Fog.mocking?
@service.get_user_collaboration('col-abcde')
end
tests("accept_user_collaboration('col-abcde')").raises(Excon::Errors::Forbidden) do
pending if Fog.mocking?
@service.accept_user_collaboration('col-abcde')
end
tests("reject_user_collaboration('col-abcde')").raises(Excon::Errors::Forbidden) do
pending if Fog.mocking?
@service.reject_user_collaboration('col-abcde')
end
end
end
end