70 lines
2.2 KiB
Ruby
70 lines
2.2 KiB
Ruby
require 'tempfile'
|
|
require 'securerandom'
|
|
require "db/mongo/models/model_with_provider"
|
|
require "db/validators/stack_template/template_content"
|
|
|
|
module Devops
|
|
module Model
|
|
class StackTemplateBase < MongoModel
|
|
|
|
include ModelWithProvider
|
|
|
|
attr_accessor :id, :template_body, :provider, :owner
|
|
|
|
types id: {type: String, empty: false},
|
|
provider: {type: String, empty: false},
|
|
template_body: {type: String, empty: false},
|
|
owner: {type: String, empty: false}
|
|
|
|
set_field_validators :id, ::Validators::FieldValidator::NotNil,
|
|
::Validators::FieldValidator::FieldType::String,
|
|
::Validators::FieldValidator::NotEmpty,
|
|
::Validators::FieldValidator::Name
|
|
|
|
set_field_validators :provider, ::Validators::FieldValidator::NotNil,
|
|
::Validators::FieldValidator::FieldType::String,
|
|
::Validators::FieldValidator::NotEmpty
|
|
|
|
set_field_validators :template_body, ::Validators::FieldValidator::NotNil,
|
|
::Validators::FieldValidator::FieldType::String,
|
|
::Validators::FieldValidator::NotEmpty
|
|
|
|
set_field_validators :owner, ::Validators::FieldValidator::NotNil,
|
|
::Validators::FieldValidator::FieldType::String,
|
|
::Validators::FieldValidator::NotEmpty
|
|
|
|
set_validators ::Validators::StackTemplate::TemplateContent
|
|
|
|
def initialize(attrs)
|
|
self.id = attrs['id']
|
|
self.template_body = attrs['template_body']
|
|
self.provider = attrs['provider']
|
|
self.owner = attrs['owner']
|
|
self
|
|
end
|
|
|
|
def to_hash_without_id
|
|
{
|
|
provider: provider,
|
|
template_body: template_body,
|
|
owner: owner
|
|
}
|
|
end
|
|
|
|
# attrs should include:
|
|
# - id (String)
|
|
# - provider (String)
|
|
# - template_body (String)
|
|
def self.create(attrs)
|
|
new(attrs)
|
|
end
|
|
|
|
def self.build_from_bson(attrs)
|
|
attrs['id'] = attrs["_id"]
|
|
self.new(attrs)
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|