Skip to content

Commit

Permalink
refactor: move setting of operation id for post session to SessionTok…
Browse files Browse the repository at this point in the history
…enManager

this change fixes pipeline issues caused by recent generator change
  • Loading branch information
mojito317 committed Feb 6, 2025
1 parent 587cfe3 commit 29a1b62
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
11 changes: 10 additions & 1 deletion auth/sessionTokenManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
validateInput,
} from 'ibm-cloud-sdk-core';

import { getSdkHeaders } from '../lib/common';

/** Configuration options for CouchDB session token retrieval. */
export interface SessionTokenManagerOptions extends UserOptions {
/** The username portion of CouchDB session authentication. */
Expand Down Expand Up @@ -92,8 +94,15 @@ export class SessionTokenManager extends TokenManager {
* @returns {Promise}
*/
protected requestToken(): Promise<any> {
const newHeaders = getSdkHeaders(
'cloudant',
'v1',
'authenticatorPostSession'
);
if (!this.options.headers) {
this.options.headers = {};
Object.assign(this.options, { 'headers': newHeaders });
} else {
Object.assign(this.options.headers, newHeaders);
}
// these cannot be overwritten
const parameters = {
Expand Down
12 changes: 0 additions & 12 deletions lib/cloudantBaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
errorResponseInterceptor,
errorResponseStreamConverter,
} from './errorResponseInterceptor';
import { getSdkHeaders } from './common';

/**
* Set default timeout to 2.5 minutes (= 150 000 ms)
Expand Down Expand Up @@ -184,17 +183,6 @@ export default abstract class CloudantBaseService extends BaseService {
private configureSessionAuthenticator() {
const auth: Authenticator = this.getAuthenticator();
if (auth instanceof CouchdbSessionAuthenticator) {
const serviceClass = this.constructor as typeof BaseService;
const newHeaders = getSdkHeaders(
serviceClass.DEFAULT_SERVICE_NAME,
'v1',
'authenticatorPostSession'
);
if (this.baseOptions.headers === undefined) {
Object.assign(this.baseOptions, { 'headers': newHeaders });
} else {
Object.assign(this.baseOptions.headers, newHeaders);
}
(auth as CouchdbSessionAuthenticator).configure(this.baseOptions);
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/unit/sessionTokenManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const assert = require('assert');
const sinon = require('sinon');
const { CookieJar } = require('tough-cookie');
const { SessionTokenManager } = require('../../auth/sessionTokenManager.ts');
const { getSdkHeaders } = require('../../lib/common.ts');

const OPTIONS = Object.freeze({
username: 'username',
Expand Down Expand Up @@ -61,7 +62,7 @@ describe('SessionTokenManager tests', () => {
const sessionUrl = 'cloudant.example/_session';
const expectedParameters = {
options: {
headers: {},
headers: getSdkHeaders('cloudant', 'v1', 'authenticatorPostSession'),
url: sessionUrl,
method: 'POST',
body: {
Expand Down

0 comments on commit 29a1b62

Please sign in to comment.