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

Implement entitlement verification and AWS metering #42

Merged
merged 2 commits into from
Jun 20, 2024

Conversation

stefanprodan
Copy link
Member

This PR adds entitlement verification and metering for AWS Marketplace service.

Ref: controlplaneio-fluxcd/distribution#88

PS. When the operator is not installed from the AWS Marketplace, an offline entitlement client is employed that generates
a perpetual license token.

@stefanprodan stefanprodan added the area/marketplace EE marketplace issues and pull requests label Jun 18, 2024
@stefanprodan stefanprodan requested a review from souleb June 18, 2024 12:48
@stefanprodan stefanprodan force-pushed the entitlement-reconciler branch from 234b6f7 to 709ef60 Compare June 18, 2024 20:38
internal/entitlement/aws.go Outdated Show resolved Hide resolved

// NewAmazonClient creates a new AmazonClient using the default
// AWS configuration and the current region.
func NewAmazonClient(vendor string) (*AmazonClient, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to have a test for this. I believe we can use WithEndpointResolverV2() for that purpose.

type endpointResolverV2 struct {
	URL url.URL
}

func (e *endpointResolverV2) ResolveEndpoint(ctx context.Context, params marketplacemetering.EndpointParameters) (smithyendpoints.Endpoint, error) {
	return smithyendpoints.Endpoint{
		URI: e.URL,
	}, nil
}

func TestMarketplaceClient() {
	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		...
	}))
	defer srv.Close()
	opt := marketplacemetering.WithEndpointResolverV2(&endpointResolverV2{URL: url.URL{Scheme: "http", Host: srv.URL}})
	mc := marketplacemetering.NewFromConfig(cfg, opt)
	...
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Mocking the AWS APIs could come later after we release a version with metering and we tests it on EKS.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've tested this PR on EKS with an IRSA for AWSMarketplaceMeteringRegisterUsage and all works, the usage is registered and the resulting token is valid 🎉

internal/entitlement/client.go Show resolved Hide resolved
@stefanprodan stefanprodan force-pushed the entitlement-reconciler branch from 709ef60 to 8208796 Compare June 19, 2024 07:30
@stefanprodan stefanprodan changed the title Implement entitlement verification and metering Implement entitlement verification and AWS metering Jun 19, 2024
Copy link
Contributor

@souleb souleb left a comment

Choose a reason for hiding this comment

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

LGTM!

@stefanprodan stefanprodan force-pushed the entitlement-reconciler branch from 31e3ac3 to 246e88c Compare June 20, 2024 09:09
@stefanprodan stefanprodan merged commit aca33f2 into main Jun 20, 2024
1 check passed
@stefanprodan stefanprodan deleted the entitlement-reconciler branch June 20, 2024 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/marketplace EE marketplace issues and pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants