@@ -326,6 +326,64 @@ func writeHermesDiscordChannelConfig(confDir string, config dto.AgentDiscordConf
326326 return writeHermesConfigMap (configPath , cfg )
327327}
328328
329+ func deleteHermesEnvKeys (confDir string , keys ... string ) error {
330+ envPath := path .Join (confDir , ".env" )
331+ envMap , err := readHermesEnvMap (envPath )
332+ if err != nil {
333+ return err
334+ }
335+ for _ , key := range keys {
336+ delete (envMap , key )
337+ }
338+ return writeHermesEnvMap (envPath , envMap , keys )
339+ }
340+
341+ func deleteHermesConfigSections (confDir string , topLevelKeys []string , platformKeys []string ) error {
342+ configPath := path .Join (confDir , "config.yaml" )
343+ cfg , err := readHermesConfigMap (configPath )
344+ if err != nil {
345+ return err
346+ }
347+ for _ , key := range topLevelKeys {
348+ delete (cfg , key )
349+ }
350+ if len (platformKeys ) > 0 {
351+ if platforms , ok := cfg ["platforms" ].(map [string ]interface {}); ok {
352+ for _ , key := range platformKeys {
353+ delete (platforms , key )
354+ }
355+ if len (platforms ) == 0 {
356+ delete (cfg , "platforms" )
357+ }
358+ }
359+ }
360+ return writeHermesConfigMap (configPath , cfg )
361+ }
362+
363+ func deleteHermesTelegramChannelConfig (confDir string ) error {
364+ if err := deleteHermesEnvKeys (confDir ,
365+ "TELEGRAM_BOT_TOKEN" ,
366+ "TELEGRAM_ALLOWED_USERS" ,
367+ "TELEGRAM_ALLOW_ALL_USERS" ,
368+ "TELEGRAM_HOME_CHANNEL" ,
369+ ); err != nil {
370+ return err
371+ }
372+ return deleteHermesConfigSections (confDir , []string {"telegram" }, []string {"telegram" })
373+ }
374+
375+ func deleteHermesDiscordChannelConfig (confDir string ) error {
376+ if err := deleteHermesEnvKeys (confDir ,
377+ "DISCORD_BOT_TOKEN" ,
378+ "DISCORD_ALLOWED_USERS" ,
379+ "DISCORD_ALLOW_ALL_USERS" ,
380+ "DISCORD_HOME_CHANNEL" ,
381+ ); err != nil {
382+ return err
383+ }
384+ return deleteHermesConfigSections (confDir , []string {"discord" }, []string {"discord" })
385+ }
386+
329387func normalizeHermesTimezone (timezone string ) string {
330388 timezone = strings .TrimSpace (timezone )
331389 if timezone == "" {
@@ -566,13 +624,21 @@ func extractHermesEnvBool(envMap map[string]string, key string, defaultValue boo
566624 return strings .EqualFold (value , "true" )
567625}
568626
569- func validateHermesPairingApproveOutput (output string ) error {
570- text := strings .TrimSpace (output )
571- if text == "" {
627+ func validateHermesPairingApproveResult (output string , err error ) error {
628+ if strings .Contains (output , "Approved!" ) {
572629 return nil
573630 }
574- if strings .Contains (text , "not found or expired for platform" ) {
575- return errors .New (text )
631+ if strings .Contains (output , "not found or expired for platform" ) {
632+ return buserr .New ("ErrHermesPairingCodeUnavailable" )
633+ }
634+ if err == nil {
635+ if strings .TrimSpace (output ) == "" {
636+ return fmt .Errorf ("unexpected hermes pairing approve result" )
637+ }
638+ return errors .New (strings .TrimSpace (output ))
639+ }
640+ if strings .Contains (err .Error (), "not found or expired for platform" ) {
641+ return buserr .New ("ErrHermesPairingCodeUnavailable" )
576642 }
577- return nil
643+ return err
578644}
0 commit comments