Skip to content

Commit

Permalink
Fix audit logs and config persistence for Cloud Teams (#1312)
Browse files Browse the repository at this point in the history
* Fix audit logs and config persistence for Cloud Teams
* Send additional audit metadata for getting channel name
  • Loading branch information
pkosiec authored Nov 20, 2023
1 parent 1924d4a commit a00cc0c
Show file tree
Hide file tree
Showing 15 changed files with 384 additions and 190 deletions.
25 changes: 13 additions & 12 deletions internal/audit/gql_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/hasura/go-graphql-client"
"github.com/sirupsen/logrus"

remoteapi "github.com/kubeshop/botkube/internal/remote"
gqlmodel "github.com/kubeshop/botkube/internal/remote/graphql"
)

var _ AuditReporter = (*GraphQLAuditReporter)(nil)
Expand Down Expand Up @@ -39,16 +39,17 @@ func (r *GraphQLAuditReporter) ReportExecutorAuditEvent(ctx context.Context, e E
} `graphql:"createAuditEvent(input: $input)"`
}
variables := map[string]interface{}{
"input": remoteapi.AuditEventCreateInput{
"input": gqlmodel.AuditEventCreateInput{
CreatedAt: e.CreatedAt,
PluginName: e.PluginName,
DeploymentID: r.gql.DeploymentID(),
Type: remoteapi.AuditEventTypeCommandExecuted,
CommandExecuted: &remoteapi.AuditEventCommandCreateInput{
PlatformUser: e.PlatformUser,
BotPlatform: e.BotPlatform,
Command: e.Command,
Channel: e.Channel,
Type: gqlmodel.AuditEventTypeCommandExecuted,
CommandExecuted: &gqlmodel.AuditEventCommandCreateInput{
PlatformUser: e.PlatformUser,
BotPlatform: e.BotPlatform,
Command: e.Command,
Channel: e.Channel,
AdditionalCreateContext: e.AdditionalCreateContext,
},
},
}
Expand All @@ -65,14 +66,14 @@ func (r *GraphQLAuditReporter) ReportSourceAuditEvent(ctx context.Context, e Sou
} `graphql:"createAuditEvent(input: $input)"`
}
variables := map[string]interface{}{
"input": remoteapi.AuditEventCreateInput{
"input": gqlmodel.AuditEventCreateInput{
CreatedAt: e.CreatedAt,
PluginName: e.PluginName,
DeploymentID: r.gql.DeploymentID(),
Type: remoteapi.AuditEventTypeSourceEventEmitted,
SourceEventEmitted: &remoteapi.AuditEventSourceCreateInput{
Type: gqlmodel.AuditEventTypeSourceEventEmitted,
SourceEventEmitted: &gqlmodel.AuditEventSourceCreateInput{
Event: e.Event,
Source: remoteapi.AuditEventSourceDetailsInput{
Source: &gqlmodel.AuditEventSourceDetailsInput{
Name: e.Source.Name,
DisplayName: e.Source.DisplayName,
},
Expand Down
15 changes: 8 additions & 7 deletions internal/audit/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/sirupsen/logrus"

remoteapi "github.com/kubeshop/botkube/internal/remote"
"github.com/kubeshop/botkube/internal/remote/graphql"
)

// AuditReporter defines interface for reporting audit events
Expand All @@ -16,12 +16,13 @@ type AuditReporter interface {

// ExecutorAuditEvent contains audit event data
type ExecutorAuditEvent struct {
CreatedAt string
PluginName string
PlatformUser string
BotPlatform *remoteapi.BotPlatform
Command string
Channel string
CreatedAt string
PluginName string
PlatformUser string
BotPlatform *graphql.BotPlatform
Command string
Channel string
AdditionalCreateContext map[string]interface{}
}

// SourceAuditEvent contains audit event data
Expand Down
119 changes: 0 additions & 119 deletions internal/remote/api.go

This file was deleted.

20 changes: 20 additions & 0 deletions internal/remote/graphql/connected_platforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,24 @@ type OrganizationConnectedPlatforms struct {
OrganizationID string `graphql:"-"`
Slacks []*SlackWorkspace `json:"slacks"`
Slack *SlackWorkspace `json:"slack"`

TeamsOrganizations []*TeamsOrganization `json:"teamsOrganizations"`
TeamsOrganization *TeamsOrganization `json:"teamsOrganization"`
}

type TeamsOrganization struct {
ID string `json:"id"`
TenantID string `json:"tenantId"`
ConsentGiven bool `json:"consentGiven"`
IsReConsentingRequired bool `json:"isReConsentingRequired"`

// All internal, ignored fields are removed
}

type TeamsOrganizationTeam struct {
ID string `json:"id"`
AADGroupID string `json:"aadGroupId"`
DefaultConversationID string `json:"defaultConversationId"`

// All internal, ignored fields are removed
}
Loading

0 comments on commit a00cc0c

Please sign in to comment.