goldwarden-vaultwarden-bitw.../agent/actions/config.go

63 lines
2.2 KiB
Go
Raw Normal View History

2023-07-17 03:23:26 +02:00
package actions
import (
"github.com/quexten/goldwarden/agent/config"
"github.com/quexten/goldwarden/agent/sockets"
"github.com/quexten/goldwarden/agent/vault"
2023-09-20 03:05:44 +02:00
"github.com/quexten/goldwarden/ipc/messages"
2023-07-17 03:23:26 +02:00
)
2023-09-20 03:05:44 +02:00
func handleSetApiURL(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response messages.IPCMessage, err error) {
apiURL := messages.ParsePayload(request).(messages.SetApiURLRequest).Value
2023-07-17 03:23:26 +02:00
cfg.ConfigFile.ApiUrl = apiURL
err = cfg.WriteConfig()
if err != nil {
2023-09-20 03:05:44 +02:00
return messages.IPCMessageFromPayload(messages.ActionResponse{
2023-07-17 03:23:26 +02:00
Success: false,
Message: err.Error(),
})
}
2023-09-20 03:05:44 +02:00
return messages.IPCMessageFromPayload(messages.ActionResponse{
2023-07-17 03:23:26 +02:00
Success: true,
})
}
2023-09-20 03:05:44 +02:00
func handleSetIdentity(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response messages.IPCMessage, err error) {
identity := messages.ParsePayload(request).(messages.SetIdentityURLRequest).Value
2023-07-17 03:23:26 +02:00
cfg.ConfigFile.IdentityUrl = identity
err = cfg.WriteConfig()
if err != nil {
2023-09-20 03:05:44 +02:00
return messages.IPCMessageFromPayload(messages.ActionResponse{
2023-07-17 03:23:26 +02:00
Success: false,
Message: err.Error(),
})
}
2023-09-20 03:05:44 +02:00
return messages.IPCMessageFromPayload(messages.ActionResponse{
2023-07-17 03:23:26 +02:00
Success: true,
})
}
2023-09-20 03:05:44 +02:00
func handleSetNotifications(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response messages.IPCMessage, err error) {
notifications := messages.ParsePayload(request).(messages.SetNotificationsURLRequest).Value
cfg.ConfigFile.NotificationsUrl = notifications
err = cfg.WriteConfig()
if err != nil {
2023-09-20 03:05:44 +02:00
return messages.IPCMessageFromPayload(messages.ActionResponse{
Success: false,
Message: err.Error(),
})
}
2023-09-20 03:05:44 +02:00
return messages.IPCMessageFromPayload(messages.ActionResponse{
Success: true,
})
}
2023-07-17 03:23:26 +02:00
func init() {
2023-09-20 03:05:44 +02:00
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.SetIdentityURLRequest{}), handleSetIdentity)
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.SetApiURLRequest{}), handleSetApiURL)
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.SetNotificationsURLRequest{}), handleSetNotifications)
2023-07-17 03:23:26 +02:00
}