Skip to content

Commit

Permalink
[main] [1ds-post] export add header func for auth-plugin to consume (#…
Browse files Browse the repository at this point in the history
…2247)

* add export

* add remove-header

* Update PostChannel.ts

* change name
  • Loading branch information
siyuniu-ms committed Feb 7, 2024
1 parent 6b10bab commit 6365dad
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
13 changes: 13 additions & 0 deletions channels/1ds-post-js/src/HttpManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,10 @@ export class HttpManager {
_headers[name] = value;
};

_self.removeHeader = (name: string) => {
delete _headers[name];
};

_self.canSendRequest = () => {
return _hasIdleConnection() && _clockSkewManager.allowRequestSending();
};
Expand Down Expand Up @@ -1414,6 +1418,15 @@ export class HttpManager {
// @DynamicProtoStub - DO NOT add any code as this will be removed during packaging
}

/**
* Remove header to request
* @param name - Header name.
* @param value - Header value.
*/
public removeHeader(name: string) {
// @DynamicProtoStub - DO NOT add any code as this will be removed during packaging
}

/**
* Add handler to be executed with request response text.
*/
Expand Down
1 change: 1 addition & 0 deletions channels/1ds-post-js/src/InternalConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const STR_TIME_DELTA_TO_APPLY = "time-delta-to-apply-millis";
export const STR_UPLOAD_TIME = "upload-time";
export const STR_API_KEY = "apikey";
export const STR_MSA_DEVICE_TICKET = "AuthMsaDeviceTicket";
export const STR_AUTH_WEB_TOKEN = "WebAuthToken";
export const STR_AUTH_XTOKEN = "AuthXToken";
export const STR_SDK_VERSION = "sdk-version";
export const STR_NO_RESPONSE_BODY = "NoResponseBody";
Expand Down
28 changes: 27 additions & 1 deletion channels/1ds-post-js/src/PostChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from "./DataModels";
import { EventBatch } from "./EventBatch";
import { HttpManager } from "./HttpManager";
import { STR_MSA_DEVICE_TICKET, STR_TRACE, STR_USER } from "./InternalConstants";
import { STR_AUTH_WEB_TOKEN, STR_MSA_DEVICE_TICKET, STR_TRACE, STR_USER } from "./InternalConstants";
import { retryPolicyGetMillisToBackoffForRetry } from "./RetryPolicy";
import { ITimeoutOverrideWrapper, createTimeoutWrapper } from "./TimeoutOverrideWrapper";

Expand Down Expand Up @@ -546,6 +546,14 @@ export class PostChannel extends BaseTelemetryPlugin implements IChannelControls
_httpManager.addHeader(STR_MSA_DEVICE_TICKET, ticket);
};

_self.setAuthPluginHeader = (token: string) => {
_httpManager.addHeader(STR_AUTH_WEB_TOKEN, token);
};

_self.removeAuthPluginHeader = () => {
_httpManager.removeHeader(STR_AUTH_WEB_TOKEN);
};

_self.hasEvents = _hasEvents;

_self._setTransmitProfile = (profileName: string) => {
Expand All @@ -558,6 +566,7 @@ export class PostChannel extends BaseTelemetryPlugin implements IChannelControls

proxyFunctions(_self, () => _httpManager, [ "addResponseHandler" ]);


/**
* Batch and send events currently in the queue for the given latency.
* @param latency - Latency for which to send events.
Expand Down Expand Up @@ -1194,6 +1203,23 @@ export class PostChannel extends BaseTelemetryPlugin implements IChannelControls
// @DynamicProtoStub - DO NOT add any code as this will be removed during packaging
}

/**
* Set setAuthPluginHeader header
* @param token - token value.
*/
public setAuthPluginHeader(token: string) {
// @DynamicProtoStub - DO NOT add any code as this will be removed during packaging
}

/**
* remove AuthPlugin Header
* @param token - token value.
*/
public removeAuthPluginHeader(token: string) {
// @DynamicProtoStub - DO NOT add any code as this will be removed during packaging
}


/**
* Check if there are any events waiting to be scheduled for sending.
* @returns True if there are events, false otherwise.
Expand Down

0 comments on commit 6365dad

Please sign in to comment.