[Tables] Honor custom HTTP client in transactions (#19470)
* Honor custom HTTP client in transactions * keep credentials * Move to internal tests
This commit is contained in:
Родитель
52df380838
Коммит
1b6b70f4ce
|
@ -87,6 +87,7 @@ export class TableClient {
|
|||
private table: Table;
|
||||
private credential?: NamedKeyCredential | SASCredential | TokenCredential;
|
||||
private transactionClient?: InternalTableTransaction;
|
||||
private clientOptions: TableClientOptions;
|
||||
private readonly allowInsecureConnection: boolean;
|
||||
|
||||
/**
|
||||
|
@ -224,14 +225,13 @@ export class TableClient {
|
|||
const credential = isCredential(credentialOrOptions) ? credentialOrOptions : undefined;
|
||||
this.credential = credential;
|
||||
|
||||
const clientOptions =
|
||||
(!isCredential(credentialOrOptions) ? credentialOrOptions : options) || {};
|
||||
this.clientOptions = (!isCredential(credentialOrOptions) ? credentialOrOptions : options) || {};
|
||||
|
||||
this.allowInsecureConnection = clientOptions.allowInsecureConnection ?? false;
|
||||
clientOptions.endpoint = clientOptions.endpoint || this.url;
|
||||
this.allowInsecureConnection = this.clientOptions.allowInsecureConnection ?? false;
|
||||
this.clientOptions.endpoint = this.clientOptions.endpoint || this.url;
|
||||
|
||||
const internalPipelineOptions: InternalClientPipelineOptions = {
|
||||
...clientOptions,
|
||||
...this.clientOptions,
|
||||
loggingOptions: {
|
||||
logger: logger.info,
|
||||
additionalAllowedHeaderNames: [...TablesLoggingAllowedHeaderNames]
|
||||
|
@ -890,6 +890,7 @@ export class TableClient {
|
|||
partitionKey,
|
||||
transactionId,
|
||||
changesetId,
|
||||
this.clientOptions,
|
||||
new TableClient(this.url, this.tableName),
|
||||
this.credential,
|
||||
this.allowInsecureConnection
|
||||
|
|
|
@ -8,7 +8,8 @@ import {
|
|||
TableTransactionResponse,
|
||||
TransactionAction,
|
||||
UpdateMode,
|
||||
UpdateTableEntityOptions
|
||||
UpdateTableEntityOptions,
|
||||
TableServiceClientOptions
|
||||
} from "./models";
|
||||
import {
|
||||
NamedKeyCredential,
|
||||
|
@ -21,9 +22,9 @@ import {
|
|||
import {
|
||||
OperationOptions,
|
||||
ServiceClient,
|
||||
ServiceClientOptions,
|
||||
serializationPolicy,
|
||||
serializationPolicyName
|
||||
serializationPolicyName,
|
||||
ServiceClientOptions
|
||||
} from "@azure/core-client";
|
||||
import {
|
||||
Pipeline,
|
||||
|
@ -43,7 +44,6 @@ import {
|
|||
transactionRequestAssemblePolicy,
|
||||
transactionRequestAssemblePolicyName
|
||||
} from "./TablePolicies";
|
||||
import { STORAGE_SCOPE } from "./utils/constants";
|
||||
import { SpanStatusCode } from "@azure/core-tracing";
|
||||
import { TableClientLike } from "./utils/internalModels";
|
||||
import { TableServiceErrorOdataError } from "./generated";
|
||||
|
@ -53,6 +53,7 @@ import { getAuthorizationHeader } from "./tablesNamedCredentialPolicy";
|
|||
import { getTransactionHeaders } from "./utils/transactionHeaders";
|
||||
import { isCosmosEndpoint } from "./utils/isCosmosEndpoint";
|
||||
import { signURLWithSAS } from "./tablesSASTokenPolicy";
|
||||
import { STORAGE_SCOPE } from "./utils/constants";
|
||||
|
||||
/**
|
||||
* Helper to build a list of transaction actions
|
||||
|
@ -130,6 +131,7 @@ export class InternalTableTransaction {
|
|||
bodyParts: string[];
|
||||
partitionKey: string;
|
||||
};
|
||||
private clientOptions: TableServiceClientOptions;
|
||||
private interceptClient: TableClientLike;
|
||||
private credential?: NamedKeyCredential | SASCredential | TokenCredential;
|
||||
private allowInsecureConnection: boolean;
|
||||
|
@ -144,10 +146,12 @@ export class InternalTableTransaction {
|
|||
partitionKey: string,
|
||||
transactionId: string,
|
||||
changesetId: string,
|
||||
clientOptions: TableServiceClientOptions,
|
||||
interceptClient: TableClientLike,
|
||||
credential?: NamedKeyCredential | SASCredential | TokenCredential,
|
||||
allowInsecureConnection: boolean = false
|
||||
) {
|
||||
this.clientOptions = clientOptions;
|
||||
this.credential = credential;
|
||||
this.url = url;
|
||||
this.interceptClient = interceptClient;
|
||||
|
@ -275,7 +279,7 @@ export class InternalTableTransaction {
|
|||
this.resetableState.changesetId
|
||||
);
|
||||
|
||||
const options: ServiceClientOptions = {};
|
||||
const options: ServiceClientOptions = this.clientOptions;
|
||||
|
||||
if (isTokenCredential(this.credential)) {
|
||||
options.credentialScopes = STORAGE_SCOPE;
|
||||
|
@ -283,6 +287,7 @@ export class InternalTableTransaction {
|
|||
}
|
||||
|
||||
const client = new ServiceClient(options);
|
||||
|
||||
const headers = getTransactionHeaders(this.resetableState.transactionId);
|
||||
|
||||
const { span, updatedOptions } = createSpan(
|
||||
|
|
|
@ -4,10 +4,12 @@
|
|||
import {
|
||||
PipelineResponse,
|
||||
createHttpHeaders,
|
||||
createPipelineRequest
|
||||
createPipelineRequest,
|
||||
HttpClient
|
||||
} from "@azure/core-rest-pipeline";
|
||||
import { assert } from "chai";
|
||||
import { parseTransactionResponse } from "../../src/TableTransaction";
|
||||
import { TableClient } from "../../src/TableClient";
|
||||
import { parseTransactionResponse, TableTransaction } from "../../src/TableTransaction";
|
||||
|
||||
describe("TableTransaction", () => {
|
||||
describe("parseTransactionResponse", () => {
|
||||
|
@ -47,5 +49,24 @@ describe("TableTransaction", () => {
|
|||
assert.equal(error.code, "123");
|
||||
}
|
||||
});
|
||||
|
||||
it("should honor the custom httpClient passed to the TableClient", async () => {
|
||||
let isProxy = false;
|
||||
const proxyHttpClient: HttpClient = {
|
||||
sendRequest: async (request) => {
|
||||
isProxy = true;
|
||||
return { status: 200, headers: createHttpHeaders(), request };
|
||||
}
|
||||
};
|
||||
const client = new TableClient("https://example.org", "TestTable", {
|
||||
httpClient: proxyHttpClient
|
||||
});
|
||||
const transaction = new TableTransaction();
|
||||
transaction.createEntity({ partitionKey: "helper", rowKey: "1", value: "t1" });
|
||||
transaction.createEntity({ partitionKey: "helper", rowKey: "2", value: "t2" });
|
||||
|
||||
await client.submitTransaction(transaction.actions);
|
||||
assert.isTrue(isProxy);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче