| 
									
										
										
										
											2015-10-22 12:39:22 +03:00
										 |  |  | require "db/mongo/models/mongo_model" | 
					
						
							|  |  |  | require "db/mongo/models/model_with_provider" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Devops | 
					
						
							|  |  |  |   module Model | 
					
						
							|  |  |  |     class ProviderAccount < MongoModel | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       include ModelWithProvider | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:09:38 +03:00
										 |  |  | #      attr_accessor :account_name, :description, :ssh_key | 
					
						
							| 
									
										
										
										
											2015-11-02 11:42:20 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:09:38 +03:00
										 |  |  |       set_field_validators :account_name, [::Validators::FieldValidator::NotNil, | 
					
						
							| 
									
										
										
										
											2015-11-02 17:33:25 +03:00
										 |  |  |                                           ::Validators::FieldValidator::FieldType::String, | 
					
						
							|  |  |  |                                           ::Validators::FieldValidator::NotEmpty, | 
					
						
							| 
									
										
										
										
											2015-11-19 14:09:38 +03:00
										 |  |  |                                           ::Validators::FieldValidator::Name] | 
					
						
							| 
									
										
										
										
											2015-11-02 17:33:25 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:09:38 +03:00
										 |  |  |       set_field_validators :description, [::Validators::FieldValidator::Nil, | 
					
						
							| 
									
										
										
										
											2015-11-02 17:33:25 +03:00
										 |  |  |                                          ::Validators::FieldValidator::FieldType::String, | 
					
						
							|  |  |  |                                          ::Validators::FieldValidator::NotEmpty, | 
					
						
							| 
									
										
										
										
											2015-11-19 14:09:38 +03:00
										 |  |  |                                          ::Validators::FieldValidator::Description] | 
					
						
							| 
									
										
										
										
											2015-11-02 17:33:25 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:09:38 +03:00
										 |  |  |       set_field_validators :ssh_key, [::Validators::FieldValidator::NotNil, | 
					
						
							| 
									
										
										
										
											2015-11-02 17:33:25 +03:00
										 |  |  |                                      ::Validators::FieldValidator::FieldType::String, | 
					
						
							|  |  |  |                                      ::Validators::FieldValidator::NotEmpty, | 
					
						
							| 
									
										
										
										
											2015-11-19 14:09:38 +03:00
										 |  |  |                                      ::Validators::FieldValidator::SshKey] | 
					
						
							| 
									
										
										
										
											2015-11-02 17:33:25 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-02 11:42:20 +03:00
										 |  |  |       ACCOUNT_FIELDS = { | 
					
						
							|  |  |  |         account_name: "Account name (id)", | 
					
						
							|  |  |  |         description: "Account description", | 
					
						
							|  |  |  |         ssh_key: "Ssh key id" | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2015-10-22 12:39:22 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       def initialize a={} | 
					
						
							|  |  |  |         self.account_name = a["account_name"] | 
					
						
							|  |  |  |         self.description = a["description"] | 
					
						
							|  |  |  |         self.ssh_key = a["ssh_key"] | 
					
						
							|  |  |  |         self.provider = a["provider"] | 
					
						
							| 
									
										
										
										
											2015-10-26 12:04:01 +03:00
										 |  |  |         self.created_at = a["created_at"] | 
					
						
							| 
									
										
										
										
											2015-10-22 12:39:22 +03:00
										 |  |  |       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, | 
					
						
							| 
									
										
										
										
											2015-10-26 12:04:01 +03:00
										 |  |  |           "created_at" => self.created_at | 
					
						
							| 
									
										
										
										
											2015-10-22 12:39:22 +03:00
										 |  |  |         } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def to_mongo_hash | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           "_id" => self.account_name, | 
					
						
							|  |  |  |           "description" => self.description, | 
					
						
							|  |  |  |           "ssh_key" => self.ssh_key, | 
					
						
							| 
									
										
										
										
											2015-11-02 11:42:20 +03:00
										 |  |  |           "provider" => self.provider | 
					
						
							| 
									
										
										
										
											2015-10-22 12:39:22 +03:00
										 |  |  |         } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-10 17:47:36 +03:00
										 |  |  |       # absent of "id" attribute can cause some inconviniences. | 
					
						
							|  |  |  |       # for example, we have "record.id" call in InsertCommand | 
					
						
							|  |  |  |       def id | 
					
						
							|  |  |  |         account_name | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 12:39:22 +03:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |