incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1039017 - in /incubator/deltacloud/trunk: server/lib/deltacloud/drivers/mock/mock_driver.rb server/lib/deltacloud/models/key.rb tests/mock/api.feature
Date Thu, 25 Nov 2010 12:22:37 GMT
Author: mfojtik
Date: Thu Nov 25 12:22:36 2010
New Revision: 1039017

URL: http://svn.apache.org/viewvc?rev=1039017&view=rev
Log:
Added Key collection into Mock driver

Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/models/key.rb
    incubator/deltacloud/trunk/tests/mock/api.feature

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb?rev=1039017&r1=1039016&r2=1039017&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb Thu Nov 25
12:22:36 2010
@@ -26,7 +26,7 @@ module Deltacloud
 class MockDriver < Deltacloud::BaseDriver
 
   def supported_collections
-    DEFAULT_COLLECTIONS + [ :buckets ]
+    DEFAULT_COLLECTIONS + [ :buckets, :keys]
   end
 
   ( REALMS = [
@@ -81,6 +81,7 @@ class MockDriver < Deltacloud::BaseDrive
   end
 
   feature :instances, :user_name
+  feature :instances, :authentication_key
 
   def initialize
     if ENV["DELTACLOUD_MOCK_STORAGE"]
@@ -264,6 +265,49 @@ class MockDriver < Deltacloud::BaseDrive
     snapshots
   end
 
+  def keys(credentials, opts={})
+    check_credentials(credentials)
+    result = []
+    key_dir = File.join(@storage_root, 'keys')
+    Dir[key_dir + '/*.yml'].each do |key_file|
+      result << Key.new(YAML::load(File.read(key_file)))
+    end
+    result = filter_on( result, :id, opts )
+    result
+  end
+
+  def key(credentials, opts={})
+    keys(credentials, opts).first
+  end
+
+  def create_key(credentials, opts={})
+    check_credentials(credentials)
+    key_hash = {
+      :id => opts[:key_name],
+      :credential_type => :key,
+      :fingerprint => Key::generate_mock_fingerprint,
+      :pem_rsa_key => Key::generate_mock_pem
+    }
+    key_dir = File.join(@storage_root, 'keys')
+    if File.exists?(key_dir + "/#{key_hash[:id]}.yml")
+     raise Deltacloud::BackendError.new(403, self.class.to_s, "key-exists",
+                                          ["Key with same name already exists"])
+    end
+    FileUtils.mkdir_p(key_dir) unless File.directory?(key_dir)
+    File.open(key_dir + "/#{key_hash[:id]}.yml", 'w') do |f|
+      f.puts(YAML::dump(key_hash))
+    end
+    return Key.new(key_hash)
+  end
+
+  def destroy_key(credentials, opts={})
+    key = key(credentials, opts)
+    safely do
+      key_dir = File.join(@storage_root, 'keys')
+      File.delete(key_dir + "/#{key.id}.yml")
+    end
+  end
+
 #--
 # Buckets
 #--

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/models/key.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/models/key.rb?rev=1039017&r1=1039016&r2=1039017&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/models/key.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/models/key.rb Thu Nov 25 12:22:36 2010
@@ -32,4 +32,20 @@ class Key < BaseModel
     true if @credential_type.eql?(:key)
   end
 
+  # Mock fingerprint generator
+  # 1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f
+  def self.generate_mock_fingerprint
+    (0..19).map { "%02x" % (rand * 0xff) }.join(':')
+  end
+
+  # Mock PEM file
+  # NOTE: This is a fake PEM file, it will not work against SSH
+  def self.generate_mock_pem
+    chars = (('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a + %w(= / + ))
+    pem_material = (1..21).map do 
+      (1..75).collect{|a| chars[rand(chars.size)] }.join
+    end.join("\n") + "\n" + (1..68).collect{|a| chars[rand(chars.size)] }.join
+    "-----BEGIN RSA PRIVATE KEY-----\n"+pem_material+"-----END RSA PRIVATE KEY-----"
+  end
+
 end

Modified: incubator/deltacloud/trunk/tests/mock/api.feature
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/tests/mock/api.feature?rev=1039017&r1=1039016&r2=1039017&view=diff
==============================================================================
--- incubator/deltacloud/trunk/tests/mock/api.feature (original)
+++ incubator/deltacloud/trunk/tests/mock/api.feature Thu Nov 25 12:22:36 2010
@@ -14,6 +14,7 @@ Feature: Accessing API entry points
     When client access this URI
     Then client should get list of valid entry points:
     | buckets    |
+    | keys       |
     | realms     |
     | instances  |
     | images     |
@@ -29,6 +30,7 @@ Feature: Accessing API entry points
     When client access this URI
     Then client should get list of valid entry points:
     | buckets    |
+    | keys       |
     | realms     |
     | instances  |
     | images     |



Mime
View raw message