Skip to content

Commit

Permalink
remove redis cloud TLS Profile feature (#20)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Hunter II <[email protected]>
  • Loading branch information
tlhunter authored Dec 6, 2024
1 parent fc9037d commit 171a0b0
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 273 deletions.
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 @@ import {
Debug,
isInt,
parseURL,
resolveTLSProfile,
} from "./utils";
import applyMixin from "./utils/applyMixin";
import Commander from "./utils/Commander";
Expand Down Expand Up @@ -742,8 +741,7 @@ class Redis extends Commander implements DataHandledable {
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

0 comments on commit 171a0b0

Please sign in to comment.