More fixes
This commit is contained in:
@@ -4,23 +4,13 @@ import { DefaultApi as InfisicalApi } from "../infisicalapi_client";
|
||||
|
||||
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 {
|
||||
sdkAuthenticator: AuthenticatorFunction;
|
||||
apiClient: InfisicalApi;
|
||||
|
||||
constructor(authenticator: AuthenticatorFunction) {
|
||||
constructor(authenticator: AuthenticatorFunction, apiInstance: InfisicalApi) {
|
||||
this.sdkAuthenticator = authenticator;
|
||||
this.apiClient = new InfisicalApi();
|
||||
this.apiClient = apiInstance;
|
||||
}
|
||||
|
||||
universalAuth = {
|
||||
@@ -37,10 +27,3 @@ export default class AuthClient {
|
||||
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 {
|
||||
#apiInstance: InfisicalApi;
|
||||
constructor(private apiInstance: InfisicalApi) {
|
||||
constructor(apiInstance: InfisicalApi) {
|
||||
this.#apiInstance = apiInstance;
|
||||
}
|
||||
|
||||
|
||||
41
src/index.ts
41
src/index.ts
@@ -1,10 +1,22 @@
|
||||
import { Configuration, DefaultApi as InfisicalApi } from "./infisicalapi_client";
|
||||
|
||||
import { DefaultApiApiV1DynamicSecretsLeasesPostRequest } from "./infisicalapi_client";
|
||||
import SecretsClient from "./custom/secrets";
|
||||
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 = {
|
||||
siteUrl?: string;
|
||||
};
|
||||
@@ -16,27 +28,42 @@ class InfisicalSDK {
|
||||
#secretsClient: SecretsClient;
|
||||
#authClient: AuthClient;
|
||||
#basePath: string;
|
||||
#accessToken: string;
|
||||
|
||||
constructor(options?: InfisicalSDKOptions) {
|
||||
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.rest = () => buildRestClient(this.#apiInstance, this.#accessToken);
|
||||
}
|
||||
|
||||
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.#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;
|
||||
}
|
||||
|
||||
secrets = () => this.#secretsClient;
|
||||
auth = () => this.#authClient;
|
||||
rest = () => this.#apiInstance;
|
||||
rest = () => buildRestClient(this.#apiInstance, this.#accessToken);
|
||||
}
|
||||
|
||||
export { InfisicalSDK };
|
||||
|
||||
Reference in New Issue
Block a user