Class: Key
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Key
- Includes:
- AfterCommitQueue, Expirable, FromUnion, ShaAttribute, Sortable
- Defined in:
- app/models/key.rb
Direct Known Subclasses
Constant Summary
Constants included from Expirable
Constants inherited from ApplicationRecord
Constants included from ResetOnUnionError
ResetOnUnionError::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
-
#refresh_user_cache ⇒ Object
rubocop: disable CodeReuse/ServiceClass.
-
#remove_from_authorized_keys ⇒ Object
rubocop: enable CodeReuse/ServiceClass.
- #shell_id ⇒ Object
- #signing? ⇒ Boolean
-
#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, pluck_primary_key, primary_key_in, #readable_by?, 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 SensitiveSerializableHash
Class Method Details
.regular_keys ⇒ Object
63 64 65 |
# File 'app/models/key.rb', line 63 def self.regular_keys where(type: ['Key', nil]) end |
Instance Method Details
#add_to_authorized_keys ⇒ Object
rubocop: enable CodeReuse/ServiceClass
99 100 101 102 103 |
# File 'app/models/key.rb', line 99 def return unless Gitlab::CurrentSettings. AuthorizedKeysWorker.perform_async(:add_key, shell_id, key) end |
#can_delete? ⇒ Boolean
EE overrides this
89 90 91 |
# File 'app/models/key.rb', line 89 def can_delete? true end |
#ensure_sha256_fingerprint! ⇒ Object
135 136 137 138 139 |
# File 'app/models/key.rb', line 135 def ensure_sha256_fingerprint! return if self.fingerprint_sha256 save if generate_fingerprint end |
#key=(value) ⇒ Object
67 68 69 70 71 |
# File 'app/models/key.rb', line 67 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
106 107 108 |
# File 'app/models/key.rb', line 106 def post_create_hook SystemHooksService.new.execute_hooks_for(self, :create) end |
#post_destroy_hook ⇒ Object
rubocop: disable CodeReuse/ServiceClass
126 127 128 |
# File 'app/models/key.rb', line 126 def post_destroy_hook SystemHooksService.new.execute_hooks_for(self, :destroy) end |
#projects ⇒ Object
projects that has this key
80 81 82 |
# File 'app/models/key.rb', line 80 def projects user. end |
#public_key ⇒ Object
rubocop: enable CodeReuse/ServiceClass
131 132 133 |
# File 'app/models/key.rb', line 131 def public_key @public_key ||= Gitlab::SSHPublicKey.new(key) end |
#publishable_key ⇒ Object
73 74 75 76 77 |
# File 'app/models/key.rb', line 73 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 |
#refresh_user_cache ⇒ Object
rubocop: disable CodeReuse/ServiceClass
118 119 120 121 122 |
# File 'app/models/key.rb', line 118 def refresh_user_cache return unless user Users::KeysCountService.new(user).refresh_cache end |
#remove_from_authorized_keys ⇒ Object
rubocop: enable CodeReuse/ServiceClass
111 112 113 114 115 |
# File 'app/models/key.rb', line 111 def return unless Gitlab::CurrentSettings. AuthorizedKeysWorker.perform_async(:remove_key, shell_id) end |
#shell_id ⇒ Object
84 85 86 |
# File 'app/models/key.rb', line 84 def shell_id "key-#{id}" end |
#signing? ⇒ Boolean
141 142 143 |
# File 'app/models/key.rb', line 141 def signing? super || auth_and_signing? end |
#update_last_used_at ⇒ Object
rubocop: disable CodeReuse/ServiceClass
94 95 96 |
# File 'app/models/key.rb', line 94 def update_last_used_at Keys::LastUsedService.new(self).execute_async end |