MCPcopy Create free account
hub / github.com/PatchMon/PatchMon / LoadCredentials

Method LoadCredentials

agent-source-code/internal/config/config.go:258–282  ·  view source on GitHub ↗

LoadCredentials loads API credentials from file

()

Source from the content-addressed store, hash-verified

256
257// LoadCredentials loads API credentials from file
258func (m *Manager) LoadCredentials() error {
259 if _, err := os.Stat(m.config.CredentialsFile); errors.Is(err, fs.ErrNotExist) {
260 return fmt.Errorf("credentials file not found at %s", m.config.CredentialsFile)
261 }
262
263 viper.New()
264 credViper := viper.New()
265 credViper.SetConfigFile(m.config.CredentialsFile)
266 credViper.SetConfigType("yaml")
267
268 if err := credViper.ReadInConfig(); err != nil {
269 return fmt.Errorf("error reading credentials file: %w", err)
270 }
271
272 m.credentials = &models.Credentials{}
273 if err := credViper.Unmarshal(m.credentials); err != nil {
274 return fmt.Errorf("error unmarshaling credentials: %w", err)
275 }
276
277 if m.credentials.APIID == "" || m.credentials.APIKey == "" {
278 return fmt.Errorf("api_id and api_key must be configured in %s", m.config.CredentialsFile)
279 }
280
281 return nil
282}
283
284// SaveCredentials saves API credentials to file using atomic write to prevent TOCTOU race
285func (m *Manager) SaveCredentials(apiID, apiKey string) error {

Callers 6

getServerVersionInfoFunction · 0.80
pingServerFunction · 0.80
runServiceLoopFunction · 0.80
showConfigFunction · 0.80
sendReportFunction · 0.80

Calls 2

SetConfigFileMethod · 0.80
UnmarshalMethod · 0.80

Tested by

no test coverage detected