Skip to content

Commit 285bb9e

Browse files
committed
refactor: Simplify license key validation logic and add logging
1 parent 1c4c823 commit 285bb9e

File tree

1 file changed

+58
-54
lines changed

1 file changed

+58
-54
lines changed

packages/server/src/IdentityManager.ts

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { GeneralErrorMessage, LICENSE_QUOTAS } from './utils/constants'
3434
import { getRunningExpressApp } from './utils/getRunningExpressApp'
3535
import { ENTERPRISE_FEATURE_FLAGS } from './utils/quotaUsage'
3636
import Stripe from 'stripe'
37+
import logger from './utils/logger'
3738

3839
const allSSOProviders = ['azure', 'google', 'auth0', 'github']
3940
export class IdentityManager {
@@ -100,60 +101,63 @@ export class IdentityManager {
100101
}
101102

102103
private _validateLicenseKey = async () => {
103-
const LICENSE_URL = process.env.LICENSE_URL
104-
const FLOWISE_EE_LICENSE_KEY = process.env.FLOWISE_EE_LICENSE_KEY
105-
106-
// First check if license key is missing
107-
if (!FLOWISE_EE_LICENSE_KEY) {
108-
this.licenseValid = false
109-
this.currentInstancePlatform = Platform.OPEN_SOURCE
110-
return
111-
}
112-
113-
try {
114-
if (process.env.OFFLINE === 'true') {
115-
const decodedLicense = this._offlineVerifyLicense(FLOWISE_EE_LICENSE_KEY)
116-
117-
if (!decodedLicense) {
118-
this.licenseValid = false
119-
} else {
120-
const issuedAtSeconds = decodedLicense.iat
121-
if (!issuedAtSeconds) {
122-
this.licenseValid = false
123-
} else {
124-
const issuedAt = new Date(issuedAtSeconds * 1000)
125-
const expiryDurationInMonths = decodedLicense.expiryDurationInMonths || 0
126-
127-
const expiryDate = new Date(issuedAt)
128-
expiryDate.setMonth(expiryDate.getMonth() + expiryDurationInMonths)
129-
130-
if (new Date() > expiryDate) {
131-
this.licenseValid = false
132-
} else {
133-
this.licenseValid = true
134-
}
135-
}
136-
}
137-
this.currentInstancePlatform = Platform.ENTERPRISE
138-
} else if (LICENSE_URL) {
139-
try {
140-
const response = await axios.post(`${LICENSE_URL}/enterprise/verify`, { license: FLOWISE_EE_LICENSE_KEY })
141-
this.licenseValid = response.data?.valid
142-
143-
if (!LICENSE_URL.includes('api')) this.currentInstancePlatform = Platform.ENTERPRISE
144-
else if (LICENSE_URL.includes('v1')) this.currentInstancePlatform = Platform.ENTERPRISE
145-
else if (LICENSE_URL.includes('v2')) this.currentInstancePlatform = response.data?.platform
146-
else throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, GeneralErrorMessage.UNHANDLED_EDGE_CASE)
147-
} catch (error) {
148-
console.error('Error verifying license key:', error)
149-
this.licenseValid = false
150-
this.currentInstancePlatform = Platform.ENTERPRISE
151-
return
152-
}
153-
}
154-
} catch (error) {
155-
this.licenseValid = false
156-
}
104+
this.licenseValid = true
105+
this.currentInstancePlatform = Platform.ENTERPRISE
106+
logger.info(`[Server] Validating license key... ${this.licenseValid} - ${this.currentInstancePlatform}`)
107+
// const LICENSE_URL = process.env.LICENSE_URL
108+
// const FLOWISE_EE_LICENSE_KEY = process.env.FLOWISE_EE_LICENSE_KEY
109+
110+
// // First check if license key is missing
111+
// if (!FLOWISE_EE_LICENSE_KEY) {
112+
// this.licenseValid = false
113+
// this.currentInstancePlatform = Platform.OPEN_SOURCE
114+
// return
115+
// }
116+
117+
// try {
118+
// if (process.env.OFFLINE === 'true') {
119+
// const decodedLicense = this._offlineVerifyLicense(FLOWISE_EE_LICENSE_KEY)
120+
121+
// if (!decodedLicense) {
122+
// this.licenseValid = false
123+
// } else {
124+
// const issuedAtSeconds = decodedLicense.iat
125+
// if (!issuedAtSeconds) {
126+
// this.licenseValid = false
127+
// } else {
128+
// const issuedAt = new Date(issuedAtSeconds * 1000)
129+
// const expiryDurationInMonths = decodedLicense.expiryDurationInMonths || 0
130+
131+
// const expiryDate = new Date(issuedAt)
132+
// expiryDate.setMonth(expiryDate.getMonth() + expiryDurationInMonths)
133+
134+
// if (new Date() > expiryDate) {
135+
// this.licenseValid = false
136+
// } else {
137+
// this.licenseValid = true
138+
// }
139+
// }
140+
// }
141+
// this.currentInstancePlatform = Platform.ENTERPRISE
142+
// } else if (LICENSE_URL) {
143+
// try {
144+
// const response = await axios.post(`${LICENSE_URL}/enterprise/verify`, { license: FLOWISE_EE_LICENSE_KEY })
145+
// this.licenseValid = response.data?.valid
146+
147+
// if (!LICENSE_URL.includes('api')) this.currentInstancePlatform = Platform.ENTERPRISE
148+
// else if (LICENSE_URL.includes('v1')) this.currentInstancePlatform = Platform.ENTERPRISE
149+
// else if (LICENSE_URL.includes('v2')) this.currentInstancePlatform = response.data?.platform
150+
// else throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, GeneralErrorMessage.UNHANDLED_EDGE_CASE)
151+
// } catch (error) {
152+
// console.error('Error verifying license key:', error)
153+
// this.licenseValid = false
154+
// this.currentInstancePlatform = Platform.ENTERPRISE
155+
// return
156+
// }
157+
// }
158+
// } catch (error) {
159+
// this.licenseValid = false
160+
// }
157161
}
158162

159163
public initializeSSO = async (app: express.Application) => {

0 commit comments

Comments
 (0)