Skip to content
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

chore: Add ShowByID filtering generation #3227

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

sfc-gh-fbudzynski
Copy link
Collaborator

Changes

  • ExtendedIn name changed from "In" to "ExtendedIn"
  • Added ShowByID filtering options to implement_functions template
  • New filed in Operation struct with Filtering options

To generate filtering options, add filtering options in ShowByIDOperation:

).ShowByIdOperation(
	g.ShowByIDLikeFiltering,
	g.ShowByIDExtendedInFiltering,
)

Test Plan

  • acceptance tests for secrets
  • integration tests for secrets
  • unit tests for secrets
  • Used secrets as base for testing how filtering generation works

@sfc-gh-fbudzynski sfc-gh-fbudzynski changed the title Chore: Add ShowByID filtering generation chore: Add ShowByID filtering generation Nov 26, 2024
Copy link

Integration tests failure for 1599afb36a36122395af19213ab1a4562b220e90

@@ -107,7 +107,7 @@ func ReadSecrets(ctx context.Context, d *schema.ResourceData, meta any) diag.Dia
req := sdk.NewShowSecretRequest()

handleLike(d, &req.Like)
err := handleExtendedIn(d, &req.In)
err := handleExtendedIn(d, &req.ExtendedIn)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm open for discussions, but I'm not sure if it's necessary. On the other hand, in Snowflake, is just IN, and initially ExtendedIn was used only to distinguish from In with limited filtering capabilities.

Copy link
Collaborator Author

@sfc-gh-fbudzynski sfc-gh-fbudzynski Nov 28, 2024

Choose a reason for hiding this comment

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

It will change how the filtering in the template is handled and how we should define filtering for the ShowBiIDFiltering struct. But it can be changed if it is preferred to leave the Extended In as before.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For me, it's more readable that way because I know it's the extended version, but both options are ok.

{{ $impl }}, err := v.Show(ctx, NewShow{{ .ObjectInterface.NameSingular }}Request())
request := NewShow{{ .ObjectInterface.NameSingular }}Request()
{{- if not .ShowByIDFiltering }}
// TODO: adjust request if e.g. LIKE is supported for the resource
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can leave the default behavior as it is, but we can point the SDK users to use g.ShowByIDLikeFiltering, and others more explicitly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about: // TODO: adjust request if e.g. LIKE is supported for the resource with ShowByIDLikeFiltering and other filters for "ShowByIdOperation" in the definition file."

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good.

Args: "Pattern: String(id.Name())",
IdentifierBased: false,
})
case ShowByIDInFiltering:
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can use it (non-extended In) in one object to show if it works.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good idea, i will generate some objects to show all the filtering options

type ShowByIDFiltering struct {
Kind string
Args string
IdentifierBased bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we could use an enum instead? What if we have more showByIDs which have a different behavior? Such flag could be confusing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right, that would probably be a better approach than just a flag

ShowByIDInFiltering
// Enables filtering with: ExtendedIn
// Based on the identifier Kind
ShowByIDExtendedInFiltering
Copy link
Collaborator

@sfc-gh-jmichalak sfc-gh-jmichalak Nov 27, 2024

Choose a reason for hiding this comment

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

In your doc you proposed sth like

	ShowByIDSchemaFiltering     ShowByIDFilteringKind = "In{Schema: id.SchemaId()}"
	ShowByIDInDatabaseFiltering ShowByIDFilteringKind = "In{Database: id.DatabaseId()}"

I'm not saying it's bad, but I'm curious about the other approach here.

I wonder if we can separate these abstractions (one is database vs schema, and the other is in vs extended in)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think we can skip the In vs. ExtendedIn because those filterings use different structs. For ExtendedIn, we need to provide the ExtendedIn struct, and for Simple In, just the In struct.

I aimed to make it similar in use to what we have for the ShowOperation:

g.NewQueryStruct("ShowSecret").
	...
	OptionalLike().
	OptionalExtendedIn(),

and then for the filtering we use:

).ShowByIdOperation(
	g.ShowByIDLikeFiltering,
	g.ShowByIDExtendedInFiltering,
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants