Allow sudo to send structured SSEs
This commit is contained in:
parent
be1e49e524
commit
6fb964852f
4 changed files with 53 additions and 10 deletions
|
|
@ -218,16 +218,36 @@
|
|||
value="{{ .Organization.ID }}"
|
||||
/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="type" class="form-label">Type</label>
|
||||
<select class="form-select" id="type" name="type">
|
||||
<option value="created">Created</option>
|
||||
<option value="deleted">Deleted</option>
|
||||
<option value="heartbeat">Heartbeat</option>
|
||||
<option value="sudo">Sudo</option>
|
||||
<option value="updated">Updated</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="mb-3">
|
||||
<label for="content" class="form-label">Content</label>
|
||||
<label for="resource" class="form-label">Resource</label>
|
||||
<input
|
||||
class="form-control"
|
||||
id="content"
|
||||
name="content"
|
||||
placeholder="Message content"
|
||||
id="resource"
|
||||
name="resource"
|
||||
type="text"
|
||||
value="rmo:nuisance"
|
||||
/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="uriPath" class="form-label">URI path</label>
|
||||
<input
|
||||
class="form-control"
|
||||
id="uri-path"
|
||||
name="uriPath"
|
||||
type="text"
|
||||
value="/report/abcd-1234"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package platform
|
|||
import (
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/event"
|
||||
)
|
||||
|
||||
|
|
@ -14,13 +15,14 @@ const EventTypeHeartbeat = event.EventTypeHeartbeat
|
|||
func SetEventChannel(chan_events chan<- Envelope) {
|
||||
event.SetEventChannel(chan_events)
|
||||
}
|
||||
func SudoEvent(org_id int32, content string) {
|
||||
func SudoEvent(org_id int32, resource, type_, uri_path string) {
|
||||
event_type := event.EventTypeFromString(type_)
|
||||
go event.Send(event.Envelope{
|
||||
Event: Event{
|
||||
Resource: "sudo",
|
||||
Resource: resource,
|
||||
Time: time.Now(),
|
||||
Type: event.EventTypeSudo,
|
||||
URI: content,
|
||||
Type: event_type,
|
||||
URI: config.MakeURLNidus(uri_path),
|
||||
},
|
||||
OrganizationID: org_id,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ const (
|
|||
EventTypeDeleted
|
||||
EventTypeHeartbeat
|
||||
EventTypeSudo
|
||||
EventTypeUnknown
|
||||
EventTypeUpdated
|
||||
)
|
||||
|
||||
|
|
@ -43,11 +44,29 @@ func (et EventType) String() string {
|
|||
return "heartbeat"
|
||||
case EventTypeSudo:
|
||||
return "sudo"
|
||||
case EventTypeUnknown:
|
||||
return "unknown"
|
||||
case EventTypeUpdated:
|
||||
return "updated"
|
||||
}
|
||||
return "unknown"
|
||||
}
|
||||
func EventTypeFromString(s string) EventType {
|
||||
switch s {
|
||||
case "created":
|
||||
return EventTypeCreated
|
||||
case "deleted":
|
||||
return EventTypeDeleted
|
||||
case "heartbeat":
|
||||
return EventTypeHeartbeat
|
||||
case "sudo":
|
||||
return EventTypeSudo
|
||||
case "updated":
|
||||
return EventTypeUpdated
|
||||
default:
|
||||
return EventTypeUnknown
|
||||
}
|
||||
}
|
||||
|
||||
type ResourceType int
|
||||
|
||||
|
|
|
|||
|
|
@ -86,8 +86,10 @@ func postSudoSMS(ctx context.Context, r *http.Request, u platform.User, sms Form
|
|||
}
|
||||
|
||||
type FormSSE struct {
|
||||
Content string `schema:"content"`
|
||||
OrganizationID int32 `schema:"organizationID"`
|
||||
Resource string `schema:"resource"`
|
||||
Type string `schema:"type"`
|
||||
URIPath string `schema:"uriPath"`
|
||||
}
|
||||
|
||||
func postSudoSSE(ctx context.Context, r *http.Request, u platform.User, sse FormSSE) (string, *nhttp.ErrorWithStatus) {
|
||||
|
|
@ -97,6 +99,6 @@ func postSudoSSE(ctx context.Context, r *http.Request, u platform.User, sse Form
|
|||
Status: http.StatusForbidden,
|
||||
}
|
||||
}
|
||||
platform.SudoEvent(sse.OrganizationID, sse.Content)
|
||||
platform.SudoEvent(sse.OrganizationID, sse.Resource, sse.Type, sse.URIPath)
|
||||
return "/sudo", nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue