Skip to content

Commit

Permalink
refactor: remove allowed metaSite env (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
MXPOL authored Nov 22, 2023
1 parent 0abfc0e commit ad8fb06
Show file tree
Hide file tree
Showing 23 changed files with 47 additions and 312 deletions.
3 changes: 1 addition & 2 deletions apps/velo-external-db/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ExternalDbRouter, Hooks } from '@wix-velo/velo-external-db-core'
import { engineConnectorFor } from './storage/factory'

const initConnector = async(wixDataBaseUrl?: string, hooks?: Hooks) => {
const { vendor, type: adapterType, allowedMetasites, hideAppInfo } = readCommonConfig()
const { vendor, type: adapterType, hideAppInfo } = readCommonConfig()
const configReader = create()
const { authorization, jwtPublicKey, appDefId, ...dbConfig } = await configReader.readConfig()

Expand All @@ -18,7 +18,6 @@ const initConnector = async(wixDataBaseUrl?: string, hooks?: Hooks) => {
},
jwtPublicKey,
appDefId,
allowedMetasites,
vendor,
adapterType,
commonExtended: true,
Expand Down
22 changes: 11 additions & 11 deletions libs/external-db-config/src/readers/aws_config_reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class AwsConfigReader implements IConfigReader {

async readConfig() {
const { config } = await this.readExternalAndLocalConfig()
const { host, username, password, DB, ALLOWED_METASITES, DB_PORT, JWT_PUBLIC_KEY, APP_DEF_ID } = config
return { host, user: username, password, db: DB, allowedMetasites: ALLOWED_METASITES, port: DB_PORT, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
const { host, username, password, DB, DB_PORT, JWT_PUBLIC_KEY, APP_DEF_ID } = config
return { host, user: username, password, db: DB, port: DB_PORT, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
}

async readExternalConfig() {
Expand All @@ -29,8 +29,8 @@ export class AwsConfigReader implements IConfigReader {

async readExternalAndLocalConfig() {
const { externalConfig, secretMangerError }: {[key: string]: any} = await this.readExternalConfig()
const { host, username, password, DB, ALLOWED_METASITES, HOST, PASSWORD, USER, DB_PORT, JWT_PUBLIC_KEY, APP_DEF_ID }: {[key: string]: string} = { ...process.env, ...externalConfig }
const config = { host: host || HOST, username: username || USER, password: password || PASSWORD, DB, ALLOWED_METASITES, DB_PORT, JWT_PUBLIC_KEY, APP_DEF_ID }
const { host, username, password, DB, HOST, PASSWORD, USER, DB_PORT, JWT_PUBLIC_KEY, APP_DEF_ID }: {[key: string]: string} = { ...process.env, ...externalConfig }
const config = { host: host || HOST, username: username || USER, password: password || PASSWORD, DB, DB_PORT, JWT_PUBLIC_KEY, APP_DEF_ID }
return { config, secretMangerError }
}
}
Expand All @@ -48,13 +48,13 @@ export class AwsDynamoConfigReader implements IConfigReader {
if (process.env['NODE_ENV'] === 'test') {
return { region: this.region, endpoint: process.env['ENDPOINT_URL'], jwtPublicKey: config.JWT_PUBLIC_KEY, appDefId: config.APP_DEF_ID }
}
return { region: this.region, jwtPublicKey: config.JWT_PUBLIC_KEY, appDefId: config.APP_DEF_ID, allowedMetasites: config.ALLOWED_METASITES }
return { region: this.region, jwtPublicKey: config.JWT_PUBLIC_KEY, appDefId: config.APP_DEF_ID }
}

async readExternalAndLocalConfig() {
const { externalConfig, secretMangerError }: {[key: string]: any} = await this.readExternalConfig()
const { ALLOWED_METASITES = undefined, JWT_PUBLIC_KEY = undefined, APP_DEF_ID = undefined } = { ...process.env, ...externalConfig }
const config = { JWT_PUBLIC_KEY, APP_DEF_ID, ALLOWED_METASITES }
const { JWT_PUBLIC_KEY = undefined, APP_DEF_ID = undefined } = { ...process.env, ...externalConfig }
const config = { JWT_PUBLIC_KEY, APP_DEF_ID }

return { config, secretMangerError }
}
Expand Down Expand Up @@ -90,17 +90,17 @@ export class AwsMongoConfigReader implements IConfigReader {

async readExternalAndLocalConfig() {
const { externalConfig, secretMangerError } :{[key: string]: any} = await this.readExternalConfig()
const { ALLOWED_METASITES, URI, JWT_PUBLIC_KEY, APP_DEF_ID }: { ALLOWED_METASITES: string, URI: string, JWT_PUBLIC_KEY: string, APP_DEF_ID: string } = { ...process.env, ...externalConfig }
const config = { ALLOWED_METASITES, URI, JWT_PUBLIC_KEY, APP_DEF_ID }
const { URI, JWT_PUBLIC_KEY, APP_DEF_ID }: { URI: string, JWT_PUBLIC_KEY: string, APP_DEF_ID: string } = { ...process.env, ...externalConfig }
const config = { URI, JWT_PUBLIC_KEY, APP_DEF_ID }

return { config, secretMangerError }
}

async readConfig() {
const { config } = await this.readExternalAndLocalConfig()

const { ALLOWED_METASITES, URI, JWT_PUBLIC_KEY, APP_DEF_ID } = config
const { URI, JWT_PUBLIC_KEY, APP_DEF_ID } = config

return { allowedMetasites: ALLOWED_METASITES, connectionUri: URI, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
return { connectionUri: URI, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
}
}
6 changes: 3 additions & 3 deletions libs/external-db-config/src/readers/azure_config_reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export class AzureConfigReader implements IConfigReader {
}

async readConfig() {
const { HOST, USER, PASSWORD, DB, ALLOWED_METASITES, UNSECURED_ENV, DB_PORT, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
return { host: HOST, user: USER, password: PASSWORD, db: DB, allowedMetasites: ALLOWED_METASITES,
unsecuredEnv: UNSECURED_ENV, port: DB_PORT, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
const { HOST, USER, PASSWORD, DB, UNSECURED_ENV, DB_PORT, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
return { host: HOST, user: USER, password: PASSWORD, db: DB, unsecuredEnv: UNSECURED_ENV, port: DB_PORT,
jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
}
}
4 changes: 2 additions & 2 deletions libs/external-db-config/src/readers/common_config_reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default class CommonConfigReader implements IConfigReader {
constructor() { }

readConfig() {
const { CLOUD_VENDOR, TYPE, REGION, SECRET_NAME, ALLOWED_METASITES, HIDE_APP_INFO } = process.env
return { vendor: CLOUD_VENDOR, type: TYPE, region: REGION, secretId: SECRET_NAME, allowedMetasites: ALLOWED_METASITES, hideAppInfo: HIDE_APP_INFO ? HIDE_APP_INFO === 'true' : undefined }
const { CLOUD_VENDOR, TYPE, REGION, SECRET_NAME, HIDE_APP_INFO } = process.env
return { vendor: CLOUD_VENDOR, type: TYPE, region: REGION, secretId: SECRET_NAME, hideAppInfo: HIDE_APP_INFO ? HIDE_APP_INFO === 'true' : undefined }
}
}
31 changes: 14 additions & 17 deletions libs/external-db-config/src/readers/gcp_config_reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export class GcpConfigReader implements IConfigReader {
}

async readConfig() {
const { CLOUD_SQL_CONNECTION_NAME, USER, PASSWORD, DB, ALLOWED_METASITES, DB_PORT, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
const { CLOUD_SQL_CONNECTION_NAME, USER, PASSWORD, DB, DB_PORT, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
return { cloudSqlConnectionName: CLOUD_SQL_CONNECTION_NAME, user: USER, password: PASSWORD, db: DB,
allowedMetasites: ALLOWED_METASITES, port: DB_PORT, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
port: DB_PORT, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
}

}
Expand All @@ -17,9 +17,8 @@ export class GcpSpannerConfigReader implements IConfigReader {
}

async readConfig() {
const { PROJECT_ID, INSTANCE_ID, DATABASE_ID, ALLOWED_METASITES, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
return { projectId: PROJECT_ID, instanceId: INSTANCE_ID, databaseId: DATABASE_ID,
allowedMetasites: ALLOWED_METASITES, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
const { PROJECT_ID, INSTANCE_ID, DATABASE_ID, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
return { projectId: PROJECT_ID, instanceId: INSTANCE_ID, databaseId: DATABASE_ID, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
}


Expand All @@ -29,8 +28,8 @@ export class GcpFirestoreConfigReader implements IConfigReader {
constructor() { }

async readConfig() {
const { PROJECT_ID, ALLOWED_METASITES, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
return { projectId: PROJECT_ID, allowedMetasites: ALLOWED_METASITES, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
const { PROJECT_ID, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
return { projectId: PROJECT_ID, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
}


Expand All @@ -40,9 +39,9 @@ export class GcpGoogleSheetsConfigReader implements IConfigReader {
constructor() { }

async readConfig() {
const { CLIENT_EMAIL, SHEET_ID, API_PRIVATE_KEY, ALLOWED_METASITES, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
const { CLIENT_EMAIL, SHEET_ID, API_PRIVATE_KEY, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
return { clientEmail: CLIENT_EMAIL, apiPrivateKey: API_PRIVATE_KEY, sheetId: SHEET_ID,
allowedMetasites: ALLOWED_METASITES, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
}

}
Expand All @@ -51,19 +50,18 @@ export class GcpMongoConfigReader implements IConfigReader {
constructor() { }

async readConfig() {
const { URI, ALLOWED_METASITES, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
return { connectionUri: URI, allowedMetasites: ALLOWED_METASITES,
jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
const { URI, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
return { connectionUri: URI, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
}
}

export class GcpAirtableConfigReader implements IConfigReader {
constructor() { }

async readConfig() {
const { AIRTABLE_API_KEY, META_API_KEY, BASE_ID, ALLOWED_METASITES, BASE_URL, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
const { AIRTABLE_API_KEY, META_API_KEY, BASE_ID, BASE_URL, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
return { apiPrivateKey: AIRTABLE_API_KEY, metaApiKey: META_API_KEY, baseId: BASE_ID,
allowedMetasites: ALLOWED_METASITES, baseUrl: BASE_URL, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
baseUrl: BASE_URL, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
}
}

Expand All @@ -72,8 +70,7 @@ export class GcpBigQueryConfigReader implements IConfigReader {
}

async readConfig() {
const { PROJECT_ID, DATABASE_ID, ALLOWED_METASITES, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
return { projectId: PROJECT_ID, databaseId: DATABASE_ID,
allowedMetasites: ALLOWED_METASITES, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
const { PROJECT_ID, DATABASE_ID, JWT_PUBLIC_KEY, APP_DEF_ID } = process.env
return { projectId: PROJECT_ID, databaseId: DATABASE_ID, jwtPublicKey: JWT_PUBLIC_KEY, appDefId: APP_DEF_ID }
}
}
3 changes: 0 additions & 3 deletions libs/external-db-config/src/service/config_validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ describe('Config Reader Client', () => {

test('read config will retrieve config from secret provider and validate retrieved data', async() => {
driver.givenConfig(ctx.config)
driver.givenCommonConfig(ctx.externalDatabaseId, ctx.allowedMetasites)
driver.givenAuthorizationConfig(ctx.authorizationConfig)

expect( env.configValidator.readConfig() ).toEqual(matchers.configResponseFor(ctx.config, ctx.authorizationConfig))
Expand Down Expand Up @@ -86,7 +85,6 @@ describe('Config Reader Client', () => {
missingProperties: Uninitialized,
moreMissingProperties: Uninitialized,
externalDatabaseId: Uninitialized,
allowedMetasites: Uninitialized,
authorizationConfig: Uninitialized,
}

Expand All @@ -104,7 +102,6 @@ describe('Config Reader Client', () => {
ctx.missingProperties = Array.from({ length: 5 }, () => chance.word())
ctx.moreMissingProperties = Array.from({ length: 5 }, () => chance.word())
ctx.externalDatabaseId = chance.guid()
ctx.allowedMetasites = chance.guid()
env.configValidator = new ConfigValidator(driver.configValidator, driver.authorizationConfigValidator, driver.commonConfigValidator)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ describe('MySqlConfigValidator', () => {
expect(env.CommonConfigValidator.validate()).toEqual({ missingRequiredSecretsKeys: [] })
})

test('not extended common config validator will return if externalDatabaseId or allowedMetasites are missing', () => {
test('not extended common config validator will return if jwtPublicKey or appDefId are missing', () => {
env.CommonConfigValidator = new CommonConfigValidator({})
expect(env.CommonConfigValidator.validate()).toEqual({ missingRequiredSecretsKeys: ['jwtPublicKey', 'appDefId', 'allowedMetasites'] })
expect(env.CommonConfigValidator.validate()).toEqual({ missingRequiredSecretsKeys: ['jwtPublicKey', 'appDefId'] })
})

each(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class CommonConfigValidator {

validateBasic() {
return {
missingRequiredSecretsKeys: checkRequiredKeys(this.config, ['jwtPublicKey', 'appDefId', 'allowedMetasites'])
missingRequiredSecretsKeys: checkRequiredKeys(this.config, ['jwtPublicKey', 'appDefId'])
}
}

Expand All @@ -32,7 +32,7 @@ export class CommonConfigValidator {
return {
validType,
validVendor,
missingRequiredSecretsKeys: checkRequiredKeys(this.config, ['type', 'vendor', 'jwtPublicKey', 'appDefId', 'allowedMetasites'])
missingRequiredSecretsKeys: checkRequiredKeys(this.config, ['type', 'vendor', 'jwtPublicKey', 'appDefId'])
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export const defineValidConfig = (config: MongoConfig) => {
if (config.connectionUri) {
awsConfig['URI'] = config.connectionUri
}
if (config.allowedMetasites) {
awsConfig['ALLOWED_METASITES'] = config.allowedMetasites
}
if (config.authorization) {
awsConfig['PERMISSIONS'] = JSON.stringify( config.authorization )
}
Expand All @@ -36,9 +33,6 @@ const defineLocalEnvs = (config: MongoConfig) => {
if (config.connectionUri) {
process.env['URI'] = config.connectionUri
}
if (config.allowedMetasites) {
process.env['ALLOWED_METASITES'] = config.allowedMetasites
}
if (config.authorization) {
process.env['PERMISSIONS'] = JSON.stringify( config.authorization )
}
Expand All @@ -54,7 +48,6 @@ export const defineInvalidConfig = () => defineValidConfig({})

export const validConfig = () => ({
connectionUri: chance.word(),
allowedMetasites: chance.word(),
jwtPublicKey: chance.word(),
appDefId: chance.word(),
})
Expand All @@ -70,8 +63,8 @@ export const validConfigWithAuthorization = () => ({
authorization: validAuthorizationConfig.collectionPermissions
})

export const ExpectedProperties = ['URI', 'ALLOWED_METASITES', 'PERMISSIONS', 'JWT_PUBLIC_KEY', 'APP_DEF_ID']
export const RequiredProperties = ['URI', 'ALLOWED_METASITES', 'JWT_PUBLIC_KEY', 'APP_DEF_ID']
export const ExpectedProperties = ['URI', 'PERMISSIONS', 'JWT_PUBLIC_KEY', 'APP_DEF_ID']
export const RequiredProperties = ['URI', 'JWT_PUBLIC_KEY', 'APP_DEF_ID']

export const reset = () => {
mockedAwsSdk.reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export const defineValidConfig = (config: MySqlConfig) => {
if (config.db) {
awsConfig['DB'] = config.db
}
if (config.allowedMetasites) {
awsConfig['ALLOWED_METASITES'] = config.allowedMetasites
}
if (config.authorization) {
awsConfig['PERMISSIONS'] = JSON.stringify(config.authorization)
}
Expand All @@ -54,9 +51,6 @@ const defineLocalEnvs = (config: MySqlConfig) => {
if (config.db) {
process.env['DB'] = config.db
}
if (config.allowedMetasites) {
process.env['ALLOWED_METASITES'] = config.allowedMetasites
}
if (config.authorization) {
process.env['PERMISSIONS'] = JSON.stringify(config.authorization)
}
Expand All @@ -82,7 +76,6 @@ export const validConfig = (): MySqlConfig => ({
user: chance.word(),
password: chance.word(),
db: chance.word(),
allowedMetasites: chance.word(),
jwtPublicKey: chance.word(),
appDefId: chance.word(),
})
Expand All @@ -103,8 +96,8 @@ export const validConfigWithAuthConfig = () => ({
}
})

export const ExpectedProperties = ['host', 'username', 'password', 'DB', 'ALLOWED_METASITES', 'PERMISSIONS', 'JWT_PUBLIC_KEY', 'APP_DEF_ID']
export const RequiredProperties = ['host', 'username', 'password', 'DB', 'ALLOWED_METASITES', 'JWT_PUBLIC_KEY', 'APP_DEF_ID']
export const ExpectedProperties = ['host', 'username', 'password', 'DB', 'PERMISSIONS', 'JWT_PUBLIC_KEY', 'APP_DEF_ID']
export const RequiredProperties = ['host', 'username', 'password', 'DB', 'JWT_PUBLIC_KEY', 'APP_DEF_ID']

export const reset = () => {
mockedAwsSdk.reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export const defineValidConfig = (config: MySqlConfig) => {
if (config.db) {
process.env['DB'] = config.db
}
if (config.allowedMetasites) {
process.env['ALLOWED_METASITES'] = config.allowedMetasites
}
if (config.authorization) {
process.env['PERMISSIONS'] = JSON.stringify( config.authorization )
}
Expand All @@ -36,7 +33,6 @@ export const validConfig = (): MySqlConfig => ({
user: chance.word(),
password: chance.word(),
db: chance.word(),
allowedMetasites: chance.word(),
jwtPublicKey: chance.word(),
appDefId: chance.word(),
})
Expand All @@ -57,7 +53,7 @@ export const validConfigWithAuthConfig = () => ({

export const defineInvalidConfig = () => defineValidConfig({})

export const ExpectedProperties = ['HOST', 'USER', 'PASSWORD', 'DB', 'ALLOWED_METASITES', 'PERMISSIONS', 'JWT_PUBLIC_KEY', 'APP_DEF_ID']
export const ExpectedProperties = ['HOST', 'USER', 'PASSWORD', 'DB', 'PERMISSIONS', 'JWT_PUBLIC_KEY', 'APP_DEF_ID']

export const reset = () => ExpectedProperties.forEach(p => delete process.env[p])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ export const givenValidConfig = () =>
when(configValidator.validate).calledWith()
.mockReturnValue({ missingRequiredSecretsKeys: [] })

export const givenCommonConfig = (externalDatabaseId: any, allowedMetasites: any) =>
when(commonConfigValidator.readConfig).calledWith()
.mockReturnValue({ externalDatabaseId, allowedMetasites })

export const givenValidCommonConfig = () =>
when(commonConfigValidator.validate).calledWith()
.mockReturnValueOnce({ missingRequiredSecretsKeys: [], validType: true, validVendor: true })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ export const defineValidConfig = (config: FiresStoreConfig) => {
if (config.projectId) {
process.env['PROJECT_ID'] = config.projectId
}
if (config.allowedMetasites) {
process.env['ALLOWED_METASITES'] = config.allowedMetasites
}
if (config.authorization) {
process.env['PERMISSIONS'] = JSON.stringify( config.authorization )
}
Expand All @@ -24,7 +21,6 @@ export const defineValidConfig = (config: FiresStoreConfig) => {

export const validConfig = (): FiresStoreConfig => ({
projectId: chance.word(),
allowedMetasites: chance.word(),
jwtPublicKey: chance.word(),
appDefId: chance.word(),
})
Expand All @@ -45,7 +41,7 @@ export const validConfigWithAuthConfig = () => ({

export const defineInvalidConfig = () => defineValidConfig({})

export const ExpectedProperties = ['PROJECT_ID', 'ALLOWED_METASITES', 'PERMISSIONS', 'JWT_PUBLIC_KEY', 'APP_DEF_ID']
export const ExpectedProperties = ['PROJECT_ID', 'PERMISSIONS', 'JWT_PUBLIC_KEY', 'APP_DEF_ID']

export const reset = () => ExpectedProperties.forEach(p => delete process.env[p])

Expand Down
Loading

0 comments on commit ad8fb06

Please sign in to comment.