Skip to content

Commit

Permalink
MG-2358 - Add Domain to Events (#2510)
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: Felix Gateru <[email protected]>
Co-authored-by: Felix Gateru <[email protected]>
  • Loading branch information
nyagamunene and felixgateru authored Jan 16, 2025
1 parent d02d63d commit fdea1a7
Show file tree
Hide file tree
Showing 26 changed files with 659 additions and 331 deletions.
4 changes: 2 additions & 2 deletions apidocs/openapi/journal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ components:

entity_type:
name: entityType
description: Type of entity, e.g. user, group, client, etc.entityType
description: Type of entity, e.g. group, client, channel.
in: path
schema:
type: string
Expand All @@ -220,7 +220,7 @@ components:

id:
name: id
description: Unique identifier for an entity, e.g. group, channel or thing. Used together with entity_type.
description: Unique identifier for an entity, e.g. group, channel or client. Used together with entity_type.
in: path
schema:
type: string
Expand Down
117 changes: 79 additions & 38 deletions channels/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/absmach/supermq/channels"
"github.com/absmach/supermq/pkg/authn"
"github.com/absmach/supermq/pkg/connections"
"github.com/absmach/supermq/pkg/events"
"github.com/absmach/supermq/pkg/roles"
Expand Down Expand Up @@ -40,6 +41,7 @@ var (
type createChannelEvent struct {
channels.Channel
rolesProvisioned []roles.RoleProvision
authn.Session
}

func (cce createChannelEvent) Encode() (map[string]interface{}, error) {
Expand All @@ -49,6 +51,10 @@ func (cce createChannelEvent) Encode() (map[string]interface{}, error) {
"roles_provisioned": cce.rolesProvisioned,
"status": cce.Status.String(),
"created_at": cce.CreatedAt,
"domain": cce.DomainID,
"user_id": cce.UserID,
"token_type": cce.Type.String(),
"super_admin": cce.SuperAdmin,
}

if cce.Name != "" {
Expand All @@ -57,9 +63,6 @@ func (cce createChannelEvent) Encode() (map[string]interface{}, error) {
if len(cce.Tags) > 0 {
val["tags"] = cce.Tags
}
if cce.Domain != "" {
val["domain"] = cce.Domain
}
if cce.Metadata != nil {
val["metadata"] = cce.Metadata
}
Expand All @@ -70,13 +73,18 @@ func (cce createChannelEvent) Encode() (map[string]interface{}, error) {
type updateChannelEvent struct {
channels.Channel
operation string
authn.Session
}

func (uce updateChannelEvent) Encode() (map[string]interface{}, error) {
val := map[string]interface{}{
"operation": channelUpdate,
"updated_at": uce.UpdatedAt,
"updated_by": uce.UpdatedBy,
"operation": channelUpdate,
"updated_at": uce.UpdatedAt,
"updated_by": uce.UpdatedBy,
"domain": uce.DomainID,
"user_id": uce.UserID,
"token_type": uce.Type.String(),
"super_admin": uce.SuperAdmin,
}
if uce.operation != "" {
val["operation"] = channelUpdate + "_" + uce.operation
Expand All @@ -91,9 +99,6 @@ func (uce updateChannelEvent) Encode() (map[string]interface{}, error) {
if len(uce.Tags) > 0 {
val["tags"] = uce.Tags
}
if uce.Domain != "" {
val["domain"] = uce.Domain
}
if uce.Metadata != nil {
val["metadata"] = uce.Metadata
}
Expand All @@ -112,26 +117,36 @@ type changeStatusChannelEvent struct {
status string
updatedAt time.Time
updatedBy string
authn.Session
}

func (rce changeStatusChannelEvent) Encode() (map[string]interface{}, error) {
return map[string]interface{}{
"operation": channelChangeStatus,
"id": rce.id,
"status": rce.status,
"updated_at": rce.updatedAt,
"updated_by": rce.updatedBy,
"operation": channelChangeStatus,
"id": rce.id,
"status": rce.status,
"updated_at": rce.updatedAt,
"updated_by": rce.updatedBy,
"domain": rce.DomainID,
"user_id": rce.UserID,
"token_type": rce.Type.String(),
"super_admin": rce.SuperAdmin,
}, nil
}

type viewChannelEvent struct {
channels.Channel
authn.Session
}

func (vce viewChannelEvent) Encode() (map[string]interface{}, error) {
val := map[string]interface{}{
"operation": channelView,
"id": vce.ID,
"operation": channelView,
"id": vce.ID,
"domain": vce.DomainID,
"user_id": vce.UserID,
"token_type": vce.Type.String(),
"super_admin": vce.SuperAdmin,
}

if vce.Name != "" {
Expand All @@ -140,9 +155,6 @@ func (vce viewChannelEvent) Encode() (map[string]interface{}, error) {
if len(vce.Tags) > 0 {
val["tags"] = vce.Tags
}
if vce.Domain != "" {
val["domain"] = vce.Domain
}
if vce.Metadata != nil {
val["metadata"] = vce.Metadata
}
Expand All @@ -164,14 +176,19 @@ func (vce viewChannelEvent) Encode() (map[string]interface{}, error) {

type listChannelEvent struct {
channels.PageMetadata
authn.Session
}

func (lce listChannelEvent) Encode() (map[string]interface{}, error) {
val := map[string]interface{}{
"operation": channelList,
"total": lce.Total,
"offset": lce.Offset,
"limit": lce.Limit,
"operation": channelList,
"total": lce.Total,
"offset": lce.Offset,
"limit": lce.Limit,
"domain": lce.DomainID,
"user_id": lce.UserID,
"token_type": lce.Type.String(),
"super_admin": lce.SuperAdmin,
}

if lce.Name != "" {
Expand All @@ -186,9 +203,6 @@ func (lce listChannelEvent) Encode() (map[string]interface{}, error) {
if lce.Metadata != nil {
val["metadata"] = lce.Metadata
}
if lce.Domain != "" {
val["domain"] = lce.Domain
}
if lce.Tag != "" {
val["tag"] = lce.Tag
}
Expand All @@ -208,15 +222,20 @@ func (lce listChannelEvent) Encode() (map[string]interface{}, error) {
type listChannelByClientEvent struct {
clientID string
channels.PageMetadata
authn.Session
}

func (lcte listChannelByClientEvent) Encode() (map[string]interface{}, error) {
val := map[string]interface{}{
"operation": channelList,
"client_id": lcte.clientID,
"total": lcte.Total,
"offset": lcte.Offset,
"limit": lcte.Limit,
"operation": channelList,
"client_id": lcte.clientID,
"total": lcte.Total,
"offset": lcte.Offset,
"limit": lcte.Limit,
"domain": lcte.DomainID,
"user_id": lcte.UserID,
"token_type": lcte.Type.String(),
"super_admin": lcte.SuperAdmin,
}

if lcte.Name != "" {
Expand All @@ -231,9 +250,6 @@ func (lcte listChannelByClientEvent) Encode() (map[string]interface{}, error) {
if lcte.Metadata != nil {
val["metadata"] = lcte.Metadata
}
if lcte.Domain != "" {
val["domain"] = lcte.Domain
}
if lcte.Tag != "" {
val["tag"] = lcte.Tag
}
Expand All @@ -252,19 +268,25 @@ func (lcte listChannelByClientEvent) Encode() (map[string]interface{}, error) {

type removeChannelEvent struct {
id string
authn.Session
}

func (dce removeChannelEvent) Encode() (map[string]interface{}, error) {
return map[string]interface{}{
"operation": channelRemove,
"id": dce.id,
"operation": channelRemove,
"id": dce.id,
"domain": dce.DomainID,
"user_id": dce.UserID,
"token_type": dce.Type.String(),
"super_admin": dce.SuperAdmin,
}, nil
}

type connectEvent struct {
chIDs []string
thIDs []string
types []connections.ConnType
authn.Session
}

func (ce connectEvent) Encode() (map[string]interface{}, error) {
Expand All @@ -273,13 +295,18 @@ func (ce connectEvent) Encode() (map[string]interface{}, error) {
"client_ids": ce.thIDs,
"channel_ids": ce.chIDs,
"types": ce.types,
"domain": ce.DomainID,
"user_id": ce.UserID,
"token_type": ce.Type.String(),
"super_admin": ce.SuperAdmin,
}, nil
}

type disconnectEvent struct {
chIDs []string
thIDs []string
types []connections.ConnType
authn.Session
}

func (de disconnectEvent) Encode() (map[string]interface{}, error) {
Expand All @@ -288,29 +315,43 @@ func (de disconnectEvent) Encode() (map[string]interface{}, error) {
"client_ids": de.thIDs,
"channel_ids": de.chIDs,
"types": de.types,
"domain": de.DomainID,
"user_id": de.UserID,
"token_type": de.Type.String(),
"super_admin": de.SuperAdmin,
}, nil
}

type setParentGroupEvent struct {
id string
parentGroupID string
authn.Session
}

func (spge setParentGroupEvent) Encode() (map[string]interface{}, error) {
return map[string]interface{}{
"operation": channelSetParent,
"id": spge.id,
"parent_group_id": spge.parentGroupID,
"domain": spge.DomainID,
"user_id": spge.UserID,
"token_type": spge.Type.String(),
"super_admin": spge.SuperAdmin,
}, nil
}

type removeParentGroupEvent struct {
id string
authn.Session
}

func (rpge removeParentGroupEvent) Encode() (map[string]interface{}, error) {
return map[string]interface{}{
"operation": channelRemoveParent,
"id": rpge.id,
"operation": channelRemoveParent,
"id": rpge.id,
"domain": rpge.DomainID,
"user_id": rpge.UserID,
"token_type": rpge.Type.String(),
"super_admin": rpge.SuperAdmin,
}, nil
}
Loading

0 comments on commit fdea1a7

Please sign in to comment.