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

DataSource: Move the shared parts of Add+Update commands into a base struct #88036

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

Conversation

ryantxu
Copy link
Member

@ryantxu ryantxu commented May 20, 2024

This is an alternative approach to #88018

Rather than unify the two commands, this puts the shared parts into a base struct.

This adds a lot more typing when creating commands, but at least makes the difference between the two commands more clear 🤷🏻

@ryantxu ryantxu added no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes labels May 20, 2024
@ryantxu ryantxu added this to the 11.1.x milestone May 20, 2024
@ryantxu ryantxu requested review from a team as code owners May 20, 2024 06:35
Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

My +1 for this approach. It's annoying that you need to specify BaseDatasource everytime but I prefer that than both commands sharing the same struct.

type AddDataSourceCommand struct {
// The input values shared with both Add+Update commands (also part of the DTO)
// This part of the command can share validation between add and update actions
type BaseDataSourceCommand struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

the name may be a bit confusing because it could mean that DeleteDatasource also extends this one. Maybe something like BaseWriteDataSourceCommand?

Copy link
Member

@marefr marefr left a comment

Choose a reason for hiding this comment

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

In favor of this proposal as well. The trade-off with having to instantiate BaseDataSourceCommand for create/update is worth it compared to the non-explicit nature of the other proposal.

ReadOnly bool `json:"-"`
EncryptedSecureJsonData map[string][]byte `json:"-"`
UpdateSecretFn UpdateSecretFn `json:"-"`
}

// Also acts as api DTO
type AddDataSourceCommand struct {
BaseDataSourceCommand
Copy link
Member

Choose a reason for hiding this comment

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

Nit. Does this need json inline tag to make the JSON unmarshal work as expected?

APIVersion string `json:"apiVersion"`
// swagger:ignore
IsPrunable bool
BaseDataSourceCommand
Copy link
Member

Choose a reason for hiding this comment

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

Nit. Does this need json inline tag to make the JSON unmarshal work as expected?

Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/backend/db/migration area/backend area/frontend no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants