cleanup 🧼
This commit is contained in:
@@ -9,6 +9,7 @@ import type {
|
|||||||
} from "../infisicalapi_client";
|
} from "../infisicalapi_client";
|
||||||
|
|
||||||
import type { TDynamicSecretProvider } from "./schemas/dynamic-secrets";
|
import type { TDynamicSecretProvider } from "./schemas/dynamic-secrets";
|
||||||
|
import { newInfisicalError } from "./errors";
|
||||||
|
|
||||||
type CreateDynamicSecretOptions = Omit<DefaultApiApiV1DynamicSecretsPostRequest["apiV1DynamicSecretsPostRequest"], "provider"> & {
|
type CreateDynamicSecretOptions = Omit<DefaultApiApiV1DynamicSecretsPostRequest["apiV1DynamicSecretsPostRequest"], "provider"> & {
|
||||||
provider: TDynamicSecretProvider;
|
provider: TDynamicSecretProvider;
|
||||||
@@ -23,6 +24,7 @@ export default class DynamicSecretsClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async create(options: CreateDynamicSecretOptions) {
|
async create(options: CreateDynamicSecretOptions) {
|
||||||
|
try {
|
||||||
const res = await this.#apiInstance.apiV1DynamicSecretsPost(
|
const res = await this.#apiInstance.apiV1DynamicSecretsPost(
|
||||||
{
|
{
|
||||||
apiV1DynamicSecretsPostRequest: options as DefaultApiApiV1DynamicSecretsPostRequest["apiV1DynamicSecretsPostRequest"]
|
apiV1DynamicSecretsPostRequest: options as DefaultApiApiV1DynamicSecretsPostRequest["apiV1DynamicSecretsPostRequest"]
|
||||||
@@ -31,9 +33,13 @@ export default class DynamicSecretsClient {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return res.data.dynamicSecret;
|
return res.data.dynamicSecret;
|
||||||
|
} catch (err) {
|
||||||
|
throw newInfisicalError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(dynamicSecretName: string, options: DefaultApiApiV1DynamicSecretsNameDeleteRequest["apiV1DynamicSecretsNameDeleteRequest"]) {
|
async delete(dynamicSecretName: string, options: DefaultApiApiV1DynamicSecretsNameDeleteRequest["apiV1DynamicSecretsNameDeleteRequest"]) {
|
||||||
|
try {
|
||||||
const res = await this.#apiInstance.apiV1DynamicSecretsNameDelete(
|
const res = await this.#apiInstance.apiV1DynamicSecretsNameDelete(
|
||||||
{
|
{
|
||||||
name: dynamicSecretName,
|
name: dynamicSecretName,
|
||||||
@@ -43,10 +49,14 @@ export default class DynamicSecretsClient {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return res.data.dynamicSecret;
|
return res.data.dynamicSecret;
|
||||||
|
} catch (err) {
|
||||||
|
throw newInfisicalError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
leases = {
|
leases = {
|
||||||
create: async (options: DefaultApiApiV1DynamicSecretsLeasesPostRequest["apiV1DynamicSecretsLeasesPostRequest"]) => {
|
create: async (options: DefaultApiApiV1DynamicSecretsLeasesPostRequest["apiV1DynamicSecretsLeasesPostRequest"]) => {
|
||||||
|
try {
|
||||||
const res = await this.#apiInstance.apiV1DynamicSecretsLeasesPost(
|
const res = await this.#apiInstance.apiV1DynamicSecretsLeasesPost(
|
||||||
{
|
{
|
||||||
apiV1DynamicSecretsLeasesPostRequest: options
|
apiV1DynamicSecretsLeasesPostRequest: options
|
||||||
@@ -55,11 +65,15 @@ export default class DynamicSecretsClient {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return res.data;
|
return res.data;
|
||||||
|
} catch (err) {
|
||||||
|
throw newInfisicalError(err);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
delete: async (
|
delete: async (
|
||||||
leaseId: string,
|
leaseId: string,
|
||||||
options: DefaultApiApiV1DynamicSecretsLeasesLeaseIdDeleteRequest["apiV1DynamicSecretsLeasesLeaseIdDeleteRequest"]
|
options: DefaultApiApiV1DynamicSecretsLeasesLeaseIdDeleteRequest["apiV1DynamicSecretsLeasesLeaseIdDeleteRequest"]
|
||||||
) => {
|
) => {
|
||||||
|
try {
|
||||||
const res = await this.#apiInstance.apiV1DynamicSecretsLeasesLeaseIdDelete(
|
const res = await this.#apiInstance.apiV1DynamicSecretsLeasesLeaseIdDelete(
|
||||||
{
|
{
|
||||||
leaseId: leaseId,
|
leaseId: leaseId,
|
||||||
@@ -69,12 +83,16 @@ export default class DynamicSecretsClient {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return res.data;
|
return res.data;
|
||||||
|
} catch (err) {
|
||||||
|
throw newInfisicalError(err);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
renew: async (
|
renew: async (
|
||||||
leaseId: string,
|
leaseId: string,
|
||||||
options: DefaultApiApiV1DynamicSecretsLeasesLeaseIdRenewPostRequest["apiV1DynamicSecretsLeasesLeaseIdRenewPostRequest"]
|
options: DefaultApiApiV1DynamicSecretsLeasesLeaseIdRenewPostRequest["apiV1DynamicSecretsLeasesLeaseIdRenewPostRequest"]
|
||||||
) => {
|
) => {
|
||||||
|
try {
|
||||||
const res = await this.#apiInstance.apiV1DynamicSecretsLeasesLeaseIdRenewPost(
|
const res = await this.#apiInstance.apiV1DynamicSecretsLeasesLeaseIdRenewPost(
|
||||||
{
|
{
|
||||||
leaseId: leaseId,
|
leaseId: leaseId,
|
||||||
@@ -84,6 +102,9 @@ export default class DynamicSecretsClient {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return res.data;
|
return res.data;
|
||||||
|
} catch (err) {
|
||||||
|
throw newInfisicalError(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,6 +165,17 @@ export const AzureEntraIDSchema = z.object({
|
|||||||
clientSecret: z.string().trim().min(1)
|
clientSecret: z.string().trim().min(1)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const LdapSchema = z.object({
|
||||||
|
url: z.string().trim().min(1),
|
||||||
|
binddn: z.string().trim().min(1),
|
||||||
|
bindpass: z.string().trim().min(1),
|
||||||
|
ca: z.string().optional(),
|
||||||
|
|
||||||
|
creationLdif: z.string().min(1),
|
||||||
|
revocationLdif: z.string().min(1),
|
||||||
|
rollbackLdif: z.string().optional()
|
||||||
|
});
|
||||||
|
|
||||||
export enum DynamicSecretProviders {
|
export enum DynamicSecretProviders {
|
||||||
SqlDatabase = "sql-database",
|
SqlDatabase = "sql-database",
|
||||||
Cassandra = "cassandra",
|
Cassandra = "cassandra",
|
||||||
@@ -175,7 +186,8 @@ export enum DynamicSecretProviders {
|
|||||||
ElasticSearch = "elastic-search",
|
ElasticSearch = "elastic-search",
|
||||||
MongoDB = "mongo-db",
|
MongoDB = "mongo-db",
|
||||||
RabbitMq = "rabbit-mq",
|
RabbitMq = "rabbit-mq",
|
||||||
AzureEntraID = "azure-entra-id"
|
AzureEntraID = "azure-entra-id",
|
||||||
|
Ldap = "ldap"
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DynamicSecretProviderSchema = z.discriminatedUnion("type", [
|
export const DynamicSecretProviderSchema = z.discriminatedUnion("type", [
|
||||||
@@ -188,7 +200,8 @@ export const DynamicSecretProviderSchema = z.discriminatedUnion("type", [
|
|||||||
z.object({ type: z.literal(DynamicSecretProviders.ElasticSearch), inputs: DynamicSecretElasticSearchSchema }),
|
z.object({ type: z.literal(DynamicSecretProviders.ElasticSearch), inputs: DynamicSecretElasticSearchSchema }),
|
||||||
z.object({ type: z.literal(DynamicSecretProviders.MongoDB), inputs: DynamicSecretMongoDBSchema }),
|
z.object({ type: z.literal(DynamicSecretProviders.MongoDB), inputs: DynamicSecretMongoDBSchema }),
|
||||||
z.object({ type: z.literal(DynamicSecretProviders.RabbitMq), inputs: DynamicSecretRabbitMqSchema }),
|
z.object({ type: z.literal(DynamicSecretProviders.RabbitMq), inputs: DynamicSecretRabbitMqSchema }),
|
||||||
z.object({ type: z.literal(DynamicSecretProviders.AzureEntraID), inputs: AzureEntraIDSchema })
|
z.object({ type: z.literal(DynamicSecretProviders.AzureEntraID), inputs: AzureEntraIDSchema }),
|
||||||
|
z.object({ type: z.literal(DynamicSecretProviders.Ldap), inputs: LdapSchema })
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export type TDynamicSecretProvider = z.infer<typeof DynamicSecretProviderSchema>;
|
export type TDynamicSecretProvider = z.infer<typeof DynamicSecretProviderSchema>;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { AWS_IDENTITY_DOCUMENT_URI, AWS_TOKEN_METADATA_URI } from "./constants";
|
import { AWS_IDENTITY_DOCUMENT_URI, AWS_TOKEN_METADATA_URI } from "./constants";
|
||||||
import AWS from "aws-sdk";
|
import AWS from "aws-sdk";
|
||||||
|
import { InfisicalSDKError } from "./errors";
|
||||||
|
|
||||||
export const getAwsRegion = async () => {
|
export const getAwsRegion = async () => {
|
||||||
const region = process.env.AWS_REGION; // Typically found in lambda runtime environment
|
const region = process.env.AWS_REGION; // Typically found in lambda runtime environment
|
||||||
@@ -36,13 +37,13 @@ export const performAwsIamLogin = async (region: string) => {
|
|||||||
region
|
region
|
||||||
});
|
});
|
||||||
|
|
||||||
const creds = await new Promise<{ sessionToken?: string; accessKeyId: string; secretAccessKey: string }>((resolve, reject) => {
|
await new Promise<{ sessionToken?: string; accessKeyId: string; secretAccessKey: string }>((resolve, reject) => {
|
||||||
AWS.config.getCredentials((err, res) => {
|
AWS.config.getCredentials((err, res) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
if (!res) {
|
if (!res) {
|
||||||
throw new Error("Credentials not found");
|
throw new InfisicalSDKError("Credentials not found");
|
||||||
}
|
}
|
||||||
return resolve(res);
|
return resolve(res);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class InfisicalSDK {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this.#authClient = new AuthClient(this.authenticate.bind(this), this.#apiInstance, this.#basePath);
|
this.#authClient = new AuthClient(this.authenticate.bind(this), this.#apiInstance);
|
||||||
this.#dynamicSecretsClient = new DynamicSecretsClient(this.#apiInstance, this.#requestOptions);
|
this.#dynamicSecretsClient = new DynamicSecretsClient(this.#apiInstance, this.#requestOptions);
|
||||||
this.#secretsClient = new SecretsClient(this.#apiInstance, this.#requestOptions);
|
this.#secretsClient = new SecretsClient(this.#apiInstance, this.#requestOptions);
|
||||||
this.rest = () => buildRestClient(this.#apiInstance, this.#requestOptions);
|
this.rest = () => buildRestClient(this.#apiInstance, this.#requestOptions);
|
||||||
@@ -61,7 +61,7 @@ class InfisicalSDK {
|
|||||||
this.rest = () => buildRestClient(this.#apiInstance, this.#requestOptions);
|
this.rest = () => buildRestClient(this.#apiInstance, this.#requestOptions);
|
||||||
this.#secretsClient = new SecretsClient(this.#apiInstance, this.#requestOptions);
|
this.#secretsClient = new SecretsClient(this.#apiInstance, this.#requestOptions);
|
||||||
this.#dynamicSecretsClient = new DynamicSecretsClient(this.#apiInstance, this.#requestOptions);
|
this.#dynamicSecretsClient = new DynamicSecretsClient(this.#apiInstance, this.#requestOptions);
|
||||||
this.#authClient = new AuthClient(this.authenticate.bind(this), this.#apiInstance, this.#basePath);
|
this.#authClient = new AuthClient(this.authenticate.bind(this), this.#apiInstance, accessToken);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user