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

Add support for using featureKey with entitlements #1065

Closed
wants to merge 6 commits into from

Conversation

GAlexIHU
Copy link
Contributor

@GAlexIHU GAlexIHU commented Jun 25, 2024

Overview

  • adds support for using feature key when interacting with entitlements
  • stores UsagePeriod

Fixes #(issue)

Notes for reviewer

chore: support fetching by key
(cherry picked from commit 8964555c73ba3450df5f2d0732748f4a5d99d9a6)
@GAlexIHU GAlexIHU added kind/feature New feature or request release-note/feature Release note: Exciting New Features area/entitlements labels Jun 25, 2024
@GAlexIHU GAlexIHU mentioned this pull request Jun 25, 2024
return Entitlement{}, &productcatalog.FeatureNotFoundError{ID: input.FeatureID}
func (c *entitlementConnector) CreateEntitlement(ctx context.Context, input CreateEntitlementInputs) (*Entitlement, error) {
// ID has precedence over key
idOrKey := input.FeatureID
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the inputs should already get a single FeatureIDorKey field, and this should be handled in the httpdriver layer.

This would also align the PR with the GetEntitlementValue's signature

@@ -30,6 +30,7 @@ func (Entitlement) Fields() []ent.Field {
field.String("feature_id").Immutable().SchemaType(map[string]string{
dialect.Postgres: "char(26)",
}),
field.String("feature_key").Immutable(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's worth storing it here. I would rather prefer that the connector resolves the ID and we persits that data.

I wouldn't want to allow for a situation where a feature gets archived, then a new feature is created with the same key. Let's make sure that inside the DB we are not representing this convenience feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So actually the problem has deeper roots than implementation details:

  • If we want to allow entitlements to be accessible by featureKey, then it's necessary to limit that a user can only be entitled to a given featureKey once. Otherwise we cannot return a simple value.
  • If we limit that then after archiving a feature the user can only be entitled again if the previous is deleted.

The issue is that this is not yet enforced (which i'll add) but after that these archivation scenarios are resolved. (this has some implications on the checks we do at create-time but nothing too complex)

internal/entitlement/postgresadapter/entitlement.go Outdated Show resolved Hide resolved
internal/entitlement/postgresadapter/entitlement.go Outdated Show resolved Hide resolved
internal/entitlement/repository.go Show resolved Hide resolved
internal/productcatalog/feature_connector.go Outdated Show resolved Hide resolved
func (c *featureConnector) GetFeature(ctx context.Context, featureID models.NamespacedID) (Feature, error) {
feature, err := c.featureRepo.GetByID(ctx, featureID)
func (c *featureConnector) GetFeature(ctx context.Context, namespace string, idOrKey string) (*Feature, error) {
feature, err := c.featureRepo.GetByIdOrKey(ctx, namespace, idOrKey, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add an options struct at least for the includeArchived as true/false const arguments are extremely hard to understand what they are representing. (or you can add a type IncludeArchive bool so that the next one reading this code won't have to look up the function signature) ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree 4 arguments is starting to get on the longer side, but signature wise a bool is no different than a string and we don't do custom types for that.

@GAlexIHU GAlexIHU changed the title Refactor/keys and ids 2 Add support for using featureKey with entitlements Jun 26, 2024
@GAlexIHU GAlexIHU marked this pull request as draft June 26, 2024 18:08
@GAlexIHU
Copy link
Contributor Author

implemented in another PR

@GAlexIHU GAlexIHU closed this Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/entitlements kind/feature New feature or request release-note/feature Release note: Exciting New Features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants