Module: CommandTower::Messaging::Endpoints::Validators::Pushover
- Defined in:
- app/services/command_tower/messaging/endpoints/validators/pushover.rb
Constant Summary collapse
- MIN_LENGTH =
8
Class Method Summary collapse
- .coerce_credentials!(credentials) ⇒ Object
- .mask_user_key(key) ⇒ Object
- .normalize_secret!(value, label:) ⇒ Object
-
.validate!(address) ⇒ Object
Legacy single-address path retained for model/spec helpers that still normalize a user key string — façade create/replace use credentials.
- .validate_credentials!(credentials) ⇒ Object
Class Method Details
.coerce_credentials!(credentials) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'app/services/command_tower/messaging/endpoints/validators/pushover.rb', line 54 def coerce_credentials!(credentials) unless credentials.is_a?(Hash) raise ValidationError, "pushover credentials must be a Hash with user_key and application_token" end { user_key: credentials[:user_key] || credentials["user_key"], application_token: credentials[:application_token] || credentials["application_token"], } end |
.mask_user_key(key) ⇒ Object
46 47 48 49 50 51 52 |
# File 'app/services/command_tower/messaging/endpoints/validators/pushover.rb', line 46 def mask_user_key(key) if key.length >= 4 "#{"•" * 8}#{key[-4, 4]}" else "configured" end end |
.normalize_secret!(value, label:) ⇒ Object
38 39 40 41 42 43 44 |
# File 'app/services/command_tower/messaging/endpoints/validators/pushover.rb', line 38 def normalize_secret!(value, label:) secret = value.to_s.strip raise ValidationError, "#{label} must be present" if secret.empty? raise ValidationError, "#{label} is too short" if secret.length < MIN_LENGTH secret end |
.validate!(address) ⇒ Object
Legacy single-address path retained for model/spec helpers that still normalize a user key string — façade create/replace use credentials.
14 15 16 17 18 19 20 |
# File 'app/services/command_tower/messaging/endpoints/validators/pushover.rb', line 14 def validate!(address) key = normalize_secret!(address, label: "pushover user key") Result.new( normalized_address: key, masked_display_value: mask_user_key(key), ) end |
.validate_credentials!(credentials) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/services/command_tower/messaging/endpoints/validators/pushover.rb', line 22 def validate_credentials!(credentials) hash = coerce_credentials!(credentials) user_key = normalize_secret!(hash[:user_key], label: "pushover user key") application_token = normalize_secret!( hash[:application_token], label: "pushover application token", ) PushoverCredentialsResult.new( normalized_user_key: user_key, normalized_application_token: application_token, masked_display_value: mask_user_key(user_key), pair_fingerprint_material: "#{user_key}\n#{application_token}", ) end |