mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 10:28:22 +00:00
feat(secret-sync): add PR suggestions for Zabbix secret sync
This commit is contained in:
@@ -46,6 +46,9 @@ const handleZabbixResponse = <T>(response: ZabbixApiResponse<T>): T => {
|
|||||||
const listZabbixSecrets = async (apiToken: string, instanceUrl: string, hostId?: string): Promise<TZabbixSecret[]> => {
|
const listZabbixSecrets = async (apiToken: string, instanceUrl: string, hostId?: string): Promise<TZabbixSecret[]> => {
|
||||||
const apiUrl = `${instanceUrl.replace(TRAILING_SLASH_REGEX, "")}/api_jsonrpc.php`;
|
const apiUrl = `${instanceUrl.replace(TRAILING_SLASH_REGEX, "")}/api_jsonrpc.php`;
|
||||||
|
|
||||||
|
// - jsonrpc: Specifies the JSON-RPC protocol version.
|
||||||
|
// - method: The API method to call, in this case "usermacro.get" for retrieving user macros.
|
||||||
|
// - id: A unique identifier for the request. Required by JSON-RPC but not used by the API for logic. Typically set to any integer.
|
||||||
const payload = {
|
const payload = {
|
||||||
jsonrpc: "2.0" as const,
|
jsonrpc: "2.0" as const,
|
||||||
method: "usermacro.get",
|
method: "usermacro.get",
|
||||||
|
|||||||
+4
-3
@@ -7,6 +7,7 @@ import {
|
|||||||
TZabbixHost,
|
TZabbixHost,
|
||||||
useZabbixConnectionListHosts,
|
useZabbixConnectionListHosts,
|
||||||
ZABBIX_SYNC_SCOPES,
|
ZABBIX_SYNC_SCOPES,
|
||||||
|
ZabbixMacroType,
|
||||||
ZabbixSyncScope
|
ZabbixSyncScope
|
||||||
} from "@app/hooks/api/appConnections/zabbix";
|
} from "@app/hooks/api/appConnections/zabbix";
|
||||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||||
@@ -120,7 +121,7 @@ export const ZabbixSyncFields = () => {
|
|||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="destinationConfig.macroType"
|
name="destinationConfig.macroType"
|
||||||
defaultValue={0}
|
defaultValue={ZabbixMacroType.Secret}
|
||||||
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||||
<FormControl isError={Boolean(error)} errorText={error?.message} label="Macro Type">
|
<FormControl isError={Boolean(error)} errorText={error?.message} label="Macro Type">
|
||||||
<Select
|
<Select
|
||||||
@@ -131,10 +132,10 @@ export const ZabbixSyncFields = () => {
|
|||||||
placeholder="Select a macro type..."
|
placeholder="Select a macro type..."
|
||||||
dropdownContainerClassName="max-w-none"
|
dropdownContainerClassName="max-w-none"
|
||||||
>
|
>
|
||||||
<SelectItem value="0" key="text">
|
<SelectItem value={String(ZabbixMacroType.Text)} key="text">
|
||||||
Text
|
Text
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
<SelectItem value="1" key="secret">
|
<SelectItem value={String(ZabbixMacroType.Secret)} key="secret">
|
||||||
Secret
|
Secret
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
</Select>
|
</Select>
|
||||||
|
|||||||
+7
-3
@@ -1,7 +1,7 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { BaseSecretSyncSchema } from "@app/components/secret-syncs/forms/schemas/base-secret-sync-schema";
|
import { BaseSecretSyncSchema } from "@app/components/secret-syncs/forms/schemas/base-secret-sync-schema";
|
||||||
import { ZabbixSyncScope } from "@app/hooks/api/appConnections/zabbix";
|
import { ZabbixMacroType, ZabbixSyncScope } from "@app/hooks/api/appConnections/zabbix";
|
||||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||||
|
|
||||||
export const ZabbixSyncDestinationSchema = BaseSecretSyncSchema().merge(
|
export const ZabbixSyncDestinationSchema = BaseSecretSyncSchema().merge(
|
||||||
@@ -12,11 +12,15 @@ export const ZabbixSyncDestinationSchema = BaseSecretSyncSchema().merge(
|
|||||||
scope: z.literal(ZabbixSyncScope.Host),
|
scope: z.literal(ZabbixSyncScope.Host),
|
||||||
hostId: z.string().trim().min(1, "Host ID required"),
|
hostId: z.string().trim().min(1, "Host ID required"),
|
||||||
hostName: z.string().trim().min(1, "Host name required"),
|
hostName: z.string().trim().min(1, "Host name required"),
|
||||||
macroType: z.number().min(0, "Macro type required").max(1, "Macro type required")
|
macroType: z.nativeEnum(ZabbixMacroType, {
|
||||||
|
errorMap: () => ({ message: "Macro type must be either 'text' or 'secret'" })
|
||||||
|
})
|
||||||
}),
|
}),
|
||||||
z.object({
|
z.object({
|
||||||
scope: z.literal(ZabbixSyncScope.Global),
|
scope: z.literal(ZabbixSyncScope.Global),
|
||||||
macroType: z.number().min(0, "Macro type required").max(1, "Macro type required")
|
macroType: z.nativeEnum(ZabbixMacroType, {
|
||||||
|
errorMap: () => ({ message: "Macro type must be either 'text' or 'secret'" })
|
||||||
|
})
|
||||||
})
|
})
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ export enum ZabbixSyncScope {
|
|||||||
Global = "global"
|
Global = "global"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ZabbixMacroType {
|
||||||
|
Text = 0,
|
||||||
|
Secret = 1
|
||||||
|
}
|
||||||
|
|
||||||
export const ZABBIX_SYNC_SCOPES = {
|
export const ZABBIX_SYNC_SCOPES = {
|
||||||
[ZabbixSyncScope.Host]: {
|
[ZabbixSyncScope.Host]: {
|
||||||
name: "Host",
|
name: "Host",
|
||||||
|
|||||||
+15
-27
@@ -2,15 +2,7 @@ import { Controller, FormProvider, useForm } from "react-hook-form";
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import {
|
import { Button, FormControl, Input, ModalClose, Select, SelectItem } from "@app/components/v2";
|
||||||
Button,
|
|
||||||
FormControl,
|
|
||||||
Input,
|
|
||||||
ModalClose,
|
|
||||||
SecretInput,
|
|
||||||
Select,
|
|
||||||
SelectItem
|
|
||||||
} from "@app/components/v2";
|
|
||||||
import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections";
|
import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections";
|
||||||
import { TZabbixConnection, ZabbixConnectionMethod } from "@app/hooks/api/appConnections";
|
import { TZabbixConnection, ZabbixConnectionMethod } from "@app/hooks/api/appConnections";
|
||||||
import { AppConnection } from "@app/hooks/api/appConnections/enums";
|
import { AppConnection } from "@app/hooks/api/appConnections/enums";
|
||||||
@@ -93,6 +85,20 @@ export const ZabbixConnectionForm = ({ appConnection, onSubmit }: Props) => {
|
|||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<Controller
|
||||||
|
name="credentials.apiToken"
|
||||||
|
control={control}
|
||||||
|
shouldUnregister
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
errorText={error?.message}
|
||||||
|
isError={Boolean(error?.message)}
|
||||||
|
label="API Token"
|
||||||
|
>
|
||||||
|
<Input {...field} type="password" placeholder="Enter your API Token" />
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
<Controller
|
<Controller
|
||||||
name="credentials.instanceUrl"
|
name="credentials.instanceUrl"
|
||||||
control={control}
|
control={control}
|
||||||
@@ -108,24 +114,6 @@ export const ZabbixConnectionForm = ({ appConnection, onSubmit }: Props) => {
|
|||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<Controller
|
|
||||||
name="credentials.apiToken"
|
|
||||||
control={control}
|
|
||||||
shouldUnregister
|
|
||||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
|
||||||
errorText={error?.message}
|
|
||||||
isError={Boolean(error?.message)}
|
|
||||||
label="Access Token"
|
|
||||||
>
|
|
||||||
<SecretInput
|
|
||||||
containerClassName="text-gray-400 group-focus-within:!border-primary-400/50 border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"
|
|
||||||
value={value}
|
|
||||||
onChange={(e) => onChange(e.target.value)}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<div className="mt-8 flex items-center">
|
<div className="mt-8 flex items-center">
|
||||||
<Button
|
<Button
|
||||||
className="mr-4"
|
className="mr-4"
|
||||||
|
|||||||
Reference in New Issue
Block a user