Skip to content

Commit

Permalink
feat(authN): Add to all DB entries 'Modified_by'... (#81) (#230)
Browse files Browse the repository at this point in the history
* feat(authN): Add to all DB entries 'Modified_by'... (#81)

Move 'CreatedAt', 'DeletedAt' and 'UpdatedAt' to common
entity.Info struct
Add 'CreatedBy' and 'UpdatedBy' to common entity.Info struct
Add metadata for user
Add tests
Add metadata for activity, IssueVariant and IssueRepository
Add metadata for component
Add metadata for componentInstance, componentVersion
Add metadata for evidence
Issue Metadata rename to IssueMetadata, because now metadata
means data related to creation time, creation user, update time
and update user
Add Metadata for Issue
Add metadata for IssueMatch
Add Metadata for IssueMatchChange, Service and SupportGroup
Refactor and review fixes
Test foreign key
Add Foreign Key
changed issueMetadata and serviceMetadata to objectMetadata

* chore: bumping for re-trigger

* Automatic application of license header

---------

Co-authored-by: David Rochow <[email protected]>
Co-authored-by: License Bot <[email protected]>
  • Loading branch information
3 people authored Nov 18, 2024
1 parent 1dcbcf7 commit 04a4f2f
Show file tree
Hide file tree
Showing 113 changed files with 1,510 additions and 488 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ For a detailed understanding of Heureka's architecture and design, refer to the
- [High-Level Architecture Diagram](https://github.com/cloudoperators/heureka/blob/main/docs/product_design_documentation.md#high-level-features): This provides a visual representation of the overall system architecture.
- [High-Level Features](https://github.com/cloudoperators/heureka/blob/main/docs/product_design_documentation.md#high-level-features): A high-level overview of Heureka's functionalities.


## Requirements and Setup

The application can be configured using environment variables. These variables are stored in a `.env` file at the root of the project.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/samber/lo v1.47.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
github.com/vektah/gqlparser/v2 v2.5.19
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
)
Expand Down Expand Up @@ -85,7 +86,6 @@ require (
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/urfave/cli/v2 v2.27.5 // indirect
github.com/vektah/gqlparser/v2 v2.5.19 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion internal/api/graphql/graph/baseResolver/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ func GetListOptions(requestedFields []string) *entity.ListOptions {
return &entity.ListOptions{
ShowTotalCount: lo.Contains(requestedFields, "totalCount"),
ShowPageInfo: lo.Contains(requestedFields, "pageInfo"),
IncludeAggregations: lo.Contains(requestedFields, "edges.node.metadata"),
IncludeAggregations: lo.Contains(requestedFields, "edges.node.objectMetadata"),
}
}
89 changes: 53 additions & 36 deletions internal/api/graphql/graph/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ import (
)

// add custom models here
func getModelMetadata(em entity.Metadata) *Metadata {
createdAt := em.CreatedAt.String()
deletedAt := em.DeletedAt.String()
updatedAt := em.UpdatedAt.String()
return &Metadata{
CreatedAt: util.Ptr(createdAt),
CreatedBy: util.Ptr(fmt.Sprintf("%d", em.CreatedBy)),
DeletedAt: util.Ptr(deletedAt),
UpdatedAt: util.Ptr(updatedAt),
UpdatedBy: util.Ptr(fmt.Sprintf("%d", em.UpdatedBy)),
}
}

var AllSeverityValuesOrdered = []SeverityValues{
SeverityValuesCritical,
Expand Down Expand Up @@ -160,17 +172,18 @@ func NewIssue(issue *entity.Issue) Issue {
Type: &issueType,
Description: &issue.Description,
LastModified: &lastModified,
Metadata: getModelMetadata(issue.Metadata),
}
}

func NewIssueWithAggregations(issue *entity.IssueResult) Issue {
lastModified := issue.Issue.UpdatedAt.String()
issueType := IssueTypes(issue.Type.String())

var metadata IssueMetadata
var objectMetadata IssueMetadata

if issue.IssueAggregations != nil {
metadata = IssueMetadata{
objectMetadata = IssueMetadata{
ServiceCount: int(issue.IssueAggregations.AffectedServices),
ActivityCount: int(issue.IssueAggregations.Activities),
IssueMatchCount: int(issue.IssueAggregations.IssueMatches),
Expand All @@ -182,11 +195,13 @@ func NewIssueWithAggregations(issue *entity.IssueResult) Issue {
}

return Issue{
ID: fmt.Sprintf("%d", issue.Issue.Id),
PrimaryName: &issue.Issue.PrimaryName,
Type: &issueType,
LastModified: &lastModified,
Metadata: &metadata,
ID: fmt.Sprintf("%d", issue.Issue.Id),
PrimaryName: &issue.Issue.PrimaryName,
Type: &issueType,
Description: &issue.Issue.Description,
LastModified: &lastModified,
ObjectMetadata: &objectMetadata,
Metadata: getModelMetadata(issue.Issue.Metadata),
}
}

Expand Down Expand Up @@ -218,6 +233,7 @@ func NewIssueMatch(im *entity.IssueMatch) IssueMatch {
IssueID: util.Ptr(fmt.Sprintf("%d", im.IssueId)),
ComponentInstanceID: util.Ptr(fmt.Sprintf("%d", im.ComponentInstanceId)),
UserID: util.Ptr(fmt.Sprintf("%d", im.UserId)),
Metadata: getModelMetadata(im.Metadata),
}
}

Expand All @@ -240,7 +256,7 @@ func NewIssueMatchEntity(im *IssueMatchInput) entity.IssueMatch {
IssueId: issueId,
ComponentInstanceId: ciId,
UserId: userId,
CreatedAt: createdAt,
Metadata: entity.Metadata{CreatedAt: createdAt},
}
}

Expand All @@ -253,6 +269,7 @@ func NewIssueMatchChange(imc *entity.IssueMatchChange) IssueMatchChange {
IssueMatch: nil,
ActivityID: util.Ptr(fmt.Sprintf("%d", imc.ActivityId)),
Activity: nil,
Metadata: getModelMetadata(imc.Metadata),
}
}

Expand All @@ -268,16 +285,13 @@ func NewIssueMatchChangeEntity(imc *IssueMatchChangeInput) entity.IssueMatchChan
}

func NewIssueRepository(repo *entity.IssueRepository) IssueRepository {
createdAt := repo.BaseIssueRepository.CreatedAt.String()
updatedAt := repo.BaseIssueRepository.UpdatedAt.String()
return IssueRepository{
ID: fmt.Sprintf("%d", repo.Id),
Name: &repo.Name,
URL: &repo.Url,
Services: nil,
IssueVariants: nil,
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
Metadata: getModelMetadata(repo.BaseIssueRepository.Metadata),
}
}

Expand All @@ -295,8 +309,6 @@ func NewIssueVariant(issueVariant *entity.IssueVariant) IssueVariant {
if issueVariant.IssueRepository != nil {
repo = NewIssueRepository(issueVariant.IssueRepository)
}
createdAt := issueVariant.CreatedAt.String()
updatedAt := issueVariant.UpdatedAt.String()
return IssueVariant{
ID: fmt.Sprintf("%d", issueVariant.Id),
SecondaryName: &issueVariant.SecondaryName,
Expand All @@ -305,20 +317,16 @@ func NewIssueVariant(issueVariant *entity.IssueVariant) IssueVariant {
IssueID: util.Ptr(fmt.Sprintf("%d", issueVariant.IssueId)),
IssueRepositoryID: util.Ptr(fmt.Sprintf("%d", issueVariant.IssueRepositoryId)),
IssueRepository: &repo,
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
Metadata: getModelMetadata(issueVariant.Metadata),
}
}

func NewIssueVariantEdge(issueVariant *entity.IssueVariant) IssueVariantEdge {
iv := NewIssueVariant(issueVariant)
edgeCreationDate := issueVariant.CreatedAt.String()
edgeUpdateDate := issueVariant.UpdatedAt.String()
issueVariantEdge := IssueVariantEdge{
Node: &iv,
Cursor: &iv.ID,
CreatedAt: &edgeCreationDate,
UpdatedAt: &edgeUpdateDate,
Node: &iv,
Cursor: &iv.ID,
Metadata: getModelMetadata(issueVariant.Metadata),
}
return issueVariantEdge
}
Expand All @@ -341,6 +349,7 @@ func NewUser(user *entity.User) User {
UniqueUserID: &user.UniqueUserID,
Name: &user.Name,
Type: int(user.Type),
Metadata: getModelMetadata(user.Metadata),
}
}

Expand All @@ -354,25 +363,27 @@ func NewUserEntity(user *UserInput) entity.User {

func NewService(s *entity.Service) Service {
return Service{
ID: fmt.Sprintf("%d", s.Id),
Ccrn: &s.CCRN,
ID: fmt.Sprintf("%d", s.Id),
Ccrn: &s.CCRN,
Metadata: getModelMetadata(s.BaseService.Metadata),
}
}

func NewServiceWithAggregations(service *entity.ServiceResult) Service {
var metadata ServiceMetadata
var objectMetadata ServiceMetadata

if service.ServiceAggregations != nil {
metadata = ServiceMetadata{
objectMetadata = ServiceMetadata{
IssueMatchCount: int(service.ServiceAggregations.IssueMatches),
ComponentInstanceCount: int(service.ServiceAggregations.ComponentInstances),
}
}

return Service{
ID: fmt.Sprintf("%d", service.Id),
Ccrn: &service.CCRN,
Metadata: &metadata,
ID: fmt.Sprintf("%d", service.Id),
Ccrn: &service.CCRN,
ObjectMetadata: &objectMetadata,
Metadata: getModelMetadata(service.BaseService.Metadata),
}
}

Expand All @@ -386,8 +397,9 @@ func NewServiceEntity(service *ServiceInput) entity.Service {

func NewSupportGroup(supportGroup *entity.SupportGroup) SupportGroup {
return SupportGroup{
ID: fmt.Sprintf("%d", supportGroup.Id),
Ccrn: &supportGroup.CCRN,
ID: fmt.Sprintf("%d", supportGroup.Id),
Ccrn: &supportGroup.CCRN,
Metadata: getModelMetadata(supportGroup.Metadata),
}
}

Expand All @@ -400,8 +412,9 @@ func NewSupportGroupEntity(supportGroup *SupportGroupInput) entity.SupportGroup
func NewActivity(activity *entity.Activity) Activity {
status := ActivityStatusValues(activity.Status.String())
return Activity{
ID: fmt.Sprintf("%d", activity.Id),
Status: &status,
ID: fmt.Sprintf("%d", activity.Id),
Status: &status,
Metadata: getModelMetadata(activity.Metadata),
}
}

Expand Down Expand Up @@ -429,6 +442,7 @@ func NewEvidence(evidence *entity.Evidence) Evidence {
Vector: severity.Cvss.Vector,
Type: &t,
RaaEnd: &raaEnd,
Metadata: getModelMetadata(evidence.Metadata),
}
}

Expand All @@ -451,9 +465,10 @@ func NewEvidenceEntity(evidence *EvidenceInput) entity.Evidence {
func NewComponent(component *entity.Component) Component {
componentType, _ := ComponentTypeValue(component.Type)
return Component{
ID: fmt.Sprintf("%d", component.Id),
Ccrn: &component.CCRN,
Type: &componentType,
ID: fmt.Sprintf("%d", component.Id),
Ccrn: &component.CCRN,
Type: &componentType,
Metadata: getModelMetadata(component.Metadata),
}
}

Expand All @@ -473,6 +488,7 @@ func NewComponentVersion(componentVersion *entity.ComponentVersion) ComponentVer
ID: fmt.Sprintf("%d", componentVersion.Id),
Version: &componentVersion.Version,
ComponentID: util.Ptr(fmt.Sprintf("%d", componentVersion.ComponentId)),
Metadata: getModelMetadata(componentVersion.Metadata),
}
}

Expand All @@ -495,6 +511,7 @@ func NewComponentInstance(componentInstance *entity.ComponentInstance) Component
Count: &count,
ComponentVersionID: util.Ptr(fmt.Sprintf("%d", componentInstance.ComponentVersionId)),
ServiceID: util.Ptr(fmt.Sprintf("%d", componentInstance.ServiceId)),
Metadata: getModelMetadata(componentInstance.Metadata),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ query ($filter: ComponentInstanceFilter, $first: Int, $after: String) {
id
ccrn
}
createdAt
updatedAt
metadata {
created_at
updated_at
}
issueMatches {
totalCount
edges {
Expand Down Expand Up @@ -57,4 +59,4 @@ query ($filter: ComponentInstanceFilter, $first: Int, $after: String) {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ mutation ($input: IssueInput!) {
description
type
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,22 @@ query ($filter: IssueFilter, $first: Int, $after: String) {
id
name
url
metadata {
created_at
updated_at
}
}
issueId
metadata {
created_at
updated_at
}
issueId
}
cursor
metadata {
created_at
updated_at
}
cursor
created_at
updated_at
}
pageInfo {
hasNextPage
Expand All @@ -61,8 +67,10 @@ query ($filter: IssueFilter, $first: Int, $after: String) {
componentInstance {
id
count
createdAt
updatedAt
metadata {
created_at
updated_at
}
ccrn
}
}
Expand All @@ -73,7 +81,7 @@ query ($filter: IssueFilter, $first: Int, $after: String) {
nextPageAfter
}
}
metadata {
objectMetadata {
serviceCount
activityCount
issueMatchCount
Expand All @@ -98,4 +106,4 @@ query ($filter: IssueFilter, $first: Int, $after: String) {
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
# SPDX-License-Identifier: Apache-2.0

query ($filter: IssueFilter, $first: Int, $after: String) {
Issues (
filter: $filter,
first: $first,
after: $after
) {
totalCount
edges {
node {
id
primaryName
type
description
metadata {
created_at
created_by
deleted_at
updated_at
updated_by
}
}
cursor
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ query ($filter: IssueFilter, $first: Int, $after: String) {
node {
id
lastModified
metadata {
objectMetadata {
serviceCount
activityCount
issueMatchCount
Expand Down
Loading

0 comments on commit 04a4f2f

Please sign in to comment.