Class: Mcpeasy::Config
- Inherits:
-
Object
- Object
- Mcpeasy::Config
- Defined in:
- lib/mcpeasy/config.rb
Constant Summary collapse
- CONFIG_DIR =
File.("~/.config/mcpeasy").freeze
- GOOGLE_DIR =
File.join(CONFIG_DIR, "google").freeze
- SLACK_DIR =
File.join(CONFIG_DIR, "slack").freeze
- NOTION_DIR =
File.join(CONFIG_DIR, "notion").freeze
- LOGS_DIR =
File.("~/.local/share/mcpeasy/logs").freeze
Class Method Summary collapse
- .config_status ⇒ Object
- .ensure_config_dirs ⇒ Object
- .google_client_id ⇒ Object
- .google_client_secret ⇒ Object
- .google_credentials ⇒ Object
-
.google_credentials_path ⇒ Object
Google credentials management.
- .google_token ⇒ Object
-
.google_token_path ⇒ Object
Google token management.
- .log_file_path(service, type = "error") ⇒ Object
-
.logs_dir ⇒ Object
Logs directory.
- .notion_api_key ⇒ Object
-
.notion_token_path ⇒ Object
Notion configuration.
- .save_google_credentials(credentials_json) ⇒ Object
- .save_google_token(token_data) ⇒ Object
- .save_notion_api_key(api_key) ⇒ Object
- .save_slack_bot_token(token) ⇒ Object
- .slack_bot_token ⇒ Object
-
.slack_token_path ⇒ Object
Slack configuration.
Class Method Details
.config_status ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/mcpeasy/config.rb', line 111 def config_status { config_dir: CONFIG_DIR, logs_dir: LOGS_DIR, google_credentials: File.exist?(google_credentials_path), google_token: File.exist?(google_token_path), slack_config: File.exist?(slack_token_path), notion_config: File.exist?(notion_token_path) } end |
.ensure_config_dirs ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/mcpeasy/config.rb', line 16 def ensure_config_dirs FileUtils.mkdir_p(CONFIG_DIR) FileUtils.mkdir_p(GOOGLE_DIR) FileUtils.mkdir_p(SLACK_DIR) FileUtils.mkdir_p(NOTION_DIR) FileUtils.mkdir_p(LOGS_DIR) end |
.google_client_id ⇒ Object
39 40 41 42 43 |
# File 'lib/mcpeasy/config.rb', line 39 def google_client_id credentials = google_credentials return nil unless credentials credentials.installed&.client_id || credentials.web&.client_id end |
.google_client_secret ⇒ Object
45 46 47 48 49 |
# File 'lib/mcpeasy/config.rb', line 45 def google_client_secret credentials = google_credentials return nil unless credentials credentials.installed&.client_secret || credentials.web&.client_secret end |
.google_credentials ⇒ Object
29 30 31 32 |
# File 'lib/mcpeasy/config.rb', line 29 def google_credentials return nil unless File.exist?(google_credentials_path) Mother.create(google_credentials_path) end |
.google_credentials_path ⇒ Object
Google credentials management
25 26 27 |
# File 'lib/mcpeasy/config.rb', line 25 def google_credentials_path File.join(GOOGLE_DIR, "credentials.json") end |
.google_token ⇒ Object
56 57 58 59 |
# File 'lib/mcpeasy/config.rb', line 56 def google_token return nil unless File.exist?(google_token_path) Mother.create(google_token_path) end |
.google_token_path ⇒ Object
Google token management
52 53 54 |
# File 'lib/mcpeasy/config.rb', line 52 def google_token_path File.join(GOOGLE_DIR, "token.json") end |
.log_file_path(service, type = "error") ⇒ Object
107 108 109 |
# File 'lib/mcpeasy/config.rb', line 107 def log_file_path(service, type = "error") File.join(LOGS_DIR, "mcp_#{service}_#{type}.log") end |
.logs_dir ⇒ Object
Logs directory
103 104 105 |
# File 'lib/mcpeasy/config.rb', line 103 def logs_dir LOGS_DIR end |
.notion_api_key ⇒ Object
89 90 91 92 93 |
# File 'lib/mcpeasy/config.rb', line 89 def notion_api_key return nil unless File.exist?(notion_token_path) config = JSON.parse(File.read(notion_token_path)) config["api_key"] end |
.notion_token_path ⇒ Object
Notion configuration
85 86 87 |
# File 'lib/mcpeasy/config.rb', line 85 def notion_token_path File.join(NOTION_DIR, "token.json") end |
.save_google_credentials(credentials_json) ⇒ Object
34 35 36 37 |
# File 'lib/mcpeasy/config.rb', line 34 def save_google_credentials(credentials_json) ensure_config_dirs File.write(google_credentials_path, credentials_json) end |
.save_google_token(token_data) ⇒ Object
61 62 63 64 |
# File 'lib/mcpeasy/config.rb', line 61 def save_google_token(token_data) ensure_config_dirs File.write(google_token_path, JSON.pretty_generate(token_data)) end |
.save_notion_api_key(api_key) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/mcpeasy/config.rb', line 95 def save_notion_api_key(api_key) ensure_config_dirs config = File.exist?(notion_token_path) ? JSON.parse(File.read(notion_token_path)) : {} config["api_key"] = api_key File.write(notion_token_path, JSON.pretty_generate(config)) end |
.save_slack_bot_token(token) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/mcpeasy/config.rb', line 77 def save_slack_bot_token(token) ensure_config_dirs config = File.exist?(slack_token_path) ? JSON.parse(File.read(slack_token_path)) : {} config["bot_token"] = token File.write(slack_token_path, JSON.pretty_generate(config)) end |
.slack_bot_token ⇒ Object
71 72 73 74 75 |
# File 'lib/mcpeasy/config.rb', line 71 def slack_bot_token return nil unless File.exist?(slack_token_path) config = JSON.parse(File.read(slack_token_path)) config["bot_token"] end |
.slack_token_path ⇒ Object
Slack configuration
67 68 69 |
# File 'lib/mcpeasy/config.rb', line 67 def slack_token_path File.join(SLACK_DIR, "token.json") end |