Implement configuration on notification url
This commit is contained in:
parent
ef5083cfb4
commit
9129c7113c
3 changed files with 71 additions and 2 deletions
|
|
@ -39,7 +39,24 @@ func handleSetIdentity(request ipc.IPCMessage, cfg *config.Config, vault *vault.
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleSetNotifications(request ipc.IPCMessage, cfg *config.Config, vault *vault.Vault, ctx sockets.CallingContext) (response interface{}, err error) {
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeSetIdentityURLRequest, handleSetIdentity)
|
AgentActionsRegistry.Register(ipc.IPCMessageTypeSetIdentityURLRequest, handleSetIdentity)
|
||||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeSetAPIUrlRequest, handleSetApiURL)
|
AgentActionsRegistry.Register(ipc.IPCMessageTypeSetAPIUrlRequest, handleSetApiURL)
|
||||||
|
AgentActionsRegistry.Register(ipc.IPCMessageTypeSetNotificationsURLRequest, handleSetNotifications)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,40 @@ var setIdentityURLCmd = &cobra.Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var setNotificationsURLCmd = &cobra.Command{
|
||||||
|
Use: "set-notifications-url",
|
||||||
|
Short: "Set the notifications url",
|
||||||
|
Long: `Set the notifications url.`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
if len(args) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
url := args[0]
|
||||||
|
request := ipc.SetNotificationsURLRequest{}
|
||||||
|
request.Value = url
|
||||||
|
|
||||||
|
result, err := commandClient.SendToAgent(request)
|
||||||
|
if err != nil {
|
||||||
|
println("Error: " + err.Error())
|
||||||
|
println("Is the daemon running?")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch result.(type) {
|
||||||
|
case ipc.ActionResponse:
|
||||||
|
if result.(ipc.ActionResponse).Success {
|
||||||
|
println("Done")
|
||||||
|
} else {
|
||||||
|
println("Setting notifications url failed: " + result.(ipc.ActionResponse).Message)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
println("Wrong IPC response type")
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var configCmd = &cobra.Command{
|
var configCmd = &cobra.Command{
|
||||||
Use: "config",
|
Use: "config",
|
||||||
Short: "Manage the configuration",
|
Short: "Manage the configuration",
|
||||||
|
|
@ -83,4 +117,5 @@ func init() {
|
||||||
rootCmd.AddCommand(configCmd)
|
rootCmd.AddCommand(configCmd)
|
||||||
configCmd.AddCommand(setApiUrlCmd)
|
configCmd.AddCommand(setApiUrlCmd)
|
||||||
configCmd.AddCommand(setIdentityURLCmd)
|
configCmd.AddCommand(setIdentityURLCmd)
|
||||||
|
configCmd.AddCommand(setNotificationsURLCmd)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
21
ipc/ipc.go
21
ipc/ipc.go
|
|
@ -45,8 +45,9 @@ const (
|
||||||
|
|
||||||
IPCMessageTypeGetVaultPINStatusRequest IPCMessageType = 2
|
IPCMessageTypeGetVaultPINStatusRequest IPCMessageType = 2
|
||||||
|
|
||||||
IPCMessageTypeSetAPIUrlRequest IPCMessageType = 30
|
IPCMessageTypeSetAPIUrlRequest IPCMessageType = 30
|
||||||
IPCMessageTypeSetIdentityURLRequest IPCMessageType = 31
|
IPCMessageTypeSetIdentityURLRequest IPCMessageType = 31
|
||||||
|
IPCMessageTypeSetNotificationsURLRequest IPCMessageType = 34
|
||||||
|
|
||||||
IPCMessageTypeGetBiometricsKeyRequest IPCMessageType = 8
|
IPCMessageTypeGetBiometricsKeyRequest IPCMessageType = 8
|
||||||
IPCMessageTypeGetBiometricsKeyResponse IPCMessageType = 9
|
IPCMessageTypeGetBiometricsKeyResponse IPCMessageType = 9
|
||||||
|
|
@ -190,6 +191,13 @@ func (m IPCMessage) ParsedPayload() interface{} {
|
||||||
panic("Unmarshal: " + err.Error())
|
panic("Unmarshal: " + err.Error())
|
||||||
}
|
}
|
||||||
return req
|
return req
|
||||||
|
case IPCMessageTypeSetNotificationsURLRequest:
|
||||||
|
var req SetNotificationsURLRequest
|
||||||
|
err := json.Unmarshal(m.Payload, &req)
|
||||||
|
if err != nil {
|
||||||
|
panic("Unmarshal: " + err.Error())
|
||||||
|
}
|
||||||
|
return req
|
||||||
case IPCMessageGetLoginsResponse:
|
case IPCMessageGetLoginsResponse:
|
||||||
var res GetLoginsResponse
|
var res GetLoginsResponse
|
||||||
err := json.Unmarshal(m.Payload, &res)
|
err := json.Unmarshal(m.Payload, &res)
|
||||||
|
|
@ -298,6 +306,11 @@ func IPCMessageFromPayload(payload interface{}) (IPCMessage, error) {
|
||||||
Type: IPCMessageTypeSetIdentityURLRequest,
|
Type: IPCMessageTypeSetIdentityURLRequest,
|
||||||
Payload: jsonBytes,
|
Payload: jsonBytes,
|
||||||
}, nil
|
}, nil
|
||||||
|
case SetNotificationsURLRequest:
|
||||||
|
return IPCMessage{
|
||||||
|
Type: IPCMessageTypeSetNotificationsURLRequest,
|
||||||
|
Payload: jsonBytes,
|
||||||
|
}, nil
|
||||||
case GetLoginRequest:
|
case GetLoginRequest:
|
||||||
return IPCMessage{
|
return IPCMessage{
|
||||||
Type: IPCMessageGetLoginRequest,
|
Type: IPCMessageGetLoginRequest,
|
||||||
|
|
@ -481,6 +494,10 @@ type SetIdentityURLRequest struct {
|
||||||
Value string
|
Value string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SetNotificationsURLRequest struct {
|
||||||
|
Value string
|
||||||
|
}
|
||||||
|
|
||||||
type ListLoginsRequest struct {
|
type ListLoginsRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue