More fixes
This commit is contained in:
@@ -4,23 +4,13 @@ import { DefaultApi as InfisicalApi } from "../infisicalapi_client";
|
|||||||
|
|
||||||
type AuthenticatorFunction = (accessToken: string) => InfisicalSDK;
|
type AuthenticatorFunction = (accessToken: string) => InfisicalSDK;
|
||||||
|
|
||||||
const getAwsRegion = () => {
|
|
||||||
// Implement AWS region retrieval logic here
|
|
||||||
// For simplicity, we'll use an environment variable
|
|
||||||
const region = process.env.AWS_REGION;
|
|
||||||
if (!region) {
|
|
||||||
throw new Error("AWS region not set");
|
|
||||||
}
|
|
||||||
return region;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default class AuthClient {
|
export default class AuthClient {
|
||||||
sdkAuthenticator: AuthenticatorFunction;
|
sdkAuthenticator: AuthenticatorFunction;
|
||||||
apiClient: InfisicalApi;
|
apiClient: InfisicalApi;
|
||||||
|
|
||||||
constructor(authenticator: AuthenticatorFunction) {
|
constructor(authenticator: AuthenticatorFunction, apiInstance: InfisicalApi) {
|
||||||
this.sdkAuthenticator = authenticator;
|
this.sdkAuthenticator = authenticator;
|
||||||
this.apiClient = new InfisicalApi();
|
this.apiClient = apiInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
universalAuth = {
|
universalAuth = {
|
||||||
@@ -37,10 +27,3 @@ export default class AuthClient {
|
|||||||
return this.sdkAuthenticator(token);
|
return this.sdkAuthenticator(token);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
import * as crypto from "crypto";
|
|
||||||
import axios from "axios";
|
|
||||||
import { SignatureV4 } from "@aws-sdk/signature-v4";
|
|
||||||
import { Sha256 } from "@aws-crypto/sha256-js";
|
|
||||||
import { defaultProvider } from "@aws-sdk/credential-provider-node";
|
|
||||||
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ const convertBool = (value: boolean | undefined) => (value ? "true" : "false");
|
|||||||
|
|
||||||
export default class SecretsClient {
|
export default class SecretsClient {
|
||||||
#apiInstance: InfisicalApi;
|
#apiInstance: InfisicalApi;
|
||||||
constructor(private apiInstance: InfisicalApi) {
|
constructor(apiInstance: InfisicalApi) {
|
||||||
this.#apiInstance = apiInstance;
|
this.#apiInstance = apiInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
41
src/index.ts
41
src/index.ts
@@ -1,10 +1,22 @@
|
|||||||
import { Configuration, DefaultApi as InfisicalApi } from "./infisicalapi_client";
|
import { Configuration, DefaultApi as InfisicalApi } from "./infisicalapi_client";
|
||||||
|
import { DefaultApiApiV1DynamicSecretsLeasesPostRequest } from "./infisicalapi_client";
|
||||||
import SecretsClient from "./custom/secrets";
|
import SecretsClient from "./custom/secrets";
|
||||||
import AuthClient from "./custom/auth";
|
import AuthClient from "./custom/auth";
|
||||||
|
|
||||||
// We need to do bind(this) because the authenticate method is a private method, and usually you can't call private methods from outside the class.
|
const buildRestClient = (apiClient: InfisicalApi, accessToken: string) => {
|
||||||
|
const defaultOptions = {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${accessToken}`
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
apiV1DynamicSecretsLeasesPost: (options: DefaultApiApiV1DynamicSecretsLeasesPostRequest) =>
|
||||||
|
apiClient.apiV1DynamicSecretsLeasesPost(options, defaultOptions)
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// We need to do bind(this) because the authenticate method is a private method, and usually you can't call private methods from outside the class.
|
||||||
type InfisicalSDKOptions = {
|
type InfisicalSDKOptions = {
|
||||||
siteUrl?: string;
|
siteUrl?: string;
|
||||||
};
|
};
|
||||||
@@ -16,27 +28,42 @@ class InfisicalSDK {
|
|||||||
#secretsClient: SecretsClient;
|
#secretsClient: SecretsClient;
|
||||||
#authClient: AuthClient;
|
#authClient: AuthClient;
|
||||||
#basePath: string;
|
#basePath: string;
|
||||||
|
#accessToken: string;
|
||||||
|
|
||||||
constructor(options?: InfisicalSDKOptions) {
|
constructor(options?: InfisicalSDKOptions) {
|
||||||
this.#basePath = options?.siteUrl || "https://app.infisical.com";
|
this.#basePath = options?.siteUrl || "https://app.infisical.com";
|
||||||
this.#apiInstance = new InfisicalApi(new Configuration({ basePath: this.#basePath }));
|
this.#accessToken = "";
|
||||||
|
|
||||||
this.#authClient = new AuthClient(this.authenticate.bind(this));
|
this.#apiInstance = new InfisicalApi(
|
||||||
|
new Configuration({
|
||||||
|
basePath: this.#basePath
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
this.#authClient = new AuthClient(this.authenticate.bind(this), this.#apiInstance);
|
||||||
this.#secretsClient = new SecretsClient(this.#apiInstance);
|
this.#secretsClient = new SecretsClient(this.#apiInstance);
|
||||||
|
this.rest = () => buildRestClient(this.#apiInstance, this.#accessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private authenticate(accessToken: string) {
|
private authenticate(accessToken: string) {
|
||||||
this.#apiInstance = new InfisicalApi(new Configuration({ accessToken, basePath: this.#basePath }));
|
this.#apiInstance = new InfisicalApi(
|
||||||
|
new Configuration({
|
||||||
|
basePath: this.#basePath,
|
||||||
|
accessToken
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
this.#accessToken = accessToken;
|
||||||
this.#secretsClient = new SecretsClient(this.#apiInstance);
|
this.#secretsClient = new SecretsClient(this.#apiInstance);
|
||||||
this.#authClient = new AuthClient(this.authenticate.bind(this));
|
this.#authClient = new AuthClient(this.authenticate.bind(this), this.#apiInstance);
|
||||||
|
this.rest = () => buildRestClient(this.#apiInstance, this.#accessToken);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
secrets = () => this.#secretsClient;
|
secrets = () => this.#secretsClient;
|
||||||
auth = () => this.#authClient;
|
auth = () => this.#authClient;
|
||||||
rest = () => this.#apiInstance;
|
rest = () => buildRestClient(this.#apiInstance, this.#accessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { InfisicalSDK };
|
export { InfisicalSDK };
|
||||||
|
|||||||
Reference in New Issue
Block a user