mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[Brightbox] Adds ApiClient Model
* Add api client model for Brightbox * Also map relevant requests to model methods * Add ApiClient declaration to compute.rb
This commit is contained in:
parent
2b8e54c826
commit
23c1e414d8
3 changed files with 63 additions and 0 deletions
|
@ -24,6 +24,8 @@ module Fog
|
|||
model :account
|
||||
collection :applications
|
||||
model :application
|
||||
collection :api_clients
|
||||
model :api_client
|
||||
collection :servers
|
||||
model :server
|
||||
collection :server_groups
|
||||
|
|
37
lib/fog/brightbox/models/compute/api_client.rb
Normal file
37
lib/fog/brightbox/models/compute/api_client.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Brightbox
|
||||
class ApiClient < Fog::Model
|
||||
identity :id
|
||||
attribute :name
|
||||
attribute :description
|
||||
attribute :secret
|
||||
attribute :revoked_at, :type => :time
|
||||
attribute :account_id
|
||||
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
|
||||
options = {
|
||||
:name => name,
|
||||
:description => description
|
||||
}.delete_if {|k,v| v.nil? || v == "" }
|
||||
data = connection.create_api_client(options)
|
||||
merge_attributes(data)
|
||||
true
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :identity
|
||||
connection.destroy_api_client(identity)
|
||||
true
|
||||
end
|
||||
|
||||
def reset_secret
|
||||
requires :identity
|
||||
connection.reset_secret_api_client(identity)
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
24
lib/fog/brightbox/models/compute/api_clients.rb
Normal file
24
lib/fog/brightbox/models/compute/api_clients.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require "fog/core/collection"
|
||||
require "fog/brightbox/models/compute/api_client"
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Brightbox
|
||||
class ApiClients < Fog::Collection
|
||||
model Fog::Compute::Brightbox::ApiClient
|
||||
|
||||
def all
|
||||
data = connection.list_api_clients
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(identifier = nil)
|
||||
data = connection.get_api_client(identifier)
|
||||
new(data)
|
||||
rescue Excon::Errors::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue