2019-10-16 17:07:22 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Aws
|
|
|
|
class Role < ApplicationRecord
|
|
|
|
self.table_name = 'aws_roles'
|
|
|
|
|
|
|
|
belongs_to :user, inverse_of: :aws_role
|
|
|
|
|
|
|
|
validates :role_external_id, uniqueness: true, length: { in: 1..64 }
|
|
|
|
validates :role_arn,
|
|
|
|
length: 1..2048,
|
2020-09-02 11:10:54 -04:00
|
|
|
allow_nil: true,
|
2019-10-16 17:07:22 -04:00
|
|
|
format: {
|
|
|
|
with: Gitlab::Regex.aws_arn_regex,
|
|
|
|
message: Gitlab::Regex.aws_arn_regex_message
|
|
|
|
}
|
2019-11-08 01:06:24 -05:00
|
|
|
|
|
|
|
before_validation :ensure_role_external_id!, on: :create
|
|
|
|
|
|
|
|
def ensure_role_external_id!
|
|
|
|
self.role_external_id ||= SecureRandom.hex(20)
|
|
|
|
end
|
2019-10-16 17:07:22 -04:00
|
|
|
end
|
|
|
|
end
|