mirror of
https://github.com/quexten/goldwarden.git
synced 2024-12-24 03:44:48 +03:00
106 lines
4.0 KiB
Go
106 lines
4.0 KiB
Go
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/messages"
|
|
)
|
|
|
|
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
|
|
cfg.ConfigFile.ApiUrl = apiURL
|
|
err = cfg.WriteConfig()
|
|
if err != nil {
|
|
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
|
Success: false,
|
|
Message: err.Error(),
|
|
})
|
|
}
|
|
|
|
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
|
Success: true,
|
|
})
|
|
}
|
|
|
|
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
|
|
cfg.ConfigFile.IdentityUrl = identity
|
|
err = cfg.WriteConfig()
|
|
if err != nil {
|
|
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
|
Success: false,
|
|
Message: err.Error(),
|
|
})
|
|
}
|
|
|
|
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
|
Success: true,
|
|
})
|
|
}
|
|
|
|
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 {
|
|
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
|
Success: false,
|
|
Message: err.Error(),
|
|
})
|
|
}
|
|
|
|
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
|
Success: true,
|
|
})
|
|
}
|
|
|
|
func handleSetClientID(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
|
clientID := messages.ParsePayload(request).(messages.SetClientIDRequest).Value
|
|
cfg.SetClientID(clientID)
|
|
err = cfg.WriteConfig()
|
|
if err != nil {
|
|
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
|
Success: false,
|
|
Message: err.Error(),
|
|
})
|
|
}
|
|
|
|
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
|
Success: true,
|
|
})
|
|
}
|
|
|
|
func handleSetClientSecret(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
|
clientSecret := messages.ParsePayload(request).(messages.SetClientSecretRequest).Value
|
|
cfg.SetClientSecret(clientSecret)
|
|
err = cfg.WriteConfig()
|
|
if err != nil {
|
|
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
|
Success: false,
|
|
Message: err.Error(),
|
|
})
|
|
}
|
|
|
|
return messages.IPCMessageFromPayload(messages.ActionResponse{
|
|
Success: true,
|
|
})
|
|
}
|
|
|
|
func handleGetRuntimeConfig(request messages.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx *sockets.CallingContext) (response messages.IPCMessage, err error) {
|
|
return messages.IPCMessageFromPayload(messages.GetRuntimeConfigResponse{
|
|
UseMemguard: cfg.ConfigFile.RuntimeConfig.UseMemguard,
|
|
SSHAgentSocketPath: cfg.ConfigFile.RuntimeConfig.SSHAgentSocketPath,
|
|
GoldwardenSocketPath: cfg.ConfigFile.RuntimeConfig.GoldwardenSocketPath,
|
|
})
|
|
}
|
|
|
|
func init() {
|
|
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.SetIdentityURLRequest{}), handleSetIdentity)
|
|
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.SetApiURLRequest{}), handleSetApiURL)
|
|
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.SetNotificationsURLRequest{}), handleSetNotifications)
|
|
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.GetRuntimeConfigRequest{}), handleGetRuntimeConfig)
|
|
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.SetClientIDRequest{}), handleSetClientID)
|
|
AgentActionsRegistry.Register(messages.MessageTypeForEmptyPayload(messages.SetClientSecretRequest{}), handleSetClientSecret)
|
|
}
|