Implement configuration on notification url
This commit is contained in:
parent
ef5083cfb4
commit
9129c7113c
|
@ -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() {
|
||||
AgentActionsRegistry.Register(ipc.IPCMessageTypeSetIdentityURLRequest, handleSetIdentity)
|
||||
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{
|
||||
Use: "config",
|
||||
Short: "Manage the configuration",
|
||||
|
@ -83,4 +117,5 @@ func init() {
|
|||
rootCmd.AddCommand(configCmd)
|
||||
configCmd.AddCommand(setApiUrlCmd)
|
||||
configCmd.AddCommand(setIdentityURLCmd)
|
||||
configCmd.AddCommand(setNotificationsURLCmd)
|
||||
}
|
||||
|
|
21
ipc/ipc.go
21
ipc/ipc.go
|
@ -45,8 +45,9 @@ const (
|
|||
|
||||
IPCMessageTypeGetVaultPINStatusRequest IPCMessageType = 2
|
||||
|
||||
IPCMessageTypeSetAPIUrlRequest IPCMessageType = 30
|
||||
IPCMessageTypeSetIdentityURLRequest IPCMessageType = 31
|
||||
IPCMessageTypeSetAPIUrlRequest IPCMessageType = 30
|
||||
IPCMessageTypeSetIdentityURLRequest IPCMessageType = 31
|
||||
IPCMessageTypeSetNotificationsURLRequest IPCMessageType = 34
|
||||
|
||||
IPCMessageTypeGetBiometricsKeyRequest IPCMessageType = 8
|
||||
IPCMessageTypeGetBiometricsKeyResponse IPCMessageType = 9
|
||||
|
@ -190,6 +191,13 @@ func (m IPCMessage) ParsedPayload() interface{} {
|
|||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req
|
||||
case IPCMessageTypeSetNotificationsURLRequest:
|
||||
var req SetNotificationsURLRequest
|
||||
err := json.Unmarshal(m.Payload, &req)
|
||||
if err != nil {
|
||||
panic("Unmarshal: " + err.Error())
|
||||
}
|
||||
return req
|
||||
case IPCMessageGetLoginsResponse:
|
||||
var res GetLoginsResponse
|
||||
err := json.Unmarshal(m.Payload, &res)
|
||||
|
@ -298,6 +306,11 @@ func IPCMessageFromPayload(payload interface{}) (IPCMessage, error) {
|
|||
Type: IPCMessageTypeSetIdentityURLRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case SetNotificationsURLRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageTypeSetNotificationsURLRequest,
|
||||
Payload: jsonBytes,
|
||||
}, nil
|
||||
case GetLoginRequest:
|
||||
return IPCMessage{
|
||||
Type: IPCMessageGetLoginRequest,
|
||||
|
@ -481,6 +494,10 @@ type SetIdentityURLRequest struct {
|
|||
Value string
|
||||
}
|
||||
|
||||
type SetNotificationsURLRequest struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
type ListLoginsRequest struct {
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue