-
Notifications
You must be signed in to change notification settings - Fork 295
refactor(OG): Update schema_rel_finding db methods to schema_finding #2405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
mistahj67
wants to merge
2
commits into
refactor-rel-findings-to-findings
from
refactor-rel-findings-to-findings-2
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -59,10 +59,11 @@ type OpenGraphSchema interface { | |||||
| GetEnvironments(ctx context.Context) ([]model.SchemaEnvironment, error) | ||||||
| DeleteEnvironment(ctx context.Context, environmentId int32) error | ||||||
|
|
||||||
| CreateSchemaRelationshipFinding(ctx context.Context, extensionId int32, relationshipKindId int32, environmentId int32, name string, displayName string) (model.SchemaRelationshipFinding, error) | ||||||
| GetSchemaRelationshipFindingById(ctx context.Context, findingId int32) (model.SchemaRelationshipFinding, error) | ||||||
| GetSchemaRelationshipFindingByName(ctx context.Context, name string) (model.SchemaRelationshipFinding, error) | ||||||
| DeleteSchemaRelationshipFinding(ctx context.Context, findingId int32) error | ||||||
| CreateSchemaFinding(ctx context.Context, findingType model.SchemaFindingType, extensionId, kindId, environmentId int32, name, displayName string) (model.SchemaFinding, error) | ||||||
| GetSchemaFindingsBySchemaExtensionId(ctx context.Context, extensionId int32) ([]model.SchemaFinding, error) | ||||||
| GetSchemaFindingById(ctx context.Context, findingId int32) (model.SchemaFinding, error) | ||||||
| GetSchemaFindingByName(ctx context.Context, name string) (model.SchemaFinding, error) | ||||||
| DeleteSchemaFinding(ctx context.Context, findingId int32) error | ||||||
|
|
||||||
| CreateRemediation(ctx context.Context, findingId int32, shortDescription string, longDescription string, shortRemediation string, longRemediation string) (model.Remediation, error) | ||||||
| GetRemediationByFindingId(ctx context.Context, findingId int32) (model.Remediation, error) | ||||||
|
|
@@ -763,61 +764,61 @@ func (s *BloodhoundDB) DeleteEnvironment(ctx context.Context, environmentId int3 | |||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| // CreateSchemaRelationshipFinding - creates a new schema relationship finding. | ||||||
| func (s *BloodhoundDB) CreateSchemaRelationshipFinding(ctx context.Context, extensionId int32, relationshipKindId int32, environmentId int32, name string, displayName string) (model.SchemaRelationshipFinding, error) { | ||||||
| var finding model.SchemaRelationshipFinding | ||||||
| // CreateSchemaFinding - creates a new schema relationship finding. | ||||||
| func (s *BloodhoundDB) CreateSchemaFinding(ctx context.Context, findingType model.SchemaFindingType, extensionId, kindId, environmentId int32, name, displayName string) (model.SchemaFinding, error) { | ||||||
| var finding model.SchemaFinding | ||||||
|
|
||||||
| if result := s.db.WithContext(ctx).Raw(fmt.Sprintf(` | ||||||
| INSERT INTO %s (schema_extension_id, relationship_kind_id, environment_id, name, display_name, created_at) | ||||||
| VALUES (?, ?, ?, ?, ?, NOW()) | ||||||
| RETURNING id, schema_extension_id, relationship_kind_id, environment_id, name, display_name, created_at`, | ||||||
| INSERT INTO %s (type, schema_extension_id, kind_id, environment_id, name, display_name, created_at) | ||||||
| VALUES (?, ?, ?, ?, ?, ?, NOW()) | ||||||
| RETURNING id, schema_extension_id, kind_id, environment_id, name, display_name, created_at`, | ||||||
| finding.TableName()), | ||||||
| extensionId, relationshipKindId, environmentId, name, displayName).Scan(&finding); result.Error != nil { | ||||||
| findingType, extensionId, kindId, environmentId, name, displayName).Scan(&finding); result.Error != nil { | ||||||
| if strings.Contains(result.Error.Error(), DuplicateKeyValueErrorString) { | ||||||
| return model.SchemaRelationshipFinding{}, fmt.Errorf("%w: %s", model.ErrDuplicateSchemaRelationshipFindingName, name) | ||||||
| return model.SchemaFinding{}, fmt.Errorf("%w: %s", model.ErrDuplicateSchemaFindingName, name) | ||||||
| } | ||||||
| return model.SchemaRelationshipFinding{}, CheckError(result) | ||||||
| return model.SchemaFinding{}, CheckError(result) | ||||||
| } | ||||||
| return finding, nil | ||||||
| } | ||||||
|
|
||||||
| // GetSchemaRelationshipFindingById - retrieves a schema relationship finding by id. | ||||||
| func (s *BloodhoundDB) GetSchemaRelationshipFindingById(ctx context.Context, findingId int32) (model.SchemaRelationshipFinding, error) { | ||||||
| var finding model.SchemaRelationshipFinding | ||||||
| // GetSchemaFindingById - retrieves a schema relationship finding by id. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| func (s *BloodhoundDB) GetSchemaFindingById(ctx context.Context, findingId int32) (model.SchemaFinding, error) { | ||||||
| var finding model.SchemaFinding | ||||||
|
|
||||||
| if result := s.db.WithContext(ctx).Raw(fmt.Sprintf(` | ||||||
| SELECT id, schema_extension_id, relationship_kind_id, environment_id, name, display_name, created_at | ||||||
| SELECT id, type, schema_extension_id, kind_id, environment_id, name, display_name, created_at | ||||||
| FROM %s WHERE id = ?`, | ||||||
| finding.TableName()), | ||||||
| findingId).Scan(&finding); result.Error != nil { | ||||||
| return model.SchemaRelationshipFinding{}, CheckError(result) | ||||||
| return model.SchemaFinding{}, CheckError(result) | ||||||
| } else if result.RowsAffected == 0 { | ||||||
| return model.SchemaRelationshipFinding{}, ErrNotFound | ||||||
| return model.SchemaFinding{}, ErrNotFound | ||||||
| } | ||||||
|
|
||||||
| return finding, nil | ||||||
| } | ||||||
|
|
||||||
| // GetSchemaRelationshipFindingByName - retrieves a schema relationship finding by finding name. | ||||||
| func (s *BloodhoundDB) GetSchemaRelationshipFindingByName(ctx context.Context, name string) (model.SchemaRelationshipFinding, error) { | ||||||
| var finding model.SchemaRelationshipFinding | ||||||
| // GetSchemaFindingByName - retrieves a schema relationship finding by finding name. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| func (s *BloodhoundDB) GetSchemaFindingByName(ctx context.Context, name string) (model.SchemaFinding, error) { | ||||||
| var finding model.SchemaFinding | ||||||
|
|
||||||
| if result := s.db.WithContext(ctx).Raw(fmt.Sprintf(` | ||||||
| SELECT id, schema_extension_id, relationship_kind_id, environment_id, name, display_name, created_at | ||||||
| SELECT id, type, schema_extension_id, kind_id, environment_id, name, display_name, created_at | ||||||
| FROM %s WHERE name = ?`, | ||||||
| finding.TableName()), | ||||||
| name).Scan(&finding); result.Error != nil { | ||||||
| return model.SchemaRelationshipFinding{}, CheckError(result) | ||||||
| return model.SchemaFinding{}, CheckError(result) | ||||||
| } else if result.RowsAffected == 0 { | ||||||
| return model.SchemaRelationshipFinding{}, ErrNotFound | ||||||
| return model.SchemaFinding{}, ErrNotFound | ||||||
| } | ||||||
|
|
||||||
| return finding, nil | ||||||
| } | ||||||
|
|
||||||
| // DeleteSchemaRelationshipFinding - deletes a schema relationship finding by id. | ||||||
| func (s *BloodhoundDB) DeleteSchemaRelationshipFinding(ctx context.Context, findingId int32) error { | ||||||
| var finding model.SchemaRelationshipFinding | ||||||
| // DeleteSchemaFinding - deletes a schema relationship finding by id. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| func (s *BloodhoundDB) DeleteSchemaFinding(ctx context.Context, findingId int32) error { | ||||||
| var finding model.SchemaFinding | ||||||
|
|
||||||
| if result := s.db.WithContext(ctx).Exec(fmt.Sprintf(`DELETE FROM %s WHERE id = ?`, finding.TableName()), findingId); result.Error != nil { | ||||||
| return CheckError(result) | ||||||
|
|
@@ -828,12 +829,13 @@ func (s *BloodhoundDB) DeleteSchemaRelationshipFinding(ctx context.Context, find | |||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| // GetSchemaRelationshipFindingsBySchemaExtensionId - returns all findings by extension id. | ||||||
| func (s *BloodhoundDB) GetSchemaRelationshipFindingsBySchemaExtensionId(ctx context.Context, extensionId int32) ([]model.SchemaRelationshipFinding, error) { | ||||||
| var findings = make([]model.SchemaRelationshipFinding, 0) | ||||||
| // GetSchemaFindingsBySchemaExtensionId - returns all findings by extension id. | ||||||
| func (s *BloodhoundDB) GetSchemaFindingsBySchemaExtensionId(ctx context.Context, extensionId int32) ([]model.SchemaFinding, error) { | ||||||
| var findings []model.SchemaFinding | ||||||
|
|
||||||
| if result := s.db.WithContext(ctx).Raw(fmt.Sprintf(` | ||||||
| SELECT id, schema_extension_id, relationship_kind_id, environment_id, name, display_name, created_at | ||||||
| FROM %s WHERE schema_extension_id = ? ORDER BY id`, model.SchemaRelationshipFinding{}.TableName()), extensionId).Scan(&findings); result.Error != nil { | ||||||
| SELECT id, type, schema_extension_id, kind_id, environment_id, name, display_name, created_at | ||||||
| FROM %s WHERE schema_extension_id = ? ORDER BY id`, model.SchemaFinding{}.TableName()), extensionId).Scan(&findings); result.Error != nil { | ||||||
| return findings, CheckError(result) | ||||||
| } | ||||||
| return findings, nil | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.