Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[main] [1ds-post] export add header func for auth-plugin to consume #2247

Merged
merged 8 commits into from
Feb 7, 2024
Merged
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
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];
siyuniu-ms marked this conversation as resolved.
Show resolved Hide resolved
};

_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
Loading