Module: Tastytrade::FileStore
- Defined in:
- lib/tastytrade/file_store.rb
Overview
Secure file-based credential storage
Class Method Summary collapse
-
.available? ⇒ Boolean
Check if file storage is available.
-
.delete(key) ⇒ Boolean
Delete a credential file.
-
.get(key) ⇒ String?
Retrieve a credential from a file.
-
.set(key, value) ⇒ Boolean
Store a credential in a file.
Class Method Details
.available? ⇒ Boolean
Check if file storage is available
62 63 64 |
# File 'lib/tastytrade/file_store.rb', line 62 def available? true end |
.delete(key) ⇒ Boolean
Delete a credential file
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/tastytrade/file_store.rb', line 46 def delete(key) return false if key.nil? path = credential_path(key) return true unless File.exist?(path) File.delete(path) true rescue StandardError => e warn "Failed to delete credential: #{e.message}" if ENV["DEBUG_SESSION"] false end |
.get(key) ⇒ String?
Retrieve a credential from a file
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tastytrade/file_store.rb', line 30 def get(key) return nil if key.nil? path = credential_path(key) return nil unless File.exist?(path) File.read(path).strip rescue StandardError => e warn "Failed to retrieve credential: #{e.message}" if ENV["DEBUG_SESSION"] nil end |
.set(key, value) ⇒ Boolean
Store a credential in a file
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tastytrade/file_store.rb', line 15 def set(key, value) return false if key.nil? || value.nil? ensure_storage_directory File.write(credential_path(key), value.to_s, mode: "w", perm: 0o600) true rescue StandardError => e warn "Failed to store credential: #{e.message}" if ENV["DEBUG_SESSION"] false end |