Repository: kubernetes-client/javascript
Pull request #1038 (2023-04-11 13:12:26)

fix: casing of applyToHttpsOptions
release-1.x forward-port of #1037 

k8s-ci-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-client/javascript/pull/1038#" title="Author self-approved">mstruebing</a>*
**Once this PR has been reviewed and has the lgtm label**, please assign drubin for approval. For more information see [the Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-client%2Fjavascript).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/kubernetes-client/javascript/blob/release-1.x/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["drubin"]} -->
brendandburns: This looks good to me, but I want to let #1033 merge first since it's been waiting a while. You may need to rebase after that.
k8s-ci-robot: PR needs rebase.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
</details>

Patch:
diff --git a/src/config.ts b/src/config.ts
index 7e0a2063..4d6dbead 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -147,8 +147,8 @@ export class KubeConfig implements SecurityAuthentication {
         this.makePathsAbsolute(rootDirectory);
     }
 
-    public async applytoFetchOptions(opts: https.RequestOptions): Promise<RequestInit> {
-        await this.applytoHTTPSOptions(opts);
+    public async applyToFetchOptions(opts: https.RequestOptions): Promise<RequestInit> {
+        await this.applyToHTTPSOptions(opts);
         const headers = new Headers();
         for (const [key, val] of Object.entries(opts.headers || {})) {
             if (Array.isArray(val)) {
@@ -170,7 +170,7 @@ export class KubeConfig implements SecurityAuthentication {
         };
     }
 
-    public async applytoHTTPSOptions(opts: https.RequestOptions): Promise<void> {
+    public async applyToHTTPSOptions(opts: https.RequestOptions): Promise<void> {
         const user = this.getCurrentUser();
 
         await this.applyOptions(opts);
diff --git a/src/log.ts b/src/log.ts
index c33d07ff..b6e3ee05 100644
--- a/src/log.ts
+++ b/src/log.ts
@@ -120,7 +120,7 @@ export class Log {
         searchParams.set('container', containerName);
         AddOptionsToSearchParams(options, searchParams);
 
-        const requestInit = await this.config.applytoFetchOptions({});
+        const requestInit = await this.config.applyToFetchOptions({});
 
         const controller = new AbortControllerCtor();
         requestInit.signal = controller.signal;
diff --git a/src/metrics.ts b/src/metrics.ts
index 73188564..99988809 100644
--- a/src/metrics.ts
+++ b/src/metrics.ts
@@ -84,7 +84,7 @@ export class Metrics {
 
         const requestURL = cluster.server + path;
 
-        const requestInit = await this.config.applytoFetchOptions({});
+        const requestInit = await this.config.applyToFetchOptions({});
         requestInit.method = 'GET';
 
         return fetch(requestURL, requestInit)
diff --git a/src/proto-client.ts b/src/proto-client.ts
index 1d885ca1..e726f339 100644
--- a/src/proto-client.ts
+++ b/src/proto-client.ts
@@ -14,7 +14,7 @@ export class ProtoClient {
             hostname: u.hostname,
             protocol: u.protocol,
         };
-        await this.config.applytoHTTPSOptions(options);
+        await this.config.applyToHTTPSOptions(options);
         const req = http.request(options);
 
         const result = await new Promise<any>((resolve, reject) => {
diff --git a/src/watch.ts b/src/watch.ts
index bd835ad7..57e3921f 100644
--- a/src/watch.ts
+++ b/src/watch.ts
@@ -41,7 +41,7 @@ export class Watch {
             }
         }
 
-        const requestInit = await this.config.applytoFetchOptions({});
+        const requestInit = await this.config.applyToFetchOptions({});
 
         const controller = new AbortControllerCtor();
         requestInit.signal = controller.signal;
diff --git a/src/web-socket-handler.ts b/src/web-socket-handler.ts
index 416369bb..64e9ef3e 100644
--- a/src/web-socket-handler.ts
+++ b/src/web-socket-handler.ts
@@ -166,7 +166,7 @@ export class WebSocketHandler implements WebSocketInterface {
 
         const opts: WebSocket.ClientOptions = {};
 
-        await this.config.applytoHTTPSOptions(opts);
+        await this.config.applyToHTTPSOptions(opts);
 
         return await new Promise<WebSocket>((resolve, reject) => {
             const client = this.socketFactory


Test patch:
diff --git a/src/config_test.ts b/src/config_test.ts
index 97b2539b..d7d79ed6 100644
--- a/src/config_test.ts
+++ b/src/config_test.ts
@@ -254,7 +254,7 @@ describe('KubeConfig', () => {
                     list: ['a', 'b'],
                 },
             };
-            const requestInit = await kc.applytoFetchOptions(opts);
+            const requestInit = await kc.applyToFetchOptions(opts);
             const expectedCA = Buffer.from('CADATA2', 'utf-8');
             const expectedAgent = new https.Agent({
                 ca: expectedCA,
@@ -279,7 +279,7 @@ describe('KubeConfig', () => {
             kc.loadFromFile(kcFileName);
 
             const opts: https.RequestOptions = {};
-            kc.applytoHTTPSOptions(opts);
+            kc.applyToHTTPSOptions(opts);
 
             expect(opts).to.deep.equal({
                 headers: {},
@@ -300,7 +300,7 @@ describe('KubeConfig', () => {
             };
             const rc = new RequestContext(testServerName1, HttpMethod.GET);
             await kc.applySecurityAuthentication(rc);
-            await kc.applytoHTTPSOptions(opts);
+            await kc.applyToHTTPSOptions(opts);
             const expectedCA = Buffer.from('CADATA2', 'utf-8');
             const expectedAgent = new https.Agent({
                 ca: expectedCA,
@@ -705,7 +705,7 @@ describe('KubeConfig', () => {
 
             config.loadFromClusterAndUser({} as Cluster, { username: user, password: passwd } as User);
             const opts = {} as https.RequestOptions;
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
 
             expect(opts.auth).to.equal(`${user}:${passwd}`);
         });
@@ -725,7 +725,7 @@ describe('KubeConfig', () => {
             );
             const opts = {} as RequestOptions;
 
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
 
             /* tslint:disable no-unused-expression*/
             expect(opts.auth).to.not.be.undefined;
@@ -740,7 +740,7 @@ describe('KubeConfig', () => {
             config.loadFromClusterAndUser({ skipTLSVerify: false } as Cluster, {} as User);
             const opts = {} as RequestOptions;
 
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
 
             expect(opts.rejectUnauthorized).to.equal(undefined);
         });
@@ -755,7 +755,7 @@ describe('KubeConfig', () => {
             );
             const opts = {} as RequestOptions;
 
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
             expect(opts.headers).to.not.be.undefined;
             if (opts.headers) {
                 expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -778,14 +778,14 @@ describe('KubeConfig', () => {
             );
             const opts = {} as RequestOptions;
 
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
             expect(opts.headers).to.not.be.undefined;
             if (opts.headers) {
                 expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
             }
             opts.headers = {};
             opts.headers.Host = 'foo.com';
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
             expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
         });
 
@@ -805,7 +805,7 @@ describe('KubeConfig', () => {
             );
             const opts = {} as RequestOptions;
 
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
             expect(opts.headers).to.not.be.undefined;
             if (opts.headers) {
                 expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -828,7 +828,7 @@ describe('KubeConfig', () => {
             );
             const opts = {} as RequestOptions;
 
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
             expect(opts.rejectUnauthorized).to.equal(false);
         });
 
@@ -850,7 +850,7 @@ describe('KubeConfig', () => {
             );
             const opts = {} as RequestOptions;
 
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
             expect(opts.rejectUnauthorized).to.equal(undefined);
         });
 
@@ -869,7 +869,7 @@ describe('KubeConfig', () => {
             );
             const opts = {} as RequestOptions;
 
-            return expect(config.applytoHTTPSOptions(opts)).to.eventually.be.rejectedWith(
+            return expect(config.applyToHTTPSOptions(opts)).to.eventually.be.rejectedWith(
                 'Token is expired!',
             );
         });
@@ -890,7 +890,7 @@ describe('KubeConfig', () => {
                 } as User,
             );
             const opts = {} as RequestOptions;
-            return expect(config.applytoHTTPSOptions(opts)).to.eventually.be.rejectedWith(
+            return expect(config.applyToHTTPSOptions(opts)).to.eventually.be.rejectedWith(
                 /Failed to refresh token/,
             );
         });
@@ -919,7 +919,7 @@ describe('KubeConfig', () => {
                 } as User,
             );
             const opts = {} as RequestOptions;
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
             expect(opts.headers).to.not.be.undefined;
             if (opts.headers) {
                 expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -950,7 +950,7 @@ describe('KubeConfig', () => {
                 } as User,
             );
             const opts = {} as RequestOptions;
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
             expect(opts.headers).to.not.be.undefined;
             if (opts.headers) {
                 expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -980,7 +980,7 @@ describe('KubeConfig', () => {
                 } as User,
             );
             const opts = {} as RequestOptions;
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
             expect(opts.headers).to.not.be.undefined;
             if (opts.headers) {
                 expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -1009,7 +1009,7 @@ describe('KubeConfig', () => {
                 } as User,
             );
             const opts = {} as RequestOptions;
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
             expect(opts.headers).to.not.be.undefined;
             if (opts.headers) {
                 expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -1038,7 +1038,7 @@ describe('KubeConfig', () => {
                 } as User,
             );
             const opts = {} as RequestOptions;
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
             expect(opts.headers).to.not.be.undefined;
             if (opts.headers) {
                 expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -1074,7 +1074,7 @@ describe('KubeConfig', () => {
             );
             // TODO: inject the exec command here and validate env vars?
             const opts = {} as RequestOptions;
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
             expect(opts.headers).to.not.be.undefined;
             if (opts.headers) {
                 expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -1110,7 +1110,7 @@ describe('KubeConfig', () => {
             );
             // TODO: inject the exec command here?
             const opts = {} as RequestOptions;
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
             expect(opts.headers).to.not.be.undefined;
             if (opts.headers) {
                 expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -1141,7 +1141,7 @@ describe('KubeConfig', () => {
             );
             // TODO: inject the exec command here?
             const opts = {} as RequestOptions;
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
             expect(opts.headers).to.not.be.undefined;
             if (opts.headers) {
                 expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
@@ -1173,7 +1173,7 @@ describe('KubeConfig', () => {
             );
             // TODO: inject the exec command here?
             const opts = {} as RequestOptions;
-            await config.applytoHTTPSOptions(opts);
+            await config.applyToHTTPSOptions(opts);
             const execAuthenticator = (KubeConfig as any).authenticators.find(
                 (authenticator) => authenticator instanceof ExecAuth,
             );
@@ -1194,7 +1194,7 @@ describe('KubeConfig', () => {
                 } as User,
             );
             const opts = {} as RequestOptions;
-            return expect(config.applytoHTTPSOptions(opts)).to.eventually.be.rejectedWith(
+            return expect(config.applyToHTTPSOptions(opts)).to.eventually.be.rejectedWith(
                 'No command was specified for exec authProvider!',
             );
         });
@@ -1493,7 +1493,7 @@ describe('KubeConfig', () => {
 
         it('should apply to request', async () => {
             const opts = {} as RequestOptions;
-            await emptyConfig.applytoHTTPSOptions(opts);
+            await emptyConfig.applyToHTTPSOptions(opts);
         });
     });