Showing the changes to plugins/openapi/react (1 of 15 files). Show all
Unified · Split
| @@ -38,7 +38,7 @@ import { · 37 unmodified lines | |||
| 38 | type SourceToolExplorerSearch, | 38 | type SourceToolExplorerSearch, |
| 39 | useSourcePluginNavigation, | 39 | useSourcePluginNavigation, |
| 40 | useSourcePluginSearch, | 40 | useSourcePluginSearch, |
| 41 | } from "@executor/react/source-plugins"; | 41 | } from "@executor/react/plugins"; |
| 42 | import { | 42 | import { |
| 43 | openApiHttpApiExtension, | 43 | openApiHttpApiExtension, |
| 44 | } from "@executor/plugin-openapi-http"; | 44 | } from "@executor/plugin-openapi-http"; |
| @@ -169,6 +169,31 @@ const inputFromConfig = ( · 124 unmodified lines | |||
| 169 | auth: config.auth, | 169 | auth: config.auth, |
| 170 | }); | 170 | }); |
| 171 | 171 | ||
| 172 | const secretValue = (input: OpenApiConnectInput["auth"]): string => | ||
| 173 | input.kind === "bearer" | ||
| 174 | ? JSON.stringify(input.tokenSecretRef) | ||
| 175 | : ""; | ||
| 176 | |||
| 177 | const authFromSecretValue = ( | ||
| 178 | authKind: OpenApiConnectInput["auth"]["kind"], | ||
| 179 | value: string, | ||
| 180 | ): OpenApiConnectInput["auth"] => { | ||
| 181 | if (authKind === "none") { | ||
| 182 | return { | ||
| 183 | kind: "none", | ||
| 184 | }; | ||
| 185 | } | ||
| 186 | |||
| 187 | if (!value) { | ||
| 188 | throw new Error("Select a secret for bearer auth."); | ||
| 189 | } | ||
| 190 | |||
| 191 | return { | ||
| 192 | kind: "bearer", | ||
| 193 | tokenSecretRef: JSON.parse(value) as OpenApiConnectInput["auth"] & { tokenSecretRef: never }["tokenSecretRef"], | ||
| 194 | }; | ||
| 195 | }; | ||
| 196 | |||
| 172 | const useAvailableSecrets = ( | 197 | const useAvailableSecrets = ( |
| 173 | openApiHttpClient: ReturnType<typeof getOpenApiHttpClient>, | 198 | openApiHttpClient: ReturnType<typeof getOpenApiHttpClient>, |
| 174 | ) => { | 199 | ) => { |
| @@ -205,9 +230,7 @@ function OpenApiSourceForm(props: { · 30 unmodified lines | |||
| 205 | props.initialValue.auth.kind, | 230 | props.initialValue.auth.kind, |
| 206 | ); | 231 | ); |
| 207 | const [tokenSecretRef, setTokenSecretRef] = useState( | 232 | const [tokenSecretRef, setTokenSecretRef] = useState( |
| 208 | props.initialValue.auth.kind === "bearer" | 233 | secretValue(props.initialValue.auth), |
| 209 | ? props.initialValue.auth.tokenSecretRef | ||
| 210 | : "", | ||
| 211 | ); | 234 | ); |
| 212 | const [error, setError] = useState<string | null>(null); | 235 | const [error, setError] = useState<string | null>(null); |
| 213 | const [preview, setPreview] = useState<OpenApiPreviewResponse | null>(null); | 236 | const [preview, setPreview] = useState<OpenApiPreviewResponse | null>(null); |
| @@ -309,19 +332,12 @@ function OpenApiSourceForm(props: { · 95 unmodified lines | |||
| 309 | } | 332 | } |
| 310 | 333 | ||
| 311 | try { | 334 | try { |
| 335 | const auth = authFromSecretValue(authKind, tokenSecretRef); | ||
| 312 | await submitMutation.mutateAsync({ | 336 | await submitMutation.mutateAsync({ |
| 313 | name: trimmedName, | 337 | name: trimmedName, |
| 314 | specUrl: trimmedSpecUrl, | 338 | specUrl: trimmedSpecUrl, |
| 315 | baseUrl: trimmedBaseUrl || null, | 339 | baseUrl: trimmedBaseUrl || null, |
| 316 | auth: | 340 | auth, |
| 317 | authKind === "bearer" | ||
| 318 | ? { | ||
| 319 | kind: "bearer", | ||
| 320 | tokenSecretRef: tokenSecretRef.trim(), | ||
| 321 | } | ||
| 322 | : { | ||
| 323 | kind: "none", | ||
| 324 | }, | ||
| 325 | }); | 341 | }); |
| 326 | } catch (cause) { | 342 | } catch (cause) { |
| 327 | setError(cause instanceof Error ? cause.message : "Failed saving source."); | 343 | setError(cause instanceof Error ? cause.message : "Failed saving source."); |
| @@ -398,7 +414,13 @@ function OpenApiSourceForm(props: { · 70 unmodified lines | |||
| 398 | > | 414 | > |
| 399 | <option value="">Select a secret</option> | 415 | <option value="">Select a secret</option> |
| 400 | {availableSecrets.map((secret) => ( | 416 | {availableSecrets.map((secret) => ( |
| 401 | <option key={secret.id} value={secret.id}> | 417 | <option |
| 418 | key={`${secret.providerId}:${secret.id}`} | ||
| 419 | value={JSON.stringify({ | ||
| 420 | providerId: secret.providerId, | ||
| 421 | handle: secret.id, | ||
| 422 | })} | ||
| 423 | > | ||
| 402 | {secret.name || secret.id} | 424 | {secret.name || secret.id} |
| 403 | </option> | 425 | </option> |
| 404 | ))} | 426 | ))} |