2023-07-17 04:23:26 +03:00
|
|
|
package actions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/quexten/goldwarden/agent/config"
|
|
|
|
"github.com/quexten/goldwarden/agent/sockets"
|
|
|
|
"github.com/quexten/goldwarden/agent/vault"
|
|
|
|
"github.com/quexten/goldwarden/ipc"
|
|
|
|
)
|
|
|
|
|
2023-09-12 19:56:35 +03:00
|
|
|
func handleSetApiURL(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
2023-07-17 04:23:26 +03:00
|
|
|
apiURL := request.ParsedPayload().(ipc.SetApiURLRequest).Value
|
|
|
|
cfg.ConfigFile.ApiUrl = apiURL
|
|
|
|
err = cfg.WriteConfig()
|
|
|
|
if err != nil {
|
|
|
|
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
|
|
|
Success: false,
|
|
|
|
Message: err.Error(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
|
|
|
Success: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-09-12 19:56:35 +03:00
|
|
|
func handleSetIdentity(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
2023-07-17 04:23:26 +03:00
|
|
|
identity := request.ParsedPayload().(ipc.SetIdentityURLRequest).Value
|
|
|
|
cfg.ConfigFile.IdentityUrl = identity
|
|
|
|
err = cfg.WriteConfig()
|
|
|
|
if err != nil {
|
|
|
|
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
|
|
|
Success: false,
|
|
|
|
Message: err.Error(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
|
|
|
Success: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-09-12 19:56:35 +03:00
|
|
|
func handleSetNotifications(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response ipc.IPCMessage, err error) {
|
2023-09-11 16:39:19 +03:00
|
|
|
notifications := request.ParsedPayload().(ipc.SetNotificationsURLRequest).Value
|
|
|
|
cfg.ConfigFile.NotificationsUrl = notifications
|
|
|
|
err = cfg.WriteConfig()
|
|
|
|
if err != nil {
|
|
|
|
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
|
|
|
Success: false,
|
|
|
|
Message: err.Error(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return ipc.IPCMessageFromPayload(ipc.ActionResponse{
|
|
|
|
Success: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-07-17 04:23:26 +03:00
|
|
|
func init() {
|
|
|
|
AgentActionsRegistry.Register(ipc.IPCMessageTypeSetIdentityURLRequest, handleSetIdentity)
|
|
|
|
AgentActionsRegistry.Register(ipc.IPCMessageTypeSetAPIUrlRequest, handleSetApiURL)
|
2023-09-11 16:39:19 +03:00
|
|
|
AgentActionsRegistry.Register(ipc.IPCMessageTypeSetNotificationsURLRequest, handleSetNotifications)
|
2023-07-17 04:23:26 +03:00
|
|
|
}
|