Skip to content

Feat/add validations to external secret data from remote ref#2962

Closed
LucasPimentel123 wants to merge 2 commits intoexternal-secrets:mainfrom
leomichalski:feat/add-validations-to-externalSecretDataFromRemoteRef
Closed

Feat/add validations to external secret data from remote ref#2962
LucasPimentel123 wants to merge 2 commits intoexternal-secrets:mainfrom
leomichalski:feat/add-validations-to-externalSecretDataFromRemoteRef

Conversation

@LucasPimentel123
Copy link
Copy Markdown
Contributor

@LucasPimentel123 LucasPimentel123 commented Dec 18, 2023

Problem Statement

Currently, there are no validations on the ExternalSecretDataFromRemoteRef, but it should

  • set either Find, Exact, or SourceRef & SourceRef.GeneratorRef.
  • set SourceRef.GeneratorRef if we want to use SourceRef.

Related Issue

Relates to #2916

Proposed Changes

I added the validations on the validateExternalSecret function

Checklist

  • I have read the contribution guidelines
  • All commits are signed with git commit --signoff
  • My changes have reasonable test coverage
  • All tests pass with make test
  • I ensured my PR is ready for review with make reviewable

Signed-off-by: Lucas Pimentel <luk.2001@hotmail.com>
…oteRef

Signed-off-by: Lucas Pimentel <luk.2001@hotmail.com>
@LucasPimentel123 LucasPimentel123 requested a review from a team as a code owner December 18, 2023 20:59
@LucasPimentel123 LucasPimentel123 requested review from rogertuma and removed request for a team December 18, 2023 20:59
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions

B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

idea Catch issues before they fail your Quality Gate with our IDE extension SonarLint SonarLint

Copy link
Copy Markdown
Contributor

@shuheiktgw shuheiktgw left a comment

Choose a reason for hiding this comment

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

Thank you for your PR, @LucasPimentel123 🙂 I've left some comments, so please take a look at them! Also, some of the jobs failed, so would you resolve them as well?

errs = errors.Join(errs, fmt.Errorf("generator must be set if SourceRef is used"))
}

if !findOrExtract && (ref.SourceRef != nil || ref.SourceRef.GeneratorRef != nil) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This condition seems to be wrong. It should be

!findOrExtract && (ref.SourceRef == nil || ref.SourceRef.GeneratorRef == nil)

Also, I found that !findOrExtract is hard to understand. Why don't we just use the following condition?

ref.Find == nil && ref.Extract == nil && (ref.SourceRef == nil || ref.SourceRef.GeneratorRef == nil)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would you add test cases to cover the four cases?

}

if !findOrExtract && (ref.SourceRef != nil || ref.SourceRef.GeneratorRef != nil) {
errs = errors.Join(errs, fmt.Errorf("either find, extract or source and generator must be set"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
errs = errors.Join(errs, fmt.Errorf("either find, extract or source and generator must be set"))
errs = errors.Join(errs, fmt.Errorf("either extract, find, or sourceRef with generatorRef must be set to dataFrom"))

}

if ref.SourceRef != nil && ref.SourceRef.GeneratorRef == nil {
errs = errors.Join(errs, fmt.Errorf("generator must be set if SourceRef is used"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
errs = errors.Join(errs, fmt.Errorf("generator must be set if SourceRef is used"))
errs = errors.Join(errs, fmt.Errorf("generatorRef cannot be empty when using sourceRef in dataFrom"))

@shuheiktgw shuheiktgw requested review from shuheiktgw and removed request for rogertuma December 21, 2023 23:44
@shuheiktgw
Copy link
Copy Markdown
Contributor

Hi @LucasPimentel123 👋 Are you still working on this PR?

@gusfcarvalho
Copy link
Copy Markdown
Member

Hi @LucasPimentel123 ! Are you still working on this PR?

@shuheiktgw
Copy link
Copy Markdown
Contributor

I will take it over from here

@shuheiktgw
Copy link
Copy Markdown
Contributor

Closing in favor of #3390

@shuheiktgw shuheiktgw closed this Apr 20, 2024
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