Skip to content

Commit

Permalink
feat: remove signing key APIs (#1279)
Browse files Browse the repository at this point in the history
These signing key APIs were only ever enabled for some private beta customers;
we have deleted them from most other SDKs, not sure how they survived in here
for so long but this commit removes them. It also allows us to clean up some
weird entanglement between the CacheClient and AbstractCacheClient.
  • Loading branch information
cprice404 authored May 14, 2024
1 parent 8a3aad4 commit ce5a4b9
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 449 deletions.
68 changes: 1 addition & 67 deletions packages/client-sdk-nodejs/src/cache-client.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import {CacheControlClient} from './internal/cache-control-client';
import {CacheDataClient} from './internal/cache-data-client';
import {
CreateSigningKey,
ListSigningKeys,
RevokeSigningKey,
CacheFlush,
MomentoLogger,
Configuration,
Configurations,
} from '.';
import {CacheFlush, MomentoLogger, Configuration, Configurations} from '.';
import {CacheClientProps, EagerCacheClientProps} from './cache-client-props';
import {
range,
Expand Down Expand Up @@ -156,64 +148,6 @@ export class CacheClient extends AbstractCacheClient implements ICacheClient {
public async flushCache(cacheName: string): Promise<CacheFlush.Response> {
return await this.notYetAbstractedControlClient.flushCache(cacheName);
}

/**
* Creates a Momento signing key.
*
* @param {number} ttlMinutes - The time to live in minutes until the Momento
* signing key expires.
* @returns {Promise<CreateSigningKey.Response>} -
* {@link CreateSigningKey.Success} containing the key, key ID, endpoint, and
* expiration date on success.
* {@link CreateSigningKey.Error} on failure.
*/
public async createSigningKey(
ttlMinutes: number
): Promise<CreateSigningKey.Response> {
const client = this.getNextDataClient();
return await this.notYetAbstractedControlClient.createSigningKey(
ttlMinutes,
client.getEndpoint()
);
}

/**
* Revokes a Momento signing key.
*
* @remarks
* All tokens signed by this key will be invalid.
*
* @param {string} keyId - The ID of the key to revoke.
* @returns {Promise<RevokeSigningKey.Response>} -
* {@link RevokeSigningKey.Success} on success.
* {@link RevokeSigningKey.Error} on failure.
*/
public async revokeSigningKey(
keyId: string
): Promise<RevokeSigningKey.Response> {
return await this.notYetAbstractedControlClient.revokeSigningKey(keyId);
}

/**
* Lists all Momento signing keys for the provided auth token.
*
* @returns {Promise<ListSigningKeys.Response>} -
* {@link ListSigningKeys.Success} containing the keys on success.
* {@link ListSigningKeys.Error} on failure.
*/
public async listSigningKeys(): Promise<ListSigningKeys.Response> {
const client = this.getNextDataClient();
return await this.notYetAbstractedControlClient.listSigningKeys(
client.getEndpoint()
);
}

protected getNextDataClient(): CacheDataClient {
const client = this.dataClients[this.nextDataClientIndex];
this.nextDataClientIndex =
(this.nextDataClientIndex + 1) % this.dataClients.length;
return client as CacheDataClient;
}
}

function getDefaultCacheClientConfiguration(): Configuration {
Expand Down
6 changes: 0 additions & 6 deletions packages/client-sdk-nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import * as CacheFlush from '@gomomento/sdk-core/dist/src/messages/responses/cac
import * as CreateCache from '@gomomento/sdk-core/dist/src/messages/responses/create-cache';
import * as DeleteCache from '@gomomento/sdk-core/dist/src/messages/responses/delete-cache';
import * as ListCaches from '@gomomento/sdk-core/dist/src/messages/responses/list-caches';
import * as CreateSigningKey from '@gomomento/sdk-core/dist/src/messages/responses/create-signing-key';
import * as ListSigningKeys from '@gomomento/sdk-core/dist/src/messages/responses/list-signing-keys';
import * as RevokeSigningKey from '@gomomento/sdk-core/dist/src/messages/responses/revoke-signing-key';
import * as CacheSetFetch from '@gomomento/sdk-core/dist/src/messages/responses/cache-set-fetch';
import * as CacheDictionaryFetch from '@gomomento/sdk-core/dist/src/messages/responses/cache-dictionary-fetch';
import * as CacheDictionarySetField from '@gomomento/sdk-core/dist/src/messages/responses/cache-dictionary-set-field';
Expand Down Expand Up @@ -292,9 +289,6 @@ export {
DeleteCache,
ListCaches,
CacheIncrement,
CreateSigningKey,
ListSigningKeys,
RevokeSigningKey,
CacheSetFetch,
CacheDictionaryFetch,
CacheDictionarySetField,
Expand Down
108 changes: 1 addition & 107 deletions packages/client-sdk-nodejs/src/internal/cache-control-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import {
CreateCache,
DeleteCache,
ListCaches,
CreateSigningKey,
ListSigningKeys,
RevokeSigningKey,
CacheFlush,
CredentialProvider,
MomentoLogger,
Expand All @@ -21,11 +18,7 @@ import {version} from '../../package.json';
import {IdleGrpcClientWrapper} from './grpc/idle-grpc-client-wrapper';
import {GrpcClientWrapper} from './grpc/grpc-client-wrapper';
import {Configuration} from '../config/configuration';
import {
validateCacheName,
validateTtlMinutes,
} from '@gomomento/sdk-core/dist/src/internal/utils';
import {_SigningKey} from '@gomomento/sdk-core/dist/src/messages/responses/grpc-response-types';
import {validateCacheName} from '@gomomento/sdk-core/dist/src/internal/utils';
import {
CacheLimits,
TopicLimits,
Expand Down Expand Up @@ -232,103 +225,4 @@ export class CacheControlClient {
});
});
}

public async createSigningKey(
ttlMinutes: number,
endpoint: string
): Promise<CreateSigningKey.Response> {
try {
validateTtlMinutes(ttlMinutes);
} catch (err) {
return this.cacheServiceErrorMapper.returnOrThrowError(
err as Error,
err => new CreateSigningKey.Error(err)
);
}
this.logger.debug("Issuing 'createSigningKey' request");
const request = new grpcControl._CreateSigningKeyRequest();
request.ttl_minutes = ttlMinutes;
return await new Promise<CreateSigningKey.Response>((resolve, reject) => {
this.clientWrapper
.getClient()
.CreateSigningKey(
request,
{interceptors: this.interceptors},
(err, resp) => {
if (err) {
this.cacheServiceErrorMapper.resolveOrRejectError({
err: err,
errorResponseFactoryFn: e => new CreateSigningKey.Error(e),
resolveFn: resolve,
rejectFn: reject,
});
} else {
const signingKey = new _SigningKey(resp?.key, resp?.expires_at);
resolve(new CreateSigningKey.Success(endpoint, signingKey));
}
}
);
});
}

public async revokeSigningKey(
keyId: string
): Promise<RevokeSigningKey.Response> {
const request = new grpcControl._RevokeSigningKeyRequest();
request.key_id = keyId;
this.logger.debug("Issuing 'revokeSigningKey' request");
return await new Promise<RevokeSigningKey.Response>((resolve, reject) => {
this.clientWrapper
.getClient()
.RevokeSigningKey(request, {interceptors: this.interceptors}, err => {
if (err) {
this.cacheServiceErrorMapper.resolveOrRejectError({
err: err,
errorResponseFactoryFn: e => new RevokeSigningKey.Error(e),
resolveFn: resolve,
rejectFn: reject,
});
} else {
resolve(new RevokeSigningKey.Success());
}
});
});
}

public async listSigningKeys(
endpoint: string
): Promise<ListSigningKeys.Response> {
const request = new grpcControl._ListSigningKeysRequest();
request.next_token = '';
this.logger.debug("Issuing 'listSigningKeys' request");
return await new Promise<ListSigningKeys.Response>((resolve, reject) => {
this.clientWrapper
.getClient()
.ListSigningKeys(
request,
{interceptors: this.interceptors},
(err, resp) => {
if (err || !resp) {
this.cacheServiceErrorMapper.resolveOrRejectError({
err: err,
errorResponseFactoryFn: e => new ListSigningKeys.Error(e),
resolveFn: resolve,
rejectFn: reject,
});
} else {
const signingKeys = resp.signing_key.map(
sk => new _SigningKey(sk.key_id, sk.expires_at)
);
resolve(
new ListSigningKeys.Success(
endpoint,
signingKeys,
resp.next_token
)
);
}
}
);
});
}
}
49 changes: 0 additions & 49 deletions packages/client-sdk-nodejs/test/integration/signing-keys.test.ts

This file was deleted.

6 changes: 0 additions & 6 deletions packages/client-sdk-web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import * as CacheFlush from '@gomomento/sdk-core/dist/src/messages/responses/cac
import * as CreateCache from '@gomomento/sdk-core/dist/src/messages/responses/create-cache';
import * as DeleteCache from '@gomomento/sdk-core/dist/src/messages/responses/delete-cache';
import * as ListCaches from '@gomomento/sdk-core/dist/src/messages/responses/list-caches';
import * as CreateSigningKey from '@gomomento/sdk-core/dist/src/messages/responses/create-signing-key';
import * as ListSigningKeys from '@gomomento/sdk-core/dist/src/messages/responses/list-signing-keys';
import * as RevokeSigningKey from '@gomomento/sdk-core/dist/src/messages/responses/revoke-signing-key';
import * as CacheSetFetch from '@gomomento/sdk-core/dist/src/messages/responses/cache-set-fetch';
import * as CacheDictionaryFetch from '@gomomento/sdk-core/dist/src/messages/responses/cache-dictionary-fetch';
import * as CacheDictionarySetField from '@gomomento/sdk-core/dist/src/messages/responses/cache-dictionary-set-field';
Expand Down Expand Up @@ -234,9 +231,6 @@ export {
DeleteCache,
ListCaches,
CacheIncrement,
CreateSigningKey,
ListSigningKeys,
RevokeSigningKey,
CacheSetFetch,
CacheDictionaryFetch,
CacheDictionarySetField,
Expand Down
6 changes: 0 additions & 6 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import * as CacheFlush from './messages/responses/cache-flush';
import * as CreateCache from './messages/responses/create-cache';
import * as DeleteCache from './messages/responses/delete-cache';
import * as ListCaches from './messages/responses/list-caches';
import * as CreateSigningKey from './messages/responses/create-signing-key';
import * as ListSigningKeys from './messages/responses/list-signing-keys';
import * as RevokeSigningKey from './messages/responses/revoke-signing-key';
import * as CacheSetFetch from './messages/responses/cache-set-fetch';
import * as CacheDictionaryFetch from './messages/responses/cache-dictionary-fetch';
import * as CacheDictionarySetField from './messages/responses/cache-dictionary-set-field';
Expand Down Expand Up @@ -235,9 +232,6 @@ export {
DeleteCache,
ListCaches,
CacheIncrement,
CreateSigningKey,
ListSigningKeys,
RevokeSigningKey,
CacheSetFetch,
CacheDictionaryFetch,
CacheDictionarySetField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export abstract class AbstractCacheClient implements ICacheClient {
// TODO: Make pingClient required if and when the nodejs side starts adding
// one as well
protected readonly pingClient?: IPingClient;
protected nextDataClientIndex: number;
private nextDataClientIndex: number;

protected constructor(
controlClient: IControlClient,
Expand Down
Loading

0 comments on commit ce5a4b9

Please sign in to comment.