Class: Key
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Key
- Includes:
- AfterCommitQueue, Expirable, FromUnion, ShaAttribute, Sortable, Todoable
- Defined in:
- app/models/key.rb
Direct Known Subclasses
Constant Summary
Constants included from Expirable
Constants inherited from ApplicationRecord
Constants included from HasCheckConstraints
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
Constants included from ResetOnColumnErrors
ResetOnColumnErrors::MAX_RESET_PERIOD
Class Method Summary collapse
Instance Method Summary collapse
-
#add_to_authorized_keys ⇒ Object
rubocop: enable CodeReuse/ServiceClass.
-
#can_delete? ⇒ Boolean
EE overrides this.
- #ensure_sha256_fingerprint! ⇒ Object
- #key=(value) ⇒ Object
-
#post_create_hook ⇒ Object
rubocop: disable CodeReuse/ServiceClass.
-
#post_destroy_hook ⇒ Object
rubocop: disable CodeReuse/ServiceClass.
-
#projects ⇒ Object
projects that has this key.
-
#public_key ⇒ Object
rubocop: enable CodeReuse/ServiceClass.
- #publishable_key ⇒ Object
- #readable_by?(user) ⇒ Boolean
-
#refresh_user_cache ⇒ Object
rubocop: disable CodeReuse/ServiceClass.
-
#remove_from_authorized_keys ⇒ Object
rubocop: enable CodeReuse/ServiceClass.
- #shell_id ⇒ Object
- #signing? ⇒ Boolean
- #to_reference ⇒ Object
-
#update_last_used_at ⇒ Object
rubocop: disable CodeReuse/ServiceClass.
Methods included from Expirable
#expired?, #expires?, #expires_soon?
Methods included from AfterCommitQueue
#run_after_commit, #run_after_commit_or_now
Methods inherited from ApplicationRecord
===, cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, nullable_column?, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
Methods included from ResetOnColumnErrors
#reset_on_union_error, #reset_on_unknown_attribute_error
Methods included from Gitlab::SensitiveSerializableHash
Class Method Details
.regular_keys ⇒ Object
66 67 68 |
# File 'app/models/key.rb', line 66 def self.regular_keys where(type: ['Key', nil]) end |
Instance Method Details
#add_to_authorized_keys ⇒ Object
rubocop: enable CodeReuse/ServiceClass
102 103 104 105 106 |
# File 'app/models/key.rb', line 102 def return unless Gitlab::CurrentSettings. AuthorizedKeysWorker.perform_async('add_key', shell_id, key) end |
#can_delete? ⇒ Boolean
EE overrides this
92 93 94 |
# File 'app/models/key.rb', line 92 def can_delete? true end |
#ensure_sha256_fingerprint! ⇒ Object
138 139 140 141 142 |
# File 'app/models/key.rb', line 138 def ensure_sha256_fingerprint! return if self.fingerprint_sha256 save if generate_fingerprint end |
#key=(value) ⇒ Object
70 71 72 73 74 |
# File 'app/models/key.rb', line 70 def key=(value) write_attribute(:key, value.present? ? Gitlab::SSHPublicKey.sanitize(value) : nil) @public_key = nil end |
#post_create_hook ⇒ Object
rubocop: disable CodeReuse/ServiceClass
109 110 111 |
# File 'app/models/key.rb', line 109 def post_create_hook SystemHooksService.new.execute_hooks_for(self, :create) end |
#post_destroy_hook ⇒ Object
rubocop: disable CodeReuse/ServiceClass
129 130 131 |
# File 'app/models/key.rb', line 129 def post_destroy_hook SystemHooksService.new.execute_hooks_for(self, :destroy) end |
#projects ⇒ Object
projects that has this key
83 84 85 |
# File 'app/models/key.rb', line 83 def projects user. end |
#public_key ⇒ Object
rubocop: enable CodeReuse/ServiceClass
134 135 136 |
# File 'app/models/key.rb', line 134 def public_key @public_key ||= Gitlab::SSHPublicKey.new(key) end |
#publishable_key ⇒ Object
76 77 78 79 80 |
# File 'app/models/key.rb', line 76 def publishable_key # Strip out the keys comment so we don't leak email addresses # Replace with simple ident of user_name (hostname) self.key.split[0..1].push("#{self.user_name} (#{Gitlab.config.gitlab.host})").join(' ') end |
#readable_by?(user) ⇒ Boolean
148 149 150 |
# File 'app/models/key.rb', line 148 def readable_by?(user) user_id == user.id end |
#refresh_user_cache ⇒ Object
rubocop: disable CodeReuse/ServiceClass
121 122 123 124 125 |
# File 'app/models/key.rb', line 121 def refresh_user_cache return unless user Users::KeysCountService.new(user).refresh_cache end |
#remove_from_authorized_keys ⇒ Object
rubocop: enable CodeReuse/ServiceClass
114 115 116 117 118 |
# File 'app/models/key.rb', line 114 def return unless Gitlab::CurrentSettings. AuthorizedKeysWorker.perform_async('remove_key', shell_id) end |
#shell_id ⇒ Object
87 88 89 |
# File 'app/models/key.rb', line 87 def shell_id "key-#{id}" end |
#signing? ⇒ Boolean
144 145 146 |
# File 'app/models/key.rb', line 144 def signing? super || auth_and_signing? end |
#to_reference ⇒ Object
152 153 154 |
# File 'app/models/key.rb', line 152 def to_reference fingerprint end |
#update_last_used_at ⇒ Object
rubocop: disable CodeReuse/ServiceClass
97 98 99 |
# File 'app/models/key.rb', line 97 def update_last_used_at Keys::LastUsedService.new(self).execute_async end |