From 23c1e414d80ae75645ee87c6a6ebd8f6bd732af9 Mon Sep 17 00:00:00 2001 From: Hemant Kumar Date: Fri, 21 Sep 2012 18:12:40 +0530 Subject: [PATCH] [Brightbox] Adds ApiClient Model * Add api client model for Brightbox * Also map relevant requests to model methods * Add ApiClient declaration to compute.rb --- lib/fog/brightbox/compute.rb | 2 + .../brightbox/models/compute/api_client.rb | 37 +++++++++++++++++++ .../brightbox/models/compute/api_clients.rb | 24 ++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 lib/fog/brightbox/models/compute/api_client.rb create mode 100644 lib/fog/brightbox/models/compute/api_clients.rb diff --git a/lib/fog/brightbox/compute.rb b/lib/fog/brightbox/compute.rb index 63a59b742..20455a7af 100644 --- a/lib/fog/brightbox/compute.rb +++ b/lib/fog/brightbox/compute.rb @@ -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 diff --git a/lib/fog/brightbox/models/compute/api_client.rb b/lib/fog/brightbox/models/compute/api_client.rb new file mode 100644 index 000000000..cf2954099 --- /dev/null +++ b/lib/fog/brightbox/models/compute/api_client.rb @@ -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 diff --git a/lib/fog/brightbox/models/compute/api_clients.rb b/lib/fog/brightbox/models/compute/api_clients.rb new file mode 100644 index 000000000..33ded8a33 --- /dev/null +++ b/lib/fog/brightbox/models/compute/api_clients.rb @@ -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