Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,14 @@
"sslKeyPemPath": {
"description": "Deprecated: Path to SSL private key file (use tls.key instead)",
"type": "string",
"deprecated": true
"deprecated": true,
"x-deprecated-replacement": "tls.key"
},
"sslCertPemPath": {
"description": "Deprecated: Path to SSL certificate file (use tls.cert instead)",
"type": "string",
"deprecated": true
"deprecated": true,
"x-deprecated-replacement": "tls.cert"
},
"configurationSources": {
"enabled": { "type": "boolean" },
Expand Down
39 changes: 28 additions & 11 deletions src/config/deprecatedFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,44 @@
* limitations under the License.
*/

import _ from 'lodash';
import schema from '../../config.schema.json';
import { GitProxyConfig } from './generated/config';

interface SchemaProperty {
deprecated?: boolean;
'x-deprecated-replacement'?: string;
}

const schemaProperties = (schema as { properties: Record<string, SchemaProperty> }).properties;

function isSet(value: unknown): boolean {
return (
value !== undefined && value !== null && (typeof value !== 'string' || value.trim() !== '')
);
}

/**
* Returns deprecation warnings for legacy top-level config keys in user overrides.
* PR 3.0 (#1545) will replace warnings with startup failure for legacy-only configs.
*/
export function getDeprecatedConfigWarnings(userSettings: Partial<GitProxyConfig>): string[] {
const settings = userSettings as Record<string, unknown>;
const warnings: string[] = [];

if (userSettings.sslKeyPemPath?.trim() && !userSettings.tls?.key?.trim()) {
warnings.push('"sslKeyPemPath" is deprecated; use "tls.key" instead (removal in GitProxy 3.0)');
}

if (userSettings.sslCertPemPath?.trim() && !userSettings.tls?.cert?.trim()) {
warnings.push(
'"sslCertPemPath" is deprecated; use "tls.cert" instead (removal in GitProxy 3.0)',
);
}
for (const [key, property] of Object.entries(schemaProperties)) {
if (!property.deprecated || !isSet(settings[key])) {
continue;
}

if (typeof userSettings.proxyUrl === 'string' && userSettings.proxyUrl.trim() !== '') {
warnings.push('"proxyUrl" is deprecated and ignored; remove it before GitProxy 3.0');
const replacement = property['x-deprecated-replacement'];
if (!replacement) {
warnings.push(`"${key}" is deprecated and ignored; remove it before GitProxy 3.0`);
} else if (!isSet(_.get(settings, replacement))) {
warnings.push(
`"${key}" is deprecated; use "${replacement}" instead (removal in GitProxy 3.0)`,
);
}
}

return warnings;
Expand Down
21 changes: 21 additions & 0 deletions test/deprecatedFields.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ describe('getDeprecatedConfigWarnings', () => {
);
});

it('warns for a deprecated field that has no replacement', () => {
expect(getDeprecatedConfigWarnings({ proxyUrl: 'https://github.com' })).toEqual([
'"proxyUrl" is deprecated and ignored; remove it before GitProxy 3.0',
]);
});

it('treats non-string values as set', () => {
expect(getDeprecatedConfigWarnings({ proxyUrl: 0 } as never)).toHaveLength(1);
expect(getDeprecatedConfigWarnings({ proxyUrl: false } as never)).toHaveLength(1);
});

it('stays quiet when the replacement is already set', () => {
expect(
getDeprecatedConfigWarnings({
sslKeyPemPath: 'key.pem',
sslCertPemPath: 'cert.pem',
tls: { enabled: true, key: 'k.pem', cert: 'c.pem' },
}),
).toEqual([]);
});

it('returns no warnings for non-deprecated overrides', () => {
expect(getDeprecatedConfigWarnings({ uiPort: 9000 })).toEqual([]);
expect(
Expand Down