Skip to content

Commit

Permalink
When admin config is missing in Databases, now is copied from write c…
Browse files Browse the repository at this point in the history
…onfig
  • Loading branch information
juanhapes committed Mar 14, 2023
1 parent 92e84a4 commit 6445242
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [5.4.5] - 2023-03-14
### Changed
- **Client Creation**. When `admin` config is missing on Databases, the config is now copied from `write`

## [5.4.4] - 2023-01-09
### Fixed
- Client `ListenerRemoved` fixed response
Expand Down
3 changes: 3 additions & 0 deletions lib/helpers/client-formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ module.exports = class ClientFormatter {
if(!dbKeyConfig.write)
dbKeyConfig = { write: dbKeyConfig };

if(!dbKeyConfig.admin)
dbKeyConfig.admin = dbKeyConfig.write;

this.settings[dbKey] = dbKeyConfig;

Object.values(dbKeyConfig)
Expand Down
4 changes: 3 additions & 1 deletion lib/helpers/credentials-fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ module.exports = class CredentialsFetcher {
return this.secretValue
&& this.secretValue.databases
&& this.secretValue.databases[key]
&& this.secretValue.databases[key][accessType];
&& this.secretValue.databases[key][accessType]
? this.secretValue.databases[key][accessType]
: {}; // devuleve un obj vacio porque del otro lado se hace un spread
}

static async fetch() {
Expand Down
7 changes: 2 additions & 5 deletions tests/api-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,8 @@ describe('Client Create API', () => {
stubGetSecret(sinon, {
databases: {
secureDB: {
write: {
host: 'secure-host',
user: 'secure-user',
password: 'secure-password'
}
write: { host: 'secure-host', user: 'secure-user', password: 'secure-password' },
admin: { host: 'secure-host', user: 'secure-user', password: 'secure-password' }
}
}
});
Expand Down
24 changes: 24 additions & 0 deletions tests/helpers/prepare-fake-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@ module.exports = (code, addSecureData = false, addDB = true) => ({
host: 'database-host',
database: `janis-${code}`,
someLimit: 10
},
admin: {
skipFetchCredentials: true,
host: 'database-host',
database: `janis-${code}`,
someLimit: 10
}
},
onlyWriteDB: {
write: {
skipFetchCredentials: true,
host: 'write-database-host',
database: `janis-write-${code}`
},
admin: {
skipFetchCredentials: true,
host: 'write-database-host',
database: `janis-write-${code}`
}
},
completeDB: {
Expand All @@ -30,6 +41,11 @@ module.exports = (code, addSecureData = false, addDB = true) => ({
skipFetchCredentials: true,
host: 'complete-read-database-host',
database: `janis-complete-read-${code}`
},
admin: {
skipFetchCredentials: true,
host: 'complete-write-database-host',
database: `janis-complete-write-${code}`
}
},
secureDB: {
Expand All @@ -40,6 +56,14 @@ module.exports = (code, addSecureData = false, addDB = true) => ({
user: 'secure-user',
password: 'secure-password'
}
},
admin: {
database: `secure-${code}`,
...addSecureData && {
host: 'secure-host',
user: 'secure-user',
password: 'secure-password'
}
}
}
} : {},
Expand Down
7 changes: 2 additions & 5 deletions tests/listener-created.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,8 @@ describe('Client Created Listener', async () => {
stubGetSecret(sinon, {
databases: {
secureDB: {
write: {
host: 'secure-host',
user: 'secure-user',
password: 'secure-password'
}
write: { host: 'secure-host', user: 'secure-user', password: 'secure-password' },
admin: { host: 'secure-host', user: 'secure-user', password: 'secure-password' }
}
}
});
Expand Down

0 comments on commit 6445242

Please sign in to comment.