Class: Key
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Key
- Includes:
- AfterCommitQueue, Expirable, Sha256Attribute, Sortable
- Defined in:
- app/models/key.rb
Direct Known Subclasses
Constant Summary
Constants included from Expirable
Class Method Summary collapse
Instance Method Summary collapse
-
#add_to_authorized_keys ⇒ Object
rubocop: enable CodeReuse/ServiceClass.
-
#can_delete? ⇒ Boolean
EE overrides this.
- #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
-
#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
at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order
Class Method Details
.regular_keys ⇒ Object
47 48 49 |
# File 'app/models/key.rb', line 47 def self.regular_keys where(type: ['Key', nil]) end |
Instance Method Details
#add_to_authorized_keys ⇒ Object
rubocop: enable CodeReuse/ServiceClass
83 84 85 86 87 |
# File 'app/models/key.rb', line 83 def return unless Gitlab::CurrentSettings. AuthorizedKeysWorker.perform_async(:add_key, shell_id, key) end |
#can_delete? ⇒ Boolean
EE overrides this
73 74 75 |
# File 'app/models/key.rb', line 73 def can_delete? true end |
#key=(value) ⇒ Object
51 52 53 54 55 |
# File 'app/models/key.rb', line 51 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
90 91 92 |
# File 'app/models/key.rb', line 90 def post_create_hook SystemHooksService.new.execute_hooks_for(self, :create) end |
#post_destroy_hook ⇒ Object
rubocop: disable CodeReuse/ServiceClass
110 111 112 |
# File 'app/models/key.rb', line 110 def post_destroy_hook SystemHooksService.new.execute_hooks_for(self, :destroy) end |
#projects ⇒ Object
projects that has this key
64 65 66 |
# File 'app/models/key.rb', line 64 def projects user. end |
#public_key ⇒ Object
rubocop: enable CodeReuse/ServiceClass
115 116 117 |
# File 'app/models/key.rb', line 115 def public_key @public_key ||= Gitlab::SSHPublicKey.new(key) end |
#publishable_key ⇒ Object
57 58 59 60 61 |
# File 'app/models/key.rb', line 57 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
102 103 104 105 106 |
# File 'app/models/key.rb', line 102 def refresh_user_cache return unless user Users::KeysCountService.new(user).refresh_cache end |
#remove_from_authorized_keys ⇒ Object
rubocop: enable CodeReuse/ServiceClass
95 96 97 98 99 |
# File 'app/models/key.rb', line 95 def return unless Gitlab::CurrentSettings. AuthorizedKeysWorker.perform_async(:remove_key, shell_id) end |
#shell_id ⇒ Object
68 69 70 |
# File 'app/models/key.rb', line 68 def shell_id "key-#{id}" end |
#update_last_used_at ⇒ Object
rubocop: disable CodeReuse/ServiceClass
78 79 80 |
# File 'app/models/key.rb', line 78 def update_last_used_at Keys::LastUsedService.new(self).execute end |