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

feat: add flag to ignore app secret in manifest.xml #469

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/extension/extension_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var extensionValidateCmd = &cobra.Command{
return fmt.Errorf("cannot open extension: %w", err)
}

context := extension.RunValidation(cmd.Context(), ext)
context := extension.RunValidation(cmd.Context(), ext, ignoreAppSecret)

if context.HasErrors() || context.HasWarnings() {
table := tablewriter.NewWriter(os.Stdout)
Expand Down Expand Up @@ -67,6 +67,9 @@ var extensionValidateCmd = &cobra.Command{
},
}

var ignoreAppSecret bool

func init() {
extensionRootCmd.AddCommand(extensionValidateCmd)
extensionValidateCmd.Flags().BoolVar(&ignoreAppSecret, "ignore-app-secret", false, "Ignore app secret in manifest.xml")
}
4 changes: 2 additions & 2 deletions extension/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (a App) Validate(_ context.Context, ctx *ValidationContext) {
ctx.AddError("The element meta:license was not found in the manifest.xml")
}

if a.manifest.Setup != nil && a.manifest.Setup.Secret != "" {
ctx.AddError("The xml element setup:secret is only for local development, please remove it. You can find your generated app secret on your extension detail page in the master data section. For more information see https://docs.shopware.com/en/shopware-platform-dev-en/app-system-guide/setup#authorisation")
if a.manifest.Setup != nil && a.manifest.Setup.Secret != "" && ctx.IgnoreAppSecret == false {
ctx.AddWarning("The xml element setup:secret is only for local development, please remove it. You can find your generated app secret on your extension detail page in the master data section. For more information see https://docs.shopware.com/en/shopware-platform-dev-en/app-system-guide/setup#authorisation")
}
}
15 changes: 8 additions & 7 deletions extension/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
)

type ValidationContext struct {
Extension Extension
errors []string
warnings []string
Extension Extension
IgnoreAppSecret bool
errors []string
warnings []string
}

func newValidationContext(ext Extension) *ValidationContext {
return &ValidationContext{Extension: ext}
func newValidationContext(ext Extension, ignoreAppSecret bool) *ValidationContext {
return &ValidationContext{Extension: ext, IgnoreAppSecret: ignoreAppSecret}
}

func (c *ValidationContext) AddError(message string) {
Expand All @@ -44,8 +45,8 @@ func (c *ValidationContext) Warnings() []string {
return c.warnings
}

func RunValidation(ctx context.Context, ext Extension) *ValidationContext {
context := newValidationContext(ext)
func RunValidation(ctx context.Context, ext Extension, ignoreAppSecret bool) *ValidationContext {
context := newValidationContext(ext, ignoreAppSecret)

runDefaultValidate(context)
ext.Validate(ctx, context)
Expand Down
Loading