Skip to content

Commit 0447ae0

Browse files
committed
Fix - tons of licesing issues
1 parent 5487ed9 commit 0447ae0

File tree

3 files changed

+199
-29
lines changed

3 files changed

+199
-29
lines changed

db-connector.go

Lines changed: 92 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13537,39 +13537,119 @@ func GetEsConfig(defaultCreds bool) *opensearch.Client {
1353713537
return es
1353813538
}
1353913539

13540-
func checkNoInternet() (bool, string) {
13540+
func checkNoInternet() OnpremLicense {
13541+
13542+
license := OnpremLicense{}
1354113543
licenseKey := os.Getenv("SHUFFLE_LICENSE")
1354213544
if len(licenseKey) == 0 {
13543-
return false, ""
13545+
return license
13546+
}
13547+
13548+
if len(licenseKey) < 32 {
13549+
log.Printf("[ERROR] License key is too short")
13550+
return license
1354413551
}
1354513552

13546-
// Month + Year -> when it runs out
13547-
sum := sha256.Sum256([]byte(licenseKey))
13548-
encodedString := hex.EncodeToString(sum[:])
13553+
// Split the license key into chunks of 32 characters
13554+
licenseParts := []string{}
13555+
for i := 0; i < len(licenseKey); i += 32 {
13556+
end := i + 32
13557+
13558+
if end > len(licenseKey) {
13559+
end = len(licenseKey)
13560+
}
13561+
licenseParts = append(licenseParts, licenseKey[i:end])
13562+
}
13563+
13564+
licenseKeyPart := licenseParts[0]
13565+
sum := sha256.Sum256([]byte(licenseKeyPart))
13566+
encodedString := hex.EncodeToString(sum[:])
13567+
13568+
tenantKey := ""
13569+
if len(licenseParts) > 1 {
13570+
tenantKey = licenseParts[1]
13571+
}
13572+
13573+
tenantHash := sha256.Sum256([]byte(tenantKey))
13574+
encodedTenant := hex.EncodeToString(tenantHash[:])
13575+
environmentKey := ""
13576+
if len(licenseParts) > 2 {
13577+
environmentKey = licenseParts[2]
13578+
}
13579+
13580+
environmentHash := sha256.Sum256([]byte(environmentKey))
13581+
encodedEnvironment := hex.EncodeToString(environmentHash[:])
13582+
13583+
branding := ""
13584+
if len(licenseParts) > 3 {
13585+
branding = licenseParts[3]
13586+
}
13587+
13588+
brandingHash := sha256.Sum256([]byte(branding))
13589+
encodedBranding := hex.EncodeToString(brandingHash[:])
1354913590

1355013591
// Returns a map[sha256]timeout string
13551-
onpremKeys := GetOnpremKeys()
13592+
onpremKeys := GetOnpremKeys()
1355213593
if timeout, ok := onpremKeys[encodedString]; ok {
13553-
// Check if current time is MORE than the encoded timeout. The timeout format
13594+
// Check if current time is MORE than the encoded timeout. The timeout format
1355413595
parsedTimeout, err := time.Parse("02-01-2006", timeout)
1355513596
if err != nil {
1355613597
log.Printf("[ERROR] Failed parsing license timeout: %s", err)
1355713598
} else {
1355813599
if time.Now().Before(parsedTimeout) {
13559-
if debug {
13600+
if debug {
1356013601
log.Printf("[DEBUG] License key is valid")
1356113602
}
1356213603

13563-
return true, timeout
13604+
license.Valid = true
13605+
license.Timeout = timeout
13606+
13607+
if len(tenantKey) > 0 && len(encodedTenant) > 0 {
13608+
amount := GetTenantAmount(encodedTenant)
13609+
license.Tenant.Limit = int64(amount)
13610+
if amount > 3 {
13611+
license.Tenant.Active = true
13612+
} else {
13613+
license.Tenant.Active = false
13614+
}
13615+
} else {
13616+
license.Tenant.Limit = 3
13617+
license.Tenant.Active = false
13618+
}
13619+
13620+
//check env limit
13621+
if len(environmentKey) > 0 && len(encodedEnvironment) > 0 {
13622+
amount := GetRuntimeLocationAmount(encodedEnvironment)
13623+
license.Environment.Limit = int64(amount)
13624+
if amount > 1 {
13625+
license.Environment.Active = true
13626+
} else {
13627+
license.Environment.Active = false
13628+
}
13629+
13630+
} else {
13631+
license.Environment.Limit = 1
13632+
license.Environment.Active = false
13633+
}
13634+
13635+
//check branding enable
13636+
if len(branding) > 0 && len(encodedBranding) > 0 {
13637+
branding := GetBrandingAvailable(encodedBranding)
13638+
license.Branding = branding
13639+
} else {
13640+
license.Branding = false
13641+
}
13642+
13643+
return license
1356413644
} else {
1356513645
log.Printf("[ERROR] License key has expired on %s", timeout)
13566-
return false, timeout
13646+
return license
1356713647
}
1356813648
}
13569-
}
13649+
}
1357013650

1357113651
log.Printf("[ERROR] No valid license key found based SHUFFLE_LICENSE %s", licenseKey)
13572-
return false, ""
13652+
return license
1357313653
}
1357413654

1357513655
func UploadAppSpecFiles(ctx context.Context, client *storage.Client, api WorkflowApp, parsed ParsedOpenApi) (WorkflowApp, error) {

shared.go

Lines changed: 92 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,13 @@ func HandleGetOrg(resp http.ResponseWriter, request *http.Request) {
11041104
// Not a suborg
11051105
cloudOrg := HandleCheckLicense(ctx, *org)
11061106
org = &cloudOrg
1107+
} else if len(org.CreatorOrg) > 0 && project.Environment == "onprem" {
1108+
parentOrg, err := GetOrg(ctx, org.CreatorOrg)
1109+
if err == nil && len(parentOrg.Subscriptions) > 0 {
1110+
licenseOrg := HandleCheckLicense(ctx, *parentOrg)
1111+
parentOrg = &licenseOrg
1112+
org.Subscriptions = parentOrg.Subscriptions
1113+
}
11071114
}
11081115

11091116
if len(org.CreatorOrg) == 0 && project.Environment == "onprem" {
@@ -3070,6 +3077,7 @@ func HandleGetEnvironments(resp http.ResponseWriter, request *http.Request) {
30703077
}
30713078

30723079
hideEnvs := false
3080+
parentOrgMain := Org{}
30733081
if project.Environment == "onprem" {
30743082
currentOrg, err := GetOrg(ctx, user.ActiveOrg.Id)
30753083
if err != nil {
@@ -3089,22 +3097,52 @@ func HandleGetEnvironments(resp http.ResponseWriter, request *http.Request) {
30893097
}
30903098

30913099
licenseOrg := HandleCheckLicense(ctx, *parentOrg)
3092-
if !licenseOrg.SyncFeatures.MultiEnv.Active && int64(len(environments)) > licenseOrg.SyncFeatures.MultiEnv.Limit {
3100+
parentOrgMain = licenseOrg
3101+
if int64(len(environments)) > licenseOrg.SyncFeatures.MultiEnv.Limit {
30933102
hideEnvs = true
30943103
}
30953104
}
30963105

30973106
newEnvironments := []Environment{}
3098-
for _, environment := range environments {
3099-
if len(environment.Id) == 0 {
3100-
environment.Id = uuid.NewV4().String()
3107+
sort.Slice(environments, func(i, j int) bool {
3108+
return environments[i].Created < environments[j].Created
3109+
})
3110+
3111+
filteredEnvironments := []Environment{}
3112+
if hideEnvs {
3113+
defaultEnvs := []Environment{}
3114+
nonDefaultEnvs := []Environment{}
3115+
for _, env := range environments {
3116+
if len(env.Id) == 0 {
3117+
env.Id = uuid.NewV4().String()
3118+
}
3119+
3120+
3121+
if env.Default {
3122+
defaultEnvs = append(defaultEnvs, env)
3123+
} else {
3124+
nonDefaultEnvs = append(nonDefaultEnvs, env)
3125+
}
31013126
}
31023127

3103-
// For onprem users without a valid license, only display default environments on the frontend.
3104-
if hideEnvs && !environment.Default {
3105-
continue
3128+
filteredEnvironments = append(filteredEnvironments, defaultEnvs...)
3129+
limit := int(parentOrgMain.SyncFeatures.MultiEnv.Limit)
3130+
for i, env := range nonDefaultEnvs {
3131+
if i < (limit - 1) {
3132+
filteredEnvironments = append(filteredEnvironments, env)
3133+
}
3134+
}
3135+
3136+
environments = filteredEnvironments
3137+
} else {
3138+
for i := range environments {
3139+
if len(environments[i].Id) == 0 {
3140+
environments[i].Id = uuid.NewV4().String()
3141+
}
31063142
}
3143+
}
31073144

3145+
for _, environment := range environments {
31083146
found := false
31093147
for _, oldEnv := range newEnvironments {
31103148
if oldEnv.Name == environment.Name {
@@ -11784,7 +11822,8 @@ func HandleCreateSubOrg(resp http.ResponseWriter, request *http.Request) {
1178411822
parentOrg.SyncUsage.MultiTenant.Counter = int64(len(childOrgs))
1178511823
}
1178611824

11787-
isLicensed, _ := checkNoInternet()
11825+
license := checkNoInternet()
11826+
isLicensed := license.Valid
1178811827
if !parentOrg.CloudSync && !isLicensed && len(childOrgs) >= 3 {
1178911828
log.Printf("[WARNING] Organization %s has exceeded the free plan limit of 3 sub-organizations. An enterprise license is required to create additional sub-organizations.", parentOrg.Id)
1179011829
resp.WriteHeader(400)
@@ -30758,11 +30797,33 @@ func HandleCheckLicense(ctx context.Context, org Org) Org {
3075830797
syncFeatures, err := GetCache(ctx, cacheKey)
3075930798
if err != nil {
3076030799
log.Printf("[ERROR] Failed to get cache in HandleCheckLicense: %v", err)
30800+
org.SyncFeatures.MultiEnv.Active = false
30801+
org.SyncFeatures.MultiEnv.Limit = 1
30802+
30803+
org.SyncFeatures.MultiTenant.Active = false
30804+
org.SyncFeatures.MultiTenant.Limit = 3
30805+
30806+
org.SyncFeatures.Branding.Active = false
30807+
org.Licensed = false
3076130808
return org
3076230809
}
3076330810
features := SyncFeatures{}
3076430811
if data, ok := syncFeatures.([]byte); ok {
3076530812
if err := json.Unmarshal(data, &features); err == nil {
30813+
licenseCacheKey := fmt.Sprintf("org_licensed_%s", org.Id)
30814+
licensed, err := GetCache(ctx, licenseCacheKey)
30815+
if err != nil {
30816+
org.Licensed = false
30817+
} else if data, ok := licensed.([]byte); ok {
30818+
licenseData := string(data)
30819+
if licenseData == "true" {
30820+
org.Licensed = true
30821+
} else {
30822+
org.Licensed = false
30823+
}
30824+
} else {
30825+
org.Licensed = false
30826+
}
3076630827

3076730828
org.SyncFeatures.MultiEnv.Active = features.MultiEnv.Active
3076830829
org.SyncFeatures.MultiEnv.Limit = features.MultiEnv.Limit
@@ -30843,14 +30904,17 @@ func HandleCheckLicense(ctx context.Context, org Org) Org {
3084330904

3084430905
} else if len(shuffleLicenseKey) > 0 {
3084530906

30846-
license, timeout := checkNoInternet()
30847-
if license == true {
30848-
org.SyncFeatures.MultiEnv.Limit = 100
30849-
org.SyncFeatures.MultiEnv.Active = true
30907+
license := checkNoInternet()
30908+
if license.Valid == true {
30909+
30910+
org.Licensed = true
3085030911

30851-
org.SyncFeatures.MultiTenant.Limit = 1000
30852-
org.SyncFeatures.MultiTenant.Active = true
30853-
org.SyncFeatures.Branding.Active = true
30912+
org.SyncFeatures.MultiEnv.Limit = license.Environment.Limit
30913+
org.SyncFeatures.MultiEnv.Active = license.Environment.Active
30914+
30915+
org.SyncFeatures.MultiTenant.Limit = license.Tenant.Limit
30916+
org.SyncFeatures.MultiTenant.Active = license.Tenant.Active
30917+
org.SyncFeatures.Branding.Active = license.Branding
3085430918

3085530919
org.SyncFeatures.AppExecutions.Active = true
3085630920
org.SyncFeatures.Webhook.Active = true
@@ -30868,6 +30932,15 @@ func HandleCheckLicense(ctx context.Context, org Org) Org {
3086830932
org.SyncFeatures.Schedule.Active = true
3086930933
org.SyncFeatures.Apps.Active = true
3087030934
org.SyncFeatures.ShuffleGPT.Active = true
30935+
} else {
30936+
org.Licensed = false
30937+
org.SyncFeatures.MultiEnv.Limit = 1
30938+
org.SyncFeatures.MultiEnv.Active = false
30939+
30940+
org.SyncFeatures.MultiTenant.Limit = 3
30941+
org.SyncFeatures.MultiTenant.Active = false
30942+
30943+
org.SyncFeatures.Branding.Active = false
3087130944
}
3087230945

3087330946
parsedEula := GetOnpremPaidEula()
@@ -30893,8 +30966,8 @@ func HandleCheckLicense(ctx context.Context, org Org) Org {
3089330966
"Custom Contract",
3089430967
}
3089530968

30896-
if license {
30897-
parsedTimeout, err := time.Parse("02-01-2006", timeout)
30969+
if license.Valid {
30970+
parsedTimeout, err := time.Parse("02-01-2006", license.Timeout)
3089830971
if err != nil {
3089930972
log.Printf("[ERROR] Failed parsing license timeout: %s", err)
3090030973
parsedTimeout = time.Now()
@@ -30930,6 +31003,8 @@ func HandleCheckLicense(ctx context.Context, org Org) Org {
3093031003

3093131004
} else {
3093231005
log.Printf("[WARNING] Org %v does not have an enterprise license. Please purchase an enterprise license to unlock production-ready features. Contact [email protected] for more information.", org.Id)
31006+
31007+
org.Licensed = false
3093331008
org.SyncFeatures.MultiEnv.Limit = 1
3093431009
org.SyncFeatures.MultiEnv.Active = false
3093531010

structs.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ type RetStruct struct {
146146
SessionKey string `json:"session_key"`
147147
IntervalSeconds int64 `json:"interval_seconds"`
148148
Subscriptions []PaymentSubscription `json:"subscriptions,omitempty"`
149+
Licensed bool `json:"licensed"`
149150
}
150151

151152
type AppMini struct {
@@ -996,6 +997,19 @@ type UsecaseInfo struct {
996997
Created int64 `datastore:"created" json:"created"`
997998
}
998999

1000+
type OnpremLimits struct {
1001+
Limit int64 `json:"limit" datastore:"limit"`
1002+
Active bool `json:"active" datastore:"active"`
1003+
}
1004+
1005+
type OnpremLicense struct {
1006+
Valid bool `json:"valid" datastore:"valid"`
1007+
Tenant OnpremLimits `json:"tenant" datastore:"tenant"`
1008+
Environment OnpremLimits `json:"environment" datastore:"environment"`
1009+
Timeout string `json:"timeout" datastore:"timeout"`
1010+
Branding bool `json:"branding" datastore:"branding"`
1011+
}
1012+
9991013
type Org struct {
10001014
Name string `json:"name" datastore:"name"`
10011015
Description string `json:"description" datastore:"description"`
@@ -1045,6 +1059,7 @@ type Org struct {
10451059
Billing Billing `json:"Billing" datastore:"Billing"`
10461060
CreatorOrg string `json:"creator_org" datastore:"creator_org"`
10471061
Branding OrgBranding `json:"branding" datastore:"branding"`
1062+
Licensed bool `json:"licensed" datastore:"licensed"` //Track onprem license
10481063
}
10491064

10501065
type Billing struct {

0 commit comments

Comments
 (0)