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

remove redis cloud TLS Profile feature #20

Merged
merged 2 commits into from
Dec 6, 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
28 changes: 0 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -849,34 +849,6 @@ const valkey = new Valkey({
});
```


### TLS Profiles

> **Warning**
> TLS profiles described in this section are going to be deprecated in the next major version. Please provide TLS options explicitly.

To make it easier to configure we provide a few pre-configured TLS profiles that can be specified by setting the `tls` option to the profile's name or specifying a `tls.profile` option in case you need to customize some values of the profile.

Profiles:

- `RedisCloudFixed`: Contains the CA for [Redis.com](https://redis.com/) Cloud fixed subscriptions
- `RedisCloudFlexible`: Contains the CA for [Redis.com](https://redis.com/) Cloud flexible subscriptions

```javascript
const valkey = new Valkey({
host: "localhost",
tls: "RedisCloudFixed",
});

const valkeyWithClientCertificate = new Valkey({
host: "localhost",
tls: {
profile: "RedisCloudFixed",
key: "123",
},
});
```

<hr>

## Sentinel
Expand Down
4 changes: 1 addition & 3 deletions lib/Redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
Debug,
isInt,
parseURL,
resolveTLSProfile,
} from "./utils";
import applyMixin from "./utils/applyMixin";
import Commander from "./utils/Commander";
Expand Down Expand Up @@ -558,35 +557,35 @@
});
}

scanStream(options?: ScanStreamOptions) {

Check warning on line 560 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (22.x)

Member scanStream should be declared before all private instance method definitions

Check warning on line 560 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (20.x)

Member scanStream should be declared before all private instance method definitions

Check warning on line 560 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (22.x)

Member scanStream should be declared before all private instance method definitions

Check warning on line 560 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (18.x)

Member scanStream should be declared before all private instance method definitions

Check warning on line 560 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (20.x)

Member scanStream should be declared before all private instance method definitions

Check warning on line 560 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (18.x)

Member scanStream should be declared before all private instance method definitions
return this.createScanStream("scan", { options });
}

scanBufferStream(options?: ScanStreamOptions) {

Check warning on line 564 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (22.x)

Member scanBufferStream should be declared before all private instance method definitions

Check warning on line 564 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (20.x)

Member scanBufferStream should be declared before all private instance method definitions

Check warning on line 564 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (22.x)

Member scanBufferStream should be declared before all private instance method definitions

Check warning on line 564 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (18.x)

Member scanBufferStream should be declared before all private instance method definitions

Check warning on line 564 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (20.x)

Member scanBufferStream should be declared before all private instance method definitions

Check warning on line 564 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (18.x)

Member scanBufferStream should be declared before all private instance method definitions
return this.createScanStream("scanBuffer", { options });
}

sscanStream(key: string, options?: ScanStreamOptions) {

Check warning on line 568 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (22.x)

Member sscanStream should be declared before all private instance method definitions

Check warning on line 568 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (20.x)

Member sscanStream should be declared before all private instance method definitions

Check warning on line 568 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (22.x)

Member sscanStream should be declared before all private instance method definitions

Check warning on line 568 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (18.x)

Member sscanStream should be declared before all private instance method definitions

Check warning on line 568 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (20.x)

Member sscanStream should be declared before all private instance method definitions

Check warning on line 568 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (18.x)

Member sscanStream should be declared before all private instance method definitions
return this.createScanStream("sscan", { key, options });
}

sscanBufferStream(key: string, options?: ScanStreamOptions) {

Check warning on line 572 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (22.x)

Member sscanBufferStream should be declared before all private instance method definitions

Check warning on line 572 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (20.x)

Member sscanBufferStream should be declared before all private instance method definitions

Check warning on line 572 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (22.x)

Member sscanBufferStream should be declared before all private instance method definitions

Check warning on line 572 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (18.x)

Member sscanBufferStream should be declared before all private instance method definitions

Check warning on line 572 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (20.x)

Member sscanBufferStream should be declared before all private instance method definitions

Check warning on line 572 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (18.x)

Member sscanBufferStream should be declared before all private instance method definitions
return this.createScanStream("sscanBuffer", { key, options });
}

hscanStream(key: string, options?: ScanStreamOptions) {

Check warning on line 576 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (22.x)

Member hscanStream should be declared before all private instance method definitions

Check warning on line 576 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (20.x)

Member hscanStream should be declared before all private instance method definitions

Check warning on line 576 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (22.x)

Member hscanStream should be declared before all private instance method definitions

Check warning on line 576 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (18.x)

Member hscanStream should be declared before all private instance method definitions

Check warning on line 576 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (20.x)

Member hscanStream should be declared before all private instance method definitions

Check warning on line 576 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (18.x)

Member hscanStream should be declared before all private instance method definitions
return this.createScanStream("hscan", { key, options });
}

hscanBufferStream(key: string, options?: ScanStreamOptions) {

Check warning on line 580 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (22.x)

Member hscanBufferStream should be declared before all private instance method definitions

Check warning on line 580 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (20.x)

Member hscanBufferStream should be declared before all private instance method definitions

Check warning on line 580 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (22.x)

Member hscanBufferStream should be declared before all private instance method definitions

Check warning on line 580 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (18.x)

Member hscanBufferStream should be declared before all private instance method definitions

Check warning on line 580 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (20.x)

Member hscanBufferStream should be declared before all private instance method definitions

Check warning on line 580 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (18.x)

Member hscanBufferStream should be declared before all private instance method definitions
return this.createScanStream("hscanBuffer", { key, options });
}

zscanStream(key: string, options?: ScanStreamOptions) {

Check warning on line 584 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (22.x)

Member zscanStream should be declared before all private instance method definitions

Check warning on line 584 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (20.x)

Member zscanStream should be declared before all private instance method definitions

Check warning on line 584 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (22.x)

Member zscanStream should be declared before all private instance method definitions

Check warning on line 584 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (18.x)

Member zscanStream should be declared before all private instance method definitions

Check warning on line 584 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (20.x)

Member zscanStream should be declared before all private instance method definitions

Check warning on line 584 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (18.x)

Member zscanStream should be declared before all private instance method definitions
return this.createScanStream("zscan", { key, options });
}

zscanBufferStream(key: string, options?: ScanStreamOptions) {

Check warning on line 588 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (22.x)

Member zscanBufferStream should be declared before all private instance method definitions

Check warning on line 588 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (20.x)

Member zscanBufferStream should be declared before all private instance method definitions

Check warning on line 588 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (22.x)

Member zscanBufferStream should be declared before all private instance method definitions

Check warning on line 588 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (18.x)

Member zscanBufferStream should be declared before all private instance method definitions

Check warning on line 588 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (20.x)

Member zscanBufferStream should be declared before all private instance method definitions

Check warning on line 588 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (18.x)

Member zscanBufferStream should be declared before all private instance method definitions
return this.createScanStream("zscanBuffer", { key, options });
}

Expand All @@ -595,7 +594,7 @@
*
* @ignore
*/
silentEmit(eventName: string, arg?: unknown): boolean {

Check warning on line 597 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (22.x)

Member silentEmit should be declared before all private instance method definitions

Check warning on line 597 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (20.x)

Member silentEmit should be declared before all private instance method definitions

Check warning on line 597 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (22.x)

Member silentEmit should be declared before all private instance method definitions

Check warning on line 597 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (18.x)

Member silentEmit should be declared before all private instance method definitions

Check warning on line 597 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (20.x)

Member silentEmit should be declared before all private instance method definitions

Check warning on line 597 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (18.x)

Member silentEmit should be declared before all private instance method definitions
let error: unknown;
if (eventName === "error") {
error = arg;
Expand Down Expand Up @@ -630,7 +629,7 @@
/**
* @ignore
*/
recoverFromFatalError(

Check warning on line 632 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (22.x)

Member recoverFromFatalError should be declared before all private instance method definitions

Check warning on line 632 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (20.x)

Member recoverFromFatalError should be declared before all private instance method definitions

Check warning on line 632 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (22.x)

Member recoverFromFatalError should be declared before all private instance method definitions

Check warning on line 632 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-valkey (18.x)

Member recoverFromFatalError should be declared before all private instance method definitions

Check warning on line 632 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (20.x)

Member recoverFromFatalError should be declared before all private instance method definitions

Check warning on line 632 in lib/Redis.ts

View workflow job for this annotation

GitHub Actions / test-redis (18.x)

Member recoverFromFatalError should be declared before all private instance method definitions
_commandError: Error,
err: Error,
options: FlushQueueOptions
Expand Down Expand Up @@ -742,8 +741,7 @@
options.db = parseInt(options.db, 10);
}

// @ts-expect-error
this.options = resolveTLSProfile(options);
this.options = options;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/cluster/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseURL, resolveTLSProfile } from "../utils";
import { parseURL } from "../utils";
import { isIP } from "net";
import { SrvRecord } from "dns";

Expand Down Expand Up @@ -67,7 +67,7 @@ export function normalizeNodeOptions(
options.host = "127.0.0.1";
}

return resolveTLSProfile(options);
return options;
});
}

Expand Down
149 changes: 0 additions & 149 deletions lib/constants/TLSProfiles.ts

This file was deleted.

21 changes: 0 additions & 21 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { defaults, noop } from "./lodash";
import { Callback } from "../types";
import Debug from "./debug";

import TLSProfiles from "../constants/TLSProfiles";

/**
* Convert a buffer to string, supports buffer array
*
Expand Down Expand Up @@ -255,25 +253,6 @@ interface TLSOptions {
[key: string]: any;
}

/**
* Resolve TLS profile shortcut in connection options
*/
export function resolveTLSProfile(options: TLSOptions): TLSOptions {
let tls = options?.tls;

if (typeof tls === "string") tls = { profile: tls };

const profile = TLSProfiles[tls?.profile];

if (profile) {
tls = Object.assign({}, profile, tls);
delete tls.profile;
options = Object.assign({}, options, { tls });
}

return options;
}

/**
* Get a random element from `array`
*/
Expand Down
70 changes: 0 additions & 70 deletions test/unit/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as sinon from "sinon";
import { expect } from "chai";
import * as utils from "../../lib/utils";
import TLSProfiles from "../../lib/constants/TLSProfiles";

describe("utils", () => {
describe(".convertBufferToString", () => {
Expand Down Expand Up @@ -206,75 +205,6 @@ describe("utils", () => {
});
});

describe(".resolveTLSProfile", () => {
it("should leave options alone when no tls profile is set", () => {
[
{ host: "localhost", port: 6379 },
{ host: "localhost", port: 6379, tls: true },
{ host: "localhost", port: 6379, tls: false },
{ host: "localhost", port: 6379, tls: "foo" },
{ host: "localhost", port: 6379, tls: {} },
{ host: "localhost", port: 6379, tls: { ca: "foo" } },
{ host: "localhost", port: 6379, tls: { profile: "foo" } },
].forEach((options) => {
expect(utils.resolveTLSProfile(options)).to.eql(options);
});
});

it("should have redis.com profiles defined", () => {
expect(TLSProfiles).to.have.property("RedisCloudFixed");
expect(TLSProfiles).to.have.property("RedisCloudFlexible");
});

it("should read profile from options.tls.profile", () => {
const input = {
host: "localhost",
port: 6379,
tls: { profile: "RedisCloudFixed" },
};
const expected = {
host: "localhost",
port: 6379,
tls: TLSProfiles.RedisCloudFixed,
};

expect(utils.resolveTLSProfile(input)).to.eql(expected);
});

it("should read profile from options.tls", () => {
const input = {
host: "localhost",
port: 6379,
tls: "RedisCloudFixed",
};
const expected = {
host: "localhost",
port: 6379,
tls: TLSProfiles.RedisCloudFixed,
};

expect(utils.resolveTLSProfile(input)).to.eql(expected);
});

it("supports extra options when using options.tls.profile", () => {
const input = {
host: "localhost",
port: 6379,
tls: { profile: "RedisCloudFixed", key: "foo" },
};
const expected = {
host: "localhost",
port: 6379,
tls: {
...TLSProfiles.RedisCloudFixed,
key: "foo",
},
};

expect(utils.resolveTLSProfile(input)).to.eql(expected);
});
});

describe(".sample", () => {
it("should return a random value", () => {
let stub = sinon.stub(Math, "random").callsFake(() => 0);
Expand Down
Loading