Class: CommandTower::Messaging::Endpoints::SecretReader
- Inherits:
-
Object
- Object
- CommandTower::Messaging::Endpoints::SecretReader
- Defined in:
- app/services/command_tower/messaging/endpoints/secret_reader.rb
Overview
Internal decrypt-at-use. Not part of the safe public façade.
Class Method Summary collapse
- .read!(owner_user_id:, endpoint_id:) ⇒ Object
- .read_pushover_credentials!(owner_user_id:, endpoint_id:) ⇒ Object
Instance Method Summary collapse
-
#initialize(owner_user_id:, endpoint_id:) ⇒ SecretReader
constructor
A new instance of SecretReader.
- #read! ⇒ Object
- #read_pushover_credentials! ⇒ Object
Constructor Details
#initialize(owner_user_id:, endpoint_id:) ⇒ SecretReader
Returns a new instance of SecretReader.
16 17 18 19 |
# File 'app/services/command_tower/messaging/endpoints/secret_reader.rb', line 16 def initialize(owner_user_id:, endpoint_id:) @owner_user_id = owner_user_id @endpoint_id = endpoint_id end |
Class Method Details
.read!(owner_user_id:, endpoint_id:) ⇒ Object
8 9 10 |
# File 'app/services/command_tower/messaging/endpoints/secret_reader.rb', line 8 def self.read!(owner_user_id:, endpoint_id:) new(owner_user_id:, endpoint_id:).read! end |
.read_pushover_credentials!(owner_user_id:, endpoint_id:) ⇒ Object
12 13 14 |
# File 'app/services/command_tower/messaging/endpoints/secret_reader.rb', line 12 def self.read_pushover_credentials!(owner_user_id:, endpoint_id:) new(owner_user_id:, endpoint_id:).read_pushover_credentials! end |
Instance Method Details
#read! ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/services/command_tower/messaging/endpoints/secret_reader.rb', line 21 def read! record = load_supported_record! if record.typed_credentials_channel? raise ValidationError, "use read_pushover_credentials! for pushover endpoints" end if record.address_ciphertext.blank? raise ValidationError, "endpoint has no address ciphertext" end SecretBox.decrypt( record.address_ciphertext, key_version: record.encryption_key_version, ) end |
#read_pushover_credentials! ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/services/command_tower/messaging/endpoints/secret_reader.rb', line 36 def read_pushover_credentials! record = load_supported_record! unless record.channel_key == "pushover" raise ValidationError, "endpoint is not a pushover endpoint" end credential = record.pushover_credential raise ValidationError, "pushover credentials are missing" if credential.nil? key_version = credential.encryption_key_version { user_key: SecretBox.decrypt( credential.user_key_ciphertext, key_version:, purpose: SecretBox::PUSHOVER_USER_KEY_PURPOSE, ), application_token: SecretBox.decrypt( credential.application_token_ciphertext, key_version:, purpose: SecretBox::PUSHOVER_APPLICATION_TOKEN_PURPOSE, ), } end |