mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 14:27:30 +00:00
Small code improvements
This commit is contained in:
+2
-2
@@ -17,7 +17,7 @@ import { AppConnection } from "../app-connection-enums";
|
|||||||
import { AzureClientSecretsConnectionMethod } from "./azure-client-secrets-connection-enums";
|
import { AzureClientSecretsConnectionMethod } from "./azure-client-secrets-connection-enums";
|
||||||
import {
|
import {
|
||||||
ExchangeCodeAzureResponse,
|
ExchangeCodeAzureResponse,
|
||||||
TAzureClientSecretsConnectionAccessTokenCredentials,
|
TAzureClientSecretsConnectionClientSecretCredentials,
|
||||||
TAzureClientSecretsConnectionConfig,
|
TAzureClientSecretsConnectionConfig,
|
||||||
TAzureClientSecretsConnectionCredentials
|
TAzureClientSecretsConnectionCredentials
|
||||||
} from "./azure-client-secrets-connection-types";
|
} from "./azure-client-secrets-connection-types";
|
||||||
@@ -101,7 +101,7 @@ export const getAzureConnectionAccessToken = async (
|
|||||||
orgId: appConnection.orgId,
|
orgId: appConnection.orgId,
|
||||||
kmsService,
|
kmsService,
|
||||||
encryptedCredentials: appConnection.encryptedCredentials
|
encryptedCredentials: appConnection.encryptedCredentials
|
||||||
})) as TAzureClientSecretsConnectionAccessTokenCredentials;
|
})) as TAzureClientSecretsConnectionClientSecretCredentials;
|
||||||
const { accessToken, expiresAt, clientId, clientSecret, tenantId } = accessTokenCredentials;
|
const { accessToken, expiresAt, clientId, clientSecret, tenantId } = accessTokenCredentials;
|
||||||
if (accessToken && expiresAt && expiresAt > currentTime + 300000) {
|
if (accessToken && expiresAt && expiresAt > currentTime + 300000) {
|
||||||
return accessToken;
|
return accessToken;
|
||||||
|
|||||||
+8
-6
@@ -26,16 +26,18 @@ export const AzureClientSecretsConnectionOAuthOutputCredentialsSchema = z.object
|
|||||||
expiresAt: z.number()
|
expiresAt: z.number()
|
||||||
});
|
});
|
||||||
|
|
||||||
export const AzureClientSecretsConnectionAccessTokenInputCredentialsSchema = z.object({
|
export const AzureClientSecretsConnectionClientSecretInputCredentialsSchema = z.object({
|
||||||
clientId: z
|
clientId: z
|
||||||
.string()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
.min(1, "Client ID required")
|
.min(1, "Client ID required")
|
||||||
|
.max(50, "Client ID must be at most 50 characters long")
|
||||||
.describe(AppConnections.CREDENTIALS.AZURE_CLIENT_SECRETS.clientId),
|
.describe(AppConnections.CREDENTIALS.AZURE_CLIENT_SECRETS.clientId),
|
||||||
clientSecret: z
|
clientSecret: z
|
||||||
.string()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
.min(1, "Client Secret required")
|
.min(1, "Client Secret required")
|
||||||
|
.max(50, "Client Secret must be at most 50 characters long")
|
||||||
.describe(AppConnections.CREDENTIALS.AZURE_CLIENT_SECRETS.clientSecret),
|
.describe(AppConnections.CREDENTIALS.AZURE_CLIENT_SECRETS.clientSecret),
|
||||||
tenantId: z
|
tenantId: z
|
||||||
.string()
|
.string()
|
||||||
@@ -44,7 +46,7 @@ export const AzureClientSecretsConnectionAccessTokenInputCredentialsSchema = z.o
|
|||||||
.describe(AppConnections.CREDENTIALS.AZURE_CLIENT_SECRETS.tenantId)
|
.describe(AppConnections.CREDENTIALS.AZURE_CLIENT_SECRETS.tenantId)
|
||||||
});
|
});
|
||||||
|
|
||||||
export const AzureClientSecretsConnectionAccessTokenOutputCredentialsSchema = z.object({
|
export const AzureClientSecretsConnectionClientSecretOutputCredentialsSchema = z.object({
|
||||||
clientId: z.string(),
|
clientId: z.string(),
|
||||||
clientSecret: z.string(),
|
clientSecret: z.string(),
|
||||||
tenantId: z.string(),
|
tenantId: z.string(),
|
||||||
@@ -65,7 +67,7 @@ export const ValidateAzureClientSecretsConnectionCredentialsSchema = z.discrimin
|
|||||||
method: z
|
method: z
|
||||||
.literal(AzureClientSecretsConnectionMethod.ClientSecret)
|
.literal(AzureClientSecretsConnectionMethod.ClientSecret)
|
||||||
.describe(AppConnections.CREATE(AppConnection.AzureClientSecrets).method),
|
.describe(AppConnections.CREATE(AppConnection.AzureClientSecrets).method),
|
||||||
credentials: AzureClientSecretsConnectionAccessTokenInputCredentialsSchema.describe(
|
credentials: AzureClientSecretsConnectionClientSecretInputCredentialsSchema.describe(
|
||||||
AppConnections.CREATE(AppConnection.AzureClientSecrets).credentials
|
AppConnections.CREATE(AppConnection.AzureClientSecrets).credentials
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -80,7 +82,7 @@ export const UpdateAzureClientSecretsConnectionSchema = z
|
|||||||
credentials: z
|
credentials: z
|
||||||
.union([
|
.union([
|
||||||
AzureClientSecretsConnectionOAuthInputCredentialsSchema,
|
AzureClientSecretsConnectionOAuthInputCredentialsSchema,
|
||||||
AzureClientSecretsConnectionAccessTokenInputCredentialsSchema
|
AzureClientSecretsConnectionClientSecretInputCredentialsSchema
|
||||||
])
|
])
|
||||||
.optional()
|
.optional()
|
||||||
.describe(AppConnections.UPDATE(AppConnection.AzureClientSecrets).credentials)
|
.describe(AppConnections.UPDATE(AppConnection.AzureClientSecrets).credentials)
|
||||||
@@ -100,7 +102,7 @@ export const AzureClientSecretsConnectionSchema = z.intersection(
|
|||||||
}),
|
}),
|
||||||
z.object({
|
z.object({
|
||||||
method: z.literal(AzureClientSecretsConnectionMethod.ClientSecret),
|
method: z.literal(AzureClientSecretsConnectionMethod.ClientSecret),
|
||||||
credentials: AzureClientSecretsConnectionAccessTokenOutputCredentialsSchema
|
credentials: AzureClientSecretsConnectionClientSecretOutputCredentialsSchema
|
||||||
})
|
})
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
@@ -114,7 +116,7 @@ export const SanitizedAzureClientSecretsConnectionSchema = z.discriminatedUnion(
|
|||||||
}),
|
}),
|
||||||
BaseAzureClientSecretsConnectionSchema.extend({
|
BaseAzureClientSecretsConnectionSchema.extend({
|
||||||
method: z.literal(AzureClientSecretsConnectionMethod.ClientSecret),
|
method: z.literal(AzureClientSecretsConnectionMethod.ClientSecret),
|
||||||
credentials: AzureClientSecretsConnectionAccessTokenOutputCredentialsSchema.pick({
|
credentials: AzureClientSecretsConnectionClientSecretOutputCredentialsSchema.pick({
|
||||||
clientId: true,
|
clientId: true,
|
||||||
tenantId: true
|
tenantId: true
|
||||||
})
|
})
|
||||||
|
|||||||
+3
-3
@@ -4,7 +4,7 @@ import { DiscriminativePick } from "@app/lib/types";
|
|||||||
|
|
||||||
import { AppConnection } from "../app-connection-enums";
|
import { AppConnection } from "../app-connection-enums";
|
||||||
import {
|
import {
|
||||||
AzureClientSecretsConnectionAccessTokenOutputCredentialsSchema,
|
AzureClientSecretsConnectionClientSecretOutputCredentialsSchema,
|
||||||
AzureClientSecretsConnectionOAuthOutputCredentialsSchema,
|
AzureClientSecretsConnectionOAuthOutputCredentialsSchema,
|
||||||
AzureClientSecretsConnectionSchema,
|
AzureClientSecretsConnectionSchema,
|
||||||
CreateAzureClientSecretsConnectionSchema,
|
CreateAzureClientSecretsConnectionSchema,
|
||||||
@@ -31,8 +31,8 @@ export type TAzureClientSecretsConnectionCredentials = z.infer<
|
|||||||
typeof AzureClientSecretsConnectionOAuthOutputCredentialsSchema
|
typeof AzureClientSecretsConnectionOAuthOutputCredentialsSchema
|
||||||
>;
|
>;
|
||||||
|
|
||||||
export type TAzureClientSecretsConnectionAccessTokenCredentials = z.infer<
|
export type TAzureClientSecretsConnectionClientSecretCredentials = z.infer<
|
||||||
typeof AzureClientSecretsConnectionAccessTokenOutputCredentialsSchema
|
typeof AzureClientSecretsConnectionClientSecretOutputCredentialsSchema
|
||||||
>;
|
>;
|
||||||
|
|
||||||
export interface ExchangeCodeAzureResponse {
|
export interface ExchangeCodeAzureResponse {
|
||||||
|
|||||||
+2
-4
@@ -205,7 +205,7 @@ export const AzureClientSecretsConnectionForm = ({ appConnection, onSubmit }: Pr
|
|||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
{...field}
|
{...field}
|
||||||
placeholder="e4f34ea5-ad23-4291-8585-66d20d603cc8"
|
placeholder="00000000-0000-0000-0000-000000000000"
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
field.onChange(e.target.value);
|
field.onChange(e.target.value);
|
||||||
setValue("credentials.tenantId", e.target.value);
|
setValue("credentials.tenantId", e.target.value);
|
||||||
@@ -223,12 +223,11 @@ export const AzureClientSecretsConnectionForm = ({ appConnection, onSubmit }: Pr
|
|||||||
control={control}
|
control={control}
|
||||||
render={({ field, fieldState: { error } }) => (
|
render={({ field, fieldState: { error } }) => (
|
||||||
<FormControl
|
<FormControl
|
||||||
tooltipText="Your Azure Client ID."
|
|
||||||
isError={Boolean(error?.message)}
|
isError={Boolean(error?.message)}
|
||||||
label="Client ID"
|
label="Client ID"
|
||||||
errorText={error?.message}
|
errorText={error?.message}
|
||||||
>
|
>
|
||||||
<Input {...field} placeholder="myclientid" />
|
<Input {...field} placeholder="00000000-0000-0000-0000-000000000000" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
@@ -237,7 +236,6 @@ export const AzureClientSecretsConnectionForm = ({ appConnection, onSubmit }: Pr
|
|||||||
control={control}
|
control={control}
|
||||||
render={({ field, fieldState: { error } }) => (
|
render={({ field, fieldState: { error } }) => (
|
||||||
<FormControl
|
<FormControl
|
||||||
tooltipText="Your Azure Client Secret."
|
|
||||||
isError={Boolean(error?.message)}
|
isError={Boolean(error?.message)}
|
||||||
label="Client Secret"
|
label="Client Secret"
|
||||||
errorText={error?.message}
|
errorText={error?.message}
|
||||||
|
|||||||
Reference in New Issue
Block a user