Sha256: af9b198d4d3c49431784c7ff0176c2ecfb0b0bcec224f69cc9c0050fcc232feb

Contents?: true

Size: 1.74 KB

Versions: 4

Compression:

Stored size: 1.74 KB

Contents

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.  The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License.  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
# License for the specific language governing permissions and limitations
# under the License.

class Key < BaseModel

  attr_accessor :credential_type
  attr_accessor :fingerprint
  attr_accessor :username
  attr_accessor :password
  attr_accessor :pem_rsa_key
  attr_accessor :state

  def name
    @name || @id
  end

  def is_password?
    @credential_type.eql?(:password)
  end

  def is_key?
    @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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
deltacloud-core-1.0.5 lib/deltacloud/models/key.rb
deltacloud-core-1.0.4 lib/deltacloud/models/key.rb
deltacloud-core-1.0.3 lib/deltacloud/models/key.rb
deltacloud-core-1.0.2 lib/deltacloud/models/key.rb