-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It turns out that the config handling is quite involved. While trying…
… to move toward #17466 it became clear that the entire config reading layer needed to be concentrated in one place. So this is what this pull request does! Nothing functionally changed; it just starts out by moving all of the config parsing in DatabaseManager out to the config folder. I'll continue on this journey, but the PR would be much too horribly large if this wasn't split into parts :) Signed-off-by: Fredrik Adelöw <freben@gmail.com>
- Loading branch information
Showing
15 changed files
with
495 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@backstage/backend-common': patch | ||
--- | ||
|
||
Internal refactor for config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/backend-common/src/database/config/getAdditionalKnexConfig.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2023 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Config } from '@backstage/config'; | ||
import { Knex } from 'knex'; | ||
import { merge } from 'lodash'; | ||
|
||
/** | ||
* Provides the knexConfig which should be used for a given plugin. | ||
* | ||
* @param config - The database config root | ||
* @param pluginId - Plugin to get the knexConfig for | ||
* @returns The merged knexConfig value or undefined if it isn't specified | ||
*/ | ||
export function getAdditionalKnexConfig( | ||
config: Config, | ||
pluginId: string, | ||
): Partial<Knex.Config> | undefined { | ||
const pluginConfig = config | ||
.getOptionalConfig(`plugin.${pluginId}.knexConfig`) | ||
?.get<Partial<Knex.Config>>(); | ||
|
||
const baseConfig = config | ||
.getOptionalConfig('knexConfig') | ||
?.get<Partial<Knex.Config>>(); | ||
|
||
return merge(baseConfig, pluginConfig); | ||
} |
45 changes: 45 additions & 0 deletions
45
packages/backend-common/src/database/config/getClientType.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2023 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Config } from '@backstage/config'; | ||
|
||
/** | ||
* Provides the client type which should be used for a given plugin. | ||
* | ||
* The client type is determined by plugin specific config if present. | ||
* Otherwise the base client is used as the fallback. | ||
* | ||
* @param config - The database config root | ||
* @param pluginId - Plugin to get the client type for | ||
* @returns Object with client type returned as `client` and boolean | ||
* representing whether or not the client was overridden as | ||
* `overridden` | ||
*/ | ||
export function getClientType( | ||
config: Config, | ||
pluginId: string, | ||
): { | ||
client: string; | ||
overridden: boolean; | ||
} { | ||
const pluginClient = config.getOptionalString(`plugin.${pluginId}.client`); | ||
const baseClient = config.getString('client'); | ||
const client = pluginClient ?? baseClient; | ||
return { | ||
client, | ||
overridden: client !== baseClient, | ||
}; | ||
} |
Oops, something went wrong.