Saves the token to the .env file. This will create or overwrite the file.
(self, token)
| 104 | return None |
| 105 | |
| 106 | def save_token(self, token): |
| 107 | """ |
| 108 | Saves the token to the .env file. This will create or overwrite the file. |
| 109 | """ |
| 110 | try: |
| 111 | with open(self.env_file_path, 'w') as f: |
| 112 | f.write(f'RAGNAR_OPENAI_API_KEY={token}\n') |
| 113 | |
| 114 | # Also set it in the current running process's environment for immediate use |
| 115 | os.environ['RAGNAR_OPENAI_API_KEY'] = token |
| 116 | |
| 117 | logger.info(f"Token saved to {self.env_file_path}") |
| 118 | return {"success": True, "message": "✓ API token saved. Please restart the Ragnar service to apply the changes."} |
| 119 | except Exception as e: |
| 120 | logger.error(f"Failed to save token to .env file: {e}", exc_info=True) |
| 121 | return {"success": False, "message": f"✗ Failed to save token to .env file: {e}"} |
| 122 | |
| 123 | def get_token_status(self): |
| 124 | """ |
no test coverage detected