diff --git a/openmeter/app/stripe/adapter/stripe.go b/openmeter/app/stripe/adapter/stripe.go index 7b9b89fc5..c981b94c2 100644 --- a/openmeter/app/stripe/adapter/stripe.go +++ b/openmeter/app/stripe/adapter/stripe.go @@ -17,7 +17,6 @@ import ( appstripecustomerdb "github.com/openmeterio/openmeter/openmeter/ent/db/appstripecustomer" secretentity "github.com/openmeterio/openmeter/openmeter/secret/entity" "github.com/openmeterio/openmeter/pkg/framework/entutils" - "github.com/openmeterio/openmeter/pkg/models" ) var _ appstripe.AppStripeAdapter = (*adapter)(nil) @@ -130,12 +129,12 @@ func (a adapter) GetWebhookSecret(ctx context.Context, input appstripeentity.Get } // Get the webhook secret - secret, err := a.secretService.GetAppSecret(ctx, secretentity.GetAppSecretInput{ - NamespacedID: models.NamespacedID{ - Namespace: stripeApp.Namespace, - ID: stripeApp.WebhookSecret, - }, - }) + appID := appentitybase.AppID{ + Namespace: stripeApp.Namespace, + ID: stripeApp.ID, + } + + secret, err := a.secretService.GetAppSecret(ctx, secretentity.NewSecretID(appID, stripeApp.WebhookSecret, appstripeentity.WebhookSecretKey)) if err != nil { return secretentity.Secret{}, fmt.Errorf("failed to get webhook secret: %w", err) } @@ -323,12 +322,7 @@ func (a adapter) CreateCheckoutSession(ctx context.Context, input appstripeentit input.StripeCustomerID = &stripeCustomerId // Get Stripe API Key - apiKeySecret, err := repo.secretService.GetAppSecret(ctx, secretentity.GetAppSecretInput{ - NamespacedID: models.NamespacedID{ - Namespace: stripeApp.Namespace, - ID: stripeApp.APIKey, - }, - }) + apiKeySecret, err := repo.secretService.GetAppSecret(ctx, secretentity.NewSecretID(appID, stripeApp.APIKey, appstripeentity.APIKeySecretKey)) if err != nil { return appstripeentity.CreateCheckoutSessionOutput{}, fmt.Errorf("failed to get stripe api key secret: %w", err) } diff --git a/openmeter/app/stripe/entity/app/app.go b/openmeter/app/stripe/entity/app/app.go index 160d45f54..7ca45a9c8 100644 --- a/openmeter/app/stripe/entity/app/app.go +++ b/openmeter/app/stripe/entity/app/app.go @@ -14,7 +14,6 @@ import ( customerentity "github.com/openmeterio/openmeter/openmeter/customer/entity" "github.com/openmeterio/openmeter/openmeter/secret" secretentity "github.com/openmeterio/openmeter/openmeter/secret/entity" - "github.com/openmeterio/openmeter/pkg/models" ) const ( @@ -91,12 +90,7 @@ func (a App) ValidateCustomer(ctx context.Context, customer *customerentity.Cust } // Get Stripe API Key - apiKeySecret, err := a.SecretService.GetAppSecret(ctx, secretentity.GetAppSecretInput{ - NamespacedID: models.NamespacedID{ - Namespace: stripeAppData.APIKey.Namespace, - ID: stripeAppData.APIKey.ID, - }, - }) + apiKeySecret, err := a.SecretService.GetAppSecret(ctx, secretentity.NewSecretID(a.GetID(), stripeAppData.APIKey.ID, appstripeentity.APIKeySecretKey)) if err != nil { return fmt.Errorf("failed to get stripe api key secret: %w", err) } diff --git a/openmeter/secret/adapter/secret.go b/openmeter/secret/adapter/secret.go index d7ccff46c..a5615cb25 100644 --- a/openmeter/secret/adapter/secret.go +++ b/openmeter/secret/adapter/secret.go @@ -15,8 +15,8 @@ func (a adapter) CreateAppSecret(ctx context.Context, input secretentity.CreateA Namespace: input.AppID.Namespace, ID: input.Value, }, - // AppID: input.AppID, - // Key: input.Key, + AppID: input.AppID, + Key: input.Key, }, nil } @@ -29,8 +29,8 @@ func (a adapter) GetAppSecret(ctx context.Context, input secretentity.GetAppSecr Namespace: input.Namespace, ID: input.ID, }, - // AppID: input.AppID, - // Key: input.Key, + AppID: input.AppID, + Key: input.Key, }, Value: input.ID, }, nil diff --git a/openmeter/secret/entity/secret.go b/openmeter/secret/entity/secret.go index 6d9577600..2fcffbd60 100644 --- a/openmeter/secret/entity/secret.go +++ b/openmeter/secret/entity/secret.go @@ -11,8 +11,8 @@ import ( // SecretID represents a secret identifier. type SecretID struct { models.NamespacedID - // AppID appentitybase.AppID - // Key string + AppID appentitybase.AppID + Key string } func NewSecretID(appID appentitybase.AppID, id string, key string) SecretID { @@ -21,29 +21,29 @@ func NewSecretID(appID appentitybase.AppID, id string, key string) SecretID { Namespace: appID.Namespace, ID: id, }, - // AppID: appID, - // Key: key, + AppID: appID, + Key: key, } } func (i SecretID) Validate() error { if err := i.NamespacedID.Validate(); err != nil { return ValidationError{ - Err: fmt.Errorf("secret %w", err), + Err: fmt.Errorf("secret: %w", err), } } - // if err := i.AppID.Validate(); err != nil { - // return ValidationError{ - // Err: fmt.Errorf("secret app id %w", err), - // } - // } + if err := i.AppID.Validate(); err != nil { + return ValidationError{ + Err: fmt.Errorf("secret app id: %w", err), + } + } - // if i.Key == "" { - // return ValidationError{ - // Err: errors.New("secret key is required"), - // } - // } + if i.Key == "" { + return ValidationError{ + Err: errors.New("secret key is required"), + } + } return nil }