Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed Jul 23, 2024
1 parent 54309db commit aea1c9a
Show file tree
Hide file tree
Showing 14 changed files with 1,160 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ VALUES (
)`, pgx.NamedArgs{
"licenseID": licenseID,
// Convert to string representation of EnterpriseSubscriptionLicenseCondition
"status": subscriptionsv1.EnterpriseSubscriptionLicenseCondition_Status_name[int32(opts.Status)],
"status": opts.Status.String(),
"message": pointers.NilIfZero(opts.Message),
"transitionTime": opts.TransitionTime,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ VALUES (
`, pgx.NamedArgs{
"licenseID": licenseID,
"subscriptionID": subscriptionID,
"licenseType": subscriptionsv1.EnterpriseSubscriptionLicenseType_name[int32(licenseType)],
"licenseType": licenseType.String(),
"licenseData": licenseData,
"createdAt": opts.Time,
"expireAt": opts.ExpireTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ VALUES (
)`, pgx.NamedArgs{
"subscriptionID": subscriptionID,
// Convert to string representation of EnterpriseSubscriptionCondition
"status": subscriptionsv1.EnterpriseSubscriptionCondition_Status_name[int32(opts.Status)],
"status": opts.Status.String(),
"message": pointers.NilIfZero(opts.Message),
"transitionTime": opts.TransitionTime,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ go_library(
"@com_github_sourcegraph_sourcegraph_accounts_sdk_go//clients/v1:clients",
"@com_github_sourcegraph_sourcegraph_accounts_sdk_go//scopes",
"@org_golang_google_protobuf//types/known/timestamppb",
"@org_golang_x_crypto//ssh",
"@org_golang_x_exp//maps",
],
)
Expand All @@ -48,11 +49,15 @@ go_test(
embed = [":subscriptionsservice"],
deps = [
"//cmd/enterprise-portal/internal/database/subscriptions",
"//cmd/enterprise-portal/internal/database/utctime",
"//cmd/enterprise-portal/internal/samsm2m",
"//internal/license",
"//lib/enterpriseportal/subscriptions/v1:subscriptions",
"//lib/managedservicesplatform/iam",
"//lib/pointers",
"@com_connectrpc_connect//:connect",
"@com_github_derision_test_go_mockgen_v2//testutil/require",
"@com_github_google_uuid//:uuid",
"@com_github_hexops_autogold_v2//:autogold",
"@com_github_sourcegraph_log//logtest",
"@com_github_sourcegraph_sourcegraph_accounts_sdk_go//:sourcegraph-accounts-sdk-go",
Expand All @@ -61,6 +66,7 @@ go_test(
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@org_golang_google_protobuf//types/known/fieldmaskpb",
"@org_golang_google_protobuf//types/known/timestamppb",
],
)

Expand Down
20 changes: 13 additions & 7 deletions cmd/enterprise-portal/internal/subscriptionsservice/adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func convertLicenseKeyToLicenseKeyData(
createdAt utctime.Time,
sub *subscriptions.Subscription,
key *subscriptionsv1.EnterpriseSubscriptionLicenseKey,
requiredTags []string,
signKeyFn func(license.Info) (string, error),
) (*subscriptions.DataLicenseKey, error) {
expires := key.GetInfo().GetExpireTime().AsTime()
if expires.Before(time.Now()) {
Expand All @@ -139,6 +141,12 @@ func convertLicenseKeyToLicenseKeyData(
if _, exists := providedTagPrefixes["customer"]; !exists && sub.DisplayName != nil {
tags = append(tags, fmt.Sprintf("customer:%s", *sub.DisplayName))
}
for _, r := range requiredTags {
if _, ok := providedTagPrefixes[r]; !ok {
return nil, connect.NewError(connect.CodeInvalidArgument,
errors.Newf("key tags [%s] are required", strings.Join(requiredTags, ", ")))
}
}

info := license.Info{
Tags: tags,
Expand All @@ -150,15 +158,13 @@ func convertLicenseKeyToLicenseKeyData(
SalesforceSubscriptionID: sub.SalesforceSubscriptionID,
SalesforceOpportunityID: sub.SalesforceOpportunityID,
}

// TODO
// signedKey, _, err := licensing.GenerateProductLicenseKey(info)
// if err != nil {
// return nil, connectutil.InternalError(ctx, logger, err, "")
// }
signedKey, err := signKeyFn(info)
if err != nil {
return nil, errors.Wrap(err, "sign key")
}

return &subscriptions.DataLicenseKey{
Info: info,
SignedKey: "TODO",
SignedKey: signedKey,
}, nil
}
Loading

0 comments on commit aea1c9a

Please sign in to comment.