Skip to content

Commit 01d8549

Browse files
committed
fix: remove logger
1 parent 5b53522 commit 01d8549

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

src/keys/get-management-token.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
GetManagementTokenOptions,
1111
} from './get-management-token'
1212
import { HttpError } from '../utils'
13-
import { Logger } from '../utils'
13+
// import { Logger } from '../utils'
1414
import { sign } from 'jsonwebtoken'
1515
import { LRUCache } from 'lru-cache'
1616

@@ -24,7 +24,7 @@ const DEFAULT_OPTIONS: GetManagementTokenOptions = {
2424
environmentId: ENVIRONMENT_ID,
2525
reuseToken: false,
2626
}
27-
const noop = () => {}
27+
// const noop = () => {}
2828

2929
const defaultCache: LRUCache<string, string> = new LRUCache({ max: 10 })
3030
let fetchStub: sinon.SinonStub
@@ -40,10 +40,10 @@ afterEach(() => {
4040
describe('getManagementToken', () => {
4141
it('fetches a token', async () => {
4242
const mockToken = 'token'
43-
const logger = noop as unknown as Logger
43+
// const logger = noop as unknown as Logger
4444
fetchStub.resolves({ ok: true, status: 201, json: () => Promise.resolve({ token: mockToken }) })
4545
const getManagementToken = createGetManagementToken(
46-
logger,
46+
// logger,
4747
{ prefixUrl: '', retry: { limit: 0 } },
4848
defaultCache,
4949
)
@@ -62,14 +62,14 @@ describe('getManagementToken', () => {
6262
})
6363

6464
it('caches token while valid', async () => {
65-
const logger = noop as unknown as Logger
65+
// const logger = noop as unknown as Logger
6666
const mockToken = sign({ a: 'b' }, 'a-secret-key', {
6767
expiresIn: '10 minutes',
6868
})
6969

7070
fetchStub.resolves({ ok: true, status: 201, json: () => Promise.resolve({ token: mockToken }) })
7171
const getManagementToken = createGetManagementToken(
72-
logger,
72+
// logger,
7373
{ prefixUrl: '', retry: { limit: 0 } },
7474
defaultCache,
7575
)
@@ -84,15 +84,15 @@ describe('getManagementToken', () => {
8484
})
8585

8686
it('does not cache expired token', async () => {
87-
const logger = noop as unknown as Logger
87+
// const logger = noop as unknown as Logger
8888
const mockToken = sign({ a: 'b' }, 'a-secret-key', {
8989
expiresIn: '5 minutes',
9090
})
9191

9292
fetchStub.resolves({ ok: true, status: 201, json: () => Promise.resolve({ token: mockToken }) })
9393
const cache: LRUCache<string, string> = new LRUCache({ max: 10 })
9494
const getManagementToken = createGetManagementToken(
95-
logger,
95+
// logger,
9696
{ prefixUrl: '', retry: { limit: 0 } },
9797
cache,
9898
)
@@ -118,14 +118,14 @@ describe('getManagementToken', () => {
118118
describe('when using a keyId', () => {
119119
it('fetches a token', async () => {
120120
const mockToken = 'token'
121-
const logger = noop as unknown as Logger
121+
// const logger = noop as unknown as Logger
122122
fetchStub.resolves({
123123
ok: true,
124124
status: 201,
125125
json: () => Promise.resolve({ token: mockToken }),
126126
})
127127
const getManagementToken = createGetManagementToken(
128-
logger,
128+
// logger,
129129
{ prefixUrl: '', retry: { limit: 0 } },
130130
defaultCache,
131131
)
@@ -158,10 +158,10 @@ describe('getManagementToken', () => {
158158

159159
describe('when having API problems', () => {
160160
it(`throws when API returns an error`, async () => {
161-
const logger = noop as unknown as Logger
161+
// const logger = noop as unknown as Logger
162162
fetchStub.rejects(new HttpError({ statusCode: 500 } as unknown as Response))
163163
const getManagementToken = createGetManagementToken(
164-
logger,
164+
// logger,
165165
{ prefixUrl: '', retry: { limit: 0 } },
166166
defaultCache,
167167
)

src/keys/get-management-token.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as jwtImpl from 'jsonwebtoken'
22
import type { SignOptions } from 'jsonwebtoken'
33
import { LRUCache } from 'lru-cache'
4-
import { createLogger, Logger, createValidateStatusCode } from '../utils'
4+
import { createValidateStatusCode } from '../utils'
55
import { FetchOptions, makeRequest, withDefaultOptions, withHook, withRetry } from '../utils/http'
66

77
const jwt = 'default' in jwtImpl ? jwtImpl.default : jwtImpl
@@ -24,18 +24,19 @@ let defaultCache: LRUCache<string, string> | undefined
2424
const generateOneTimeToken = (
2525
privateKey: string,
2626
{ appId, keyId }: { appId: string; keyId?: string },
27-
{ log }: { log: Logger },
27+
// { log }: { log: Logger },
2828
): string => {
29-
log('Signing a JWT token with private key')
29+
// log('Signing a JWT token with private key')
30+
// eslint-disable-next-line no-useless-catch
3031
try {
3132
const baseSignOptions: SignOptions = { algorithm: 'RS256', issuer: appId, expiresIn: '10m' }
3233
const signOptions: SignOptions = keyId ? { ...baseSignOptions, keyid: keyId } : baseSignOptions
3334

3435
const token = sign({}, privateKey, signOptions)
35-
log('Successfully signed token')
36+
// log('Successfully signed token')
3637
return token
3738
} catch (e) {
38-
log('Unable to sign token')
39+
// log('Unable to sign token')
3940
throw e
4041
}
4142
}
@@ -47,11 +48,11 @@ const getTokenFromOneTimeToken = async (
4748
spaceId,
4849
environmentId,
4950
}: { appInstallationId: string; spaceId: string; environmentId: string },
50-
{ log, fetchOptions }: { log: Logger; fetchOptions: FetchOptions },
51+
{ /* log, */ fetchOptions }: { /* log: Logger; */ fetchOptions: FetchOptions },
5152
): Promise<string> => {
5253
const validateStatusCode = createValidateStatusCode([201])
5354

54-
log(`Requesting CMA Token with given App Token`)
55+
// log(`Requesting CMA Token with given App Token`)
5556

5657
const requestor = makeRequest(
5758
`/spaces/${spaceId}/environments/${environmentId}/app_installations/${appInstallationId}/access_tokens`,
@@ -67,9 +68,9 @@ const getTokenFromOneTimeToken = async (
6768
const retryRequestor = withRetry(hookRequestor, fetchOptions)
6869
const response = await retryRequestor()
6970

70-
log(
71-
`Successfully retrieved CMA Token for app ${appInstallationId} in space ${spaceId} and environment ${environmentId}`,
72-
)
71+
// log(
72+
// `Successfully retrieved CMA Token for app ${appInstallationId} in space ${spaceId} and environment ${environmentId}`,
73+
// )
7374

7475
return ((await response.json()) as { token: string }).token
7576
}
@@ -79,7 +80,7 @@ const getTokenFromOneTimeToken = async (
7980
* @internal
8081
*/
8182
export const createGetManagementToken = (
82-
log: Logger,
83+
// log: Logger,
8384
fetchOptions: FetchOptions,
8485
cache: LRUCache<string, string>,
8586
) => {
@@ -104,9 +105,9 @@ export const createGetManagementToken = (
104105
const appToken = generateOneTimeToken(
105106
privateKey,
106107
{ appId: opts.appInstallationId, keyId: opts.keyId },
107-
{ log },
108+
// { log },
108109
)
109-
const ott = await getTokenFromOneTimeToken(appToken, opts, { log, fetchOptions })
110+
const ott = await getTokenFromOneTimeToken(appToken, opts, { /* log, */ fetchOptions })
110111
if (opts.reuseToken) {
111112
const decoded = decode(ott)
112113
if (decoded && typeof decoded === 'object' && decoded.exp) {
@@ -151,7 +152,7 @@ export const getManagementToken = async (privateKey: string, opts: GetManagement
151152
const httpClientOpts = typeof opts.host !== 'undefined' ? { prefixUrl: opts.host } : {}
152153

153154
return createGetManagementToken(
154-
createLogger({ filename: __filename }),
155+
// createLogger({ filename: __filename }),
155156
withDefaultOptions(httpClientOpts),
156157
defaultCache!,
157158
)(privateKey, opts)

0 commit comments

Comments
 (0)