Class: Mcpeasy::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/mcpeasy/config.rb

Constant Summary collapse

CONFIG_DIR =
File.expand_path("~/.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.expand_path("~/.local/share/mcpeasy/logs").freeze

Class Method Summary collapse

Class Method Details

.config_statusObject



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_dirsObject



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_idObject



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_secretObject



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_credentialsObject



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_pathObject

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_tokenObject



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_pathObject

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_dirObject

Logs directory



103
104
105
# File 'lib/mcpeasy/config.rb', line 103

def logs_dir
  LOGS_DIR
end

.notion_api_keyObject



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_pathObject

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_tokenObject



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_pathObject

Slack configuration



67
68
69
# File 'lib/mcpeasy/config.rb', line 67

def slack_token_path
  File.join(SLACK_DIR, "token.json")
end