Skip to content

Commit

Permalink
fix: auth header omitted during asset creation (#772)
Browse files Browse the repository at this point in the history
Co-authored-by: Benedikt T. Arnold <69961360+bearn01d@users.noreply.github.com>
  • Loading branch information
richardtreier and bearn01d authored Jul 23, 2024
1 parent c5d5902 commit 40af45b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ the detailed section referring to by linking pull requests or issues.

#### Patch

- Fixed an issue that caused the auth information to get lost during asset creation.

### Deployment Migration Notes

## [v4.0.0] - 2024-07-15
Expand Down
8 changes: 8 additions & 0 deletions src/app/core/services/asset-data-source-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Injectable} from '@angular/core';
import {UiDataSource} from '@sovity.de/edc-client';
import {AssetDatasourceFormValue} from '../../routes/connector-ui/asset-page/asset-edit-dialog/form/model/asset-datasource-form-model';
import {HttpDatasourceHeaderFormValue} from '../../routes/connector-ui/asset-page/asset-edit-dialog/form/model/http-datasource-header-form-model';
import {getAuthFields} from '../utils/form-value-utils';
import {QueryParamsMapper} from './query-params-mapper';

@Injectable({providedIn: 'root'})
Expand Down Expand Up @@ -53,12 +54,19 @@ export class AssetDataSourceMapper {
formValue.httpQueryParams ?? [],
);

const authFields = getAuthFields(formValue);

return {
type: 'HTTP_DATA',
httpData: {
method: formValue.httpMethod,
baseUrl,
queryString: queryString ?? undefined,
authHeaderName: authFields.authHeaderName ?? undefined,
authHeaderValue: {
secretName: authFields.authHeaderSecretName ?? undefined,
rawValue: authFields.authHeaderValue ?? undefined,
},
headers: this.buildHttpHeaders(formValue.httpHeaders ?? []),
enableMethodParameterization: formValue.httpProxyMethod,
enablePathParameterization: formValue.httpProxyPath,
Expand Down
28 changes: 2 additions & 26 deletions src/app/core/services/transfer-data-sink-mapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Injectable} from '@angular/core';
import {HttpDatasourceHeaderFormValue} from '../../routes/connector-ui/asset-page/asset-edit-dialog/form/model/http-datasource-header-form-model';
import {ContractAgreementTransferDialogFormValue} from '../../routes/connector-ui/contract-agreement-page/contract-agreement-transfer-dialog/contract-agreement-transfer-dialog-form-model';
import {getAuthFields} from '../utils/form-value-utils';
import {mapKeys, removeNullValues} from '../utils/record-utils';
import {DataAddressProperty} from './models/data-address-properties';
import {HttpDataAddressParams} from './models/http-data-address-params';
Expand Down Expand Up @@ -82,7 +83,7 @@ export class TransferDataSinkMapper {
formValue: ContractAgreementTransferDialogFormValue,
): HttpDataAddressParams {
const {authHeaderName, authHeaderValue, authHeaderSecretName} =
this.getAuthFields(formValue);
getAuthFields(formValue);

let method = formValue?.httpMethod?.trim().toUpperCase() || null;

Expand All @@ -105,31 +106,6 @@ export class TransferDataSinkMapper {
};
}

private getAuthFields(
formValue: ContractAgreementTransferDialogFormValue | undefined,
): {
authHeaderName: string | null;
authHeaderValue: string | null;
authHeaderSecretName: string | null;
} {
let authHeaderName: string | null = null;
if (formValue?.httpAuthHeaderType !== 'None') {
authHeaderName = formValue?.httpAuthHeaderName?.trim() || null;
}

let authHeaderValue: string | null = null;
if (authHeaderName && formValue?.httpAuthHeaderType === 'Value') {
authHeaderValue = formValue?.httpAuthHeaderValue?.trim() || null;
}

let authHeaderSecretName: string | null = null;
if (authHeaderName && formValue?.httpAuthHeaderType === 'Vault-Secret') {
authHeaderSecretName =
formValue?.httpAuthHeaderSecretName?.trim() || null;
}
return {authHeaderName, authHeaderValue, authHeaderSecretName};
}

private buildHttpHeaders(
headers: HttpDatasourceHeaderFormValue[],
): Record<string, string> {
Expand Down
29 changes: 29 additions & 0 deletions src/app/core/utils/form-value-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {AssetDatasourceFormValue} from '../../routes/connector-ui/asset-page/asset-edit-dialog/form/model/asset-datasource-form-model';
import {ContractAgreementTransferDialogFormValue} from '../../routes/connector-ui/contract-agreement-page/contract-agreement-transfer-dialog/contract-agreement-transfer-dialog-form-model';

export function getAuthFields(
formValue:
| AssetDatasourceFormValue
| ContractAgreementTransferDialogFormValue
| undefined,
): {
authHeaderName: string | null;
authHeaderValue: string | null;
authHeaderSecretName: string | null;
} {
let authHeaderName: string | null = null;
if (formValue?.httpAuthHeaderType !== 'None') {
authHeaderName = formValue?.httpAuthHeaderName?.trim() || null;
}

let authHeaderValue: string | null = null;
if (authHeaderName && formValue?.httpAuthHeaderType === 'Value') {
authHeaderValue = formValue?.httpAuthHeaderValue?.trim() || null;
}

let authHeaderSecretName: string | null = null;
if (authHeaderName && formValue?.httpAuthHeaderType === 'Vault-Secret') {
authHeaderSecretName = formValue?.httpAuthHeaderSecretName?.trim() || null;
}
return {authHeaderName, authHeaderValue, authHeaderSecretName};
}

0 comments on commit 40af45b

Please sign in to comment.