fluke/devops-service/db/mongo/models/provider_accounts/provider_account.rb
2015-11-02 17:33:25 +03:00

67 lines
2.1 KiB
Ruby

require "db/mongo/models/mongo_model"
require "db/mongo/models/model_with_provider"
module Devops
module Model
class ProviderAccount < MongoModel
include ModelWithProvider
attr_accessor :account_name, :description, :ssh_key
set_field_validators :account_name, ::Validators::FieldValidator::NotNil,
::Validators::FieldValidator::FieldType::String,
::Validators::FieldValidator::NotEmpty,
::Validators::FieldValidator::Name
set_field_validators :description, ::Validators::FieldValidator::Nil,
::Validators::FieldValidator::FieldType::String,
::Validators::FieldValidator::NotEmpty,
::Validators::FieldValidator::Description
set_field_validators :ssh_key, ::Validators::FieldValidator::NotNil,
::Validators::FieldValidator::FieldType::String,
::Validators::FieldValidator::NotEmpty,
::Validators::FieldValidator::SshKey
ACCOUNT_FIELDS = {
account_name: "Account name (id)",
description: "Account description",
ssh_key: "Ssh key id"
}
def initialize a={}
self.account_name = a["account_name"]
self.description = a["description"]
self.ssh_key = a["ssh_key"]
self.provider = a["provider"]
self.created_at = a["created_at"]
end
def to_list_hash
to_hash
end
def to_hash
{
"account_name" => self.account_name,
"description" => self.description,
"ssh_key" => self.ssh_key,
"provider" => self.provider,
"created_at" => self.created_at
}
end
def to_mongo_hash
{
"_id" => self.account_name,
"description" => self.description,
"ssh_key" => self.ssh_key,
"provider" => self.provider
}
end
end
end
end