Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Fix/import managed resources#346

Merged
nxtcoder17 merged 7 commits into
mainfrom
fix/import-managed-resources
Jul 10, 2024
Merged

Fix/import managed resources#346
nxtcoder17 merged 7 commits into
mainfrom
fix/import-managed-resources

Conversation

@nxtcoder17
Copy link
Copy Markdown
Member

@nxtcoder17 nxtcoder17 commented Jul 10, 2024

Description

  • Introduces Import Integrated Resources
  • Root Credentials for Integrated Services, are now also treated as an Integrated Resource
  • Environments can now import integrated resources, and use it

Summary by Sourcery

This pull request introduces the capability to create and manage integrated resources, including root credentials for integrated services. It also allows environments to import and use these resources. The changes include updates to gRPC interfaces, domain logic, and GraphQL schema and resolvers.

  • New Features:
    • Introduced the ability to create and manage integrated resources, including root credentials for integrated services.
    • Environments can now import integrated resources and utilize them.
  • Enhancements:
    • Added new gRPC methods and message types to support the creation and management of integrated resources.
    • Refactored the domain logic to handle integrated resources, including new methods for creating, updating, and deleting these resources.
    • Updated the GraphQL schema and resolvers to support querying and mutating integrated resources.

@nxtcoder17 nxtcoder17 requested a review from karthik1729 as a code owner July 10, 2024 08:27
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jul 10, 2024

Reviewer's Guide by Sourcery

This pull request introduces the ability to import managed resources and treat root credentials for integrated services as integrated resources. It also allows environments to import and use these integrated resources.

File-Level Changes

Files Changes
grpc-interfaces/kloudlite.io/rpc/console/console.pb.go
apps/console/internal/app/grpc-server.go
Introduced CreateManagedResource RPC method and its implementation.
apps/console/internal/domain/mres.go
apps/console/internal/domain/secret.go
apps/console/internal/domain/domain.go
Refactored managed resource and secret handling, added support for root managed resources, and updated domain structure.
apps/console/internal/app/graph/model/models_gen.go
apps/console/internal/app/graph/schema.resolvers.go
apps/console/internal/app/graph/common-types.resolvers.go
apps/console/internal/app/graph/importedmanagedresource.resolvers.go
Updated GraphQL schema and resolvers to support imported managed resources and new fields.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @nxtcoder17 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 13 issues found
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

}

// mutations
func (d *domain) CreateRootManagedResource(ctx ConsoleContext, accountNamespace string, mres *entities.ManagedResource) (*entities.ManagedResource, error) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider adding validation for the input parameters.

Adding validation for accountNamespace and mres can help catch potential issues early and improve the robustness of the function.

Suggested change
func (d *domain) CreateRootManagedResource(ctx ConsoleContext, accountNamespace string, mres *entities.ManagedResource) (*entities.ManagedResource, error) {
func (d *domain) CreateRootManagedResource(ctx ConsoleContext, accountNamespace string, mres *entities.ManagedResource) (*entities.ManagedResource, error) {
if accountNamespace == "" {
return nil, errors.New("accountNamespace cannot be empty")
}
if mres == nil {
return nil, errors.New("managed resource cannot be nil")
}
if err := d.canPerformActionInAccount(ctx, iamT.CreateManagedResource); err != nil {
return nil, errors.NewE(err)
}

}

// ManagedResource is the resolver for the ManagedResource field.
func (r *importedManagedResourceResolver) ManagedResource(ctx context.Context, obj *entities.ImportedManagedResource) (*entities.ManagedResource, error) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider handling potential nil values for obj.

Adding a nil check for obj can prevent potential runtime panics and improve the robustness of the function.

Suggested change
func (r *importedManagedResourceResolver) ManagedResource(ctx context.Context, obj *entities.ImportedManagedResource) (*entities.ManagedResource, error) {
func (r *importedManagedResourceResolver) ManagedResource(ctx context.Context, obj *entities.ImportedManagedResource) (*entities.ManagedResource, error) {
if obj == nil {
return nil, errors.New("imported managed resource is nil")
}
cc, err := toConsoleContext(ctx)
if err != nil {

return pr, nil
}

func fromDataToStringData(secret *corev1.Secret) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Consider adding a nil check for secret.

Adding a nil check for secret can prevent potential runtime panics and improve the robustness of the function.

Suggested change
func fromDataToStringData(secret *corev1.Secret) {
func fromDataToStringData(secret *corev1.Secret) {
if secret == nil {
return
}
if secret.StringData == nil {
secret.StringData = make(map[string]string, len(secret.Data))
}

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (d *domain) ImportManagedResource(ctx ManagedResourceContext, mresName string, importName string) (*entities.ImportedManagedResource, error) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider adding validation for input parameters.

It would be beneficial to validate mresName and importName to ensure they are not empty or invalid before proceeding with the function logic.

Suggested change
func (d *domain) ImportManagedResource(ctx ManagedResourceContext, mresName string, importName string) (*entities.ImportedManagedResource, error) {
func (d *domain) ImportManagedResource(ctx ManagedResourceContext, mresName string, importName string) (*entities.ImportedManagedResource, error) {
if mresName == "" || importName == "" {
return nil, fmt.Errorf("mresName and importName must not be empty")
}

return imr, nil
}

func (d *domain) DeleteImportedManagedResource(ctx ResourceContext, importName string) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 suggestion (security): Consider adding a confirmation step before deletion.

To prevent accidental deletions, consider adding a confirmation step or a soft delete mechanism.

Suggested change
func (d *domain) DeleteImportedManagedResource(ctx ResourceContext, importName string) error {
func (d *domain) DeleteImportedManagedResource(ctx ResourceContext, importName string) error {
confirmation := getConfirmationFromUser()
if !confirmation {
return errors.New("deletion aborted by user")
}
if err := d.canMutateResourcesInEnvironment(ctx); err != nil {
return errors.NewE(err)
}

return ResourceTypeImportedManagedResource
}

type ManagedResourceRef struct {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider embedding common fields.

If ManagedResourceRef is used in multiple places, consider embedding it in other structs to reduce redundancy.

Suggested change
type ManagedResourceRef struct {
type CommonFields struct {
ID repos.ID `json:"id"`
Name string `json:"name"`
}
type ManagedResourceRef struct {
CommonFields
}

@@ -22948,9 +24796,9 @@ func (ec *executionContext) _ImagePullSecretPaginatedRecords_pageInfo(ctx contex
return ec.marshalNPageInfo2ᚖgithubᚗcomᚋkloudliteᚋapiᚋappsᚋconsoleᚋinternalᚋappᚋgraphᚋmodelᚐPageInfo(ctx, field.Selections, res)
}

func (ec *executionContext) fieldContext_ImagePullSecretPaginatedRecords_pageInfo(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
func (ec *executionContext) fieldContext_ImportedManagedResourcePaginatedRecords_pageInfo(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider renaming the function for consistency.

The function name fieldContext_ImportedManagedResourcePaginatedRecords_pageInfo is quite long and could be shortened for better readability. Consider renaming it to something more concise while maintaining clarity.

Suggested change
func (ec *executionContext) fieldContext_ImportedManagedResourcePaginatedRecords_pageInfo(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
func (ec *executionContext) fieldCtx_ImportedManagedResourcePageInfo(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {

@@ -32768,6 +34608,92 @@
return fc, nil
}

func (ec *executionContext) _Query_core_listImportedManagedResources(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): Consider adding pagination support.

For the listImportedManagedResources query, consider adding pagination support to handle large datasets efficiently.

Suggested change
func (ec *executionContext) _Query_core_listImportedManagedResources(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
func (ec *executionContext) _Query_core_listImportedManagedResources(ctx context.Context, field graphql.CollectedField, first *int, after *string) (ret graphql.Marshaler) {

@@ -38103,6 +40082,113 @@
return it, nil
}

func (ec *executionContext) unmarshalInputGithub__com___kloudlite___api___apps___console___internal___entities__ManagedResourceRefIn(ctx context.Context, obj interface{}) (model.GithubComKloudliteAPIAppsConsoleInternalEntitiesManagedResourceRefIn, error) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider breaking down long function names.

The function name unmarshalInputGithub__com___kloudlite___api___apps___console___internal___entities__ManagedResourceRefIn is very long and could be broken down for better readability and maintainability.

Suggested change
func (ec *executionContext) unmarshalInputGithub__com___kloudlite___api___apps___console___internal___entities__ManagedResourceRefIn(ctx context.Context, obj interface{}) (model.GithubComKloudliteAPIAppsConsoleInternalEntitiesManagedResourceRefIn, error) {
func (ec *executionContext) unmarshalInputManagedResourceRefIn(ctx context.Context, obj interface{}) (model.GithubComKloudliteAPIAppsConsoleInternalEntitiesManagedResourceRefIn, error) {

return it, nil
}

func (ec *executionContext) unmarshalInputGithub__com___kloudlite___api___pkg___types__SyncStatusIn(ctx context.Context, obj interface{}) (types.SyncStatus, error) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider adding validation for input fields.

For the unmarshalInputGithub__com___kloudlite___api___pkg___types__SyncStatusIn function, consider adding validation for the input fields to ensure data integrity.

@nxtcoder17 nxtcoder17 closed this Jul 10, 2024
@nxtcoder17 nxtcoder17 reopened this Jul 10, 2024
@nxtcoder17 nxtcoder17 merged commit fd98601 into main Jul 10, 2024
@nxtcoder17 nxtcoder17 deleted the fix/import-managed-resources branch July 10, 2024 08:33
abdheshnayak pushed a commit that referenced this pull request Nov 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants