mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 23:27:35 +00:00
feat: option to choose target environment
This commit is contained in:
@@ -1854,6 +1854,8 @@ const syncSecretsCloudflarePages = async ({
|
|||||||
accessId: string | null;
|
accessId: string | null;
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
}) => {
|
}) => {
|
||||||
|
const targetEnvironment = integration.targetEnvironment;
|
||||||
|
|
||||||
// get secrets from cloudflare pages
|
// get secrets from cloudflare pages
|
||||||
const getSecretsRes = (
|
const getSecretsRes = (
|
||||||
await standardRequest.get(
|
await standardRequest.get(
|
||||||
@@ -1866,7 +1868,7 @@ const syncSecretsCloudflarePages = async ({
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.data.result['deployment_configs'].production['env_vars'];
|
.data.result['deployment_configs'][targetEnvironment]['env_vars'];
|
||||||
|
|
||||||
// copy the secrets object, so we can set deleted keys to null
|
// copy the secrets object, so we can set deleted keys to null
|
||||||
const secretsObj: any = {...secrets};
|
const secretsObj: any = {...secrets};
|
||||||
@@ -1878,22 +1880,32 @@ const syncSecretsCloudflarePages = async ({
|
|||||||
if (getSecretsRes) { // if there are no env vars set in cloudflare pages, none have to be deleted either
|
if (getSecretsRes) { // if there are no env vars set in cloudflare pages, none have to be deleted either
|
||||||
for await (const key of Object.keys(getSecretsRes)) {
|
for await (const key of Object.keys(getSecretsRes)) {
|
||||||
if (!(key in secrets)) {
|
if (!(key in secrets)) {
|
||||||
// case: secret deos not exist in infisical
|
// case: secret does not exist in infisical
|
||||||
// -> delete secret from cloudflare pages
|
// -> delete secret from cloudflare pages
|
||||||
secretsObj[key] = null;
|
secretsObj[key] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const data = targetEnvironment === 'production'
|
||||||
|
? {
|
||||||
|
"deployment_configs": {
|
||||||
|
"production" : {
|
||||||
|
"env_vars": secretsObj
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
"deployment_configs": {
|
||||||
|
"preview": {
|
||||||
|
"env_vars": secretsObj
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const result = await standardRequest.patch(
|
const result = await standardRequest.patch(
|
||||||
`${INTEGRATION_CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accessId}/pages/projects/${integration.app}`,
|
`${INTEGRATION_CLOUDFLARE_PAGES_API_URL}/client/v4/accounts/${accessId}/pages/projects/${integration.app}`,
|
||||||
{
|
data,
|
||||||
"deployment_configs": {
|
|
||||||
"production": {
|
|
||||||
"env_vars": secretsObj
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ import { useGetIntegrationAuthApps, useGetIntegrationAuthById } from '~/hooks/ap
|
|||||||
import createIntegration from '~/pages/api/integrations/createIntegration';
|
import createIntegration from '~/pages/api/integrations/createIntegration';
|
||||||
import { Button, Card, CardTitle, FormControl, Select, SelectItem } from '~/components/v2';
|
import { Button, Card, CardTitle, FormControl, Select, SelectItem } from '~/components/v2';
|
||||||
|
|
||||||
|
const cloudflareEnvironments = [
|
||||||
|
{ name: 'Production', slug: 'production' },
|
||||||
|
{ name: 'Preview', slug: 'preview' }
|
||||||
|
];
|
||||||
|
|
||||||
export default function CloudflarePagesIntegrationPage() {
|
export default function CloudflarePagesIntegrationPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
@@ -19,6 +24,7 @@ export default function CloudflarePagesIntegrationPage() {
|
|||||||
const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState('');
|
const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState('');
|
||||||
const [targetApp, setTargetApp] = useState('');
|
const [targetApp, setTargetApp] = useState('');
|
||||||
const [targetAppId, setTargetAppId] = useState('');
|
const [targetAppId, setTargetAppId] = useState('');
|
||||||
|
const [targetEnvironment, setTargetEnvironment] = useState('');
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
@@ -33,8 +39,10 @@ export default function CloudflarePagesIntegrationPage() {
|
|||||||
if (integrationAuthApps.length > 0) {
|
if (integrationAuthApps.length > 0) {
|
||||||
setTargetApp(integrationAuthApps[0].name);
|
setTargetApp(integrationAuthApps[0].name);
|
||||||
setTargetAppId(String(integrationAuthApps[0].appId));
|
setTargetAppId(String(integrationAuthApps[0].appId));
|
||||||
|
setTargetEnvironment(cloudflareEnvironments[0].slug);
|
||||||
} else {
|
} else {
|
||||||
setTargetApp('none');
|
setTargetApp('none');
|
||||||
|
setTargetEnvironment(cloudflareEnvironments[0].slug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [integrationAuthApps]);
|
}, [integrationAuthApps]);
|
||||||
@@ -51,7 +59,7 @@ export default function CloudflarePagesIntegrationPage() {
|
|||||||
app: targetApp,
|
app: targetApp,
|
||||||
appId: targetAppId,
|
appId: targetAppId,
|
||||||
sourceEnvironment: selectedSourceEnvironment,
|
sourceEnvironment: selectedSourceEnvironment,
|
||||||
targetEnvironment: null,
|
targetEnvironment,
|
||||||
targetEnvironmentId: null,
|
targetEnvironmentId: null,
|
||||||
targetService: null,
|
targetService: null,
|
||||||
targetServiceId: null,
|
targetServiceId: null,
|
||||||
@@ -73,6 +81,7 @@ export default function CloudflarePagesIntegrationPage() {
|
|||||||
workspace &&
|
workspace &&
|
||||||
selectedSourceEnvironment &&
|
selectedSourceEnvironment &&
|
||||||
integrationAuthApps &&
|
integrationAuthApps &&
|
||||||
|
targetEnvironment &&
|
||||||
targetApp ? (
|
targetApp ? (
|
||||||
<div className="flex h-full w-full items-center justify-center bg-gradient-to-tr from-mineshaft-900 to-bunker-900">
|
<div className="flex h-full w-full items-center justify-center bg-gradient-to-tr from-mineshaft-900 to-bunker-900">
|
||||||
<Card className="max-w-lg rounded-md p-0 border border-mineshaft-600">
|
<Card className="max-w-lg rounded-md p-0 border border-mineshaft-600">
|
||||||
@@ -116,6 +125,22 @@ export default function CloudflarePagesIntegrationPage() {
|
|||||||
)}
|
)}
|
||||||
</Select>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
<FormControl label="Cloudflare Pages Environment" className="mt-4 px-6">
|
||||||
|
<Select
|
||||||
|
value={targetEnvironment}
|
||||||
|
onValueChange={(val) => setTargetEnvironment(val)}
|
||||||
|
className="w-full border border-mineshaft-500"
|
||||||
|
>
|
||||||
|
{cloudflareEnvironments.map((cloudflareEnvironment) => (
|
||||||
|
<SelectItem
|
||||||
|
value={cloudflareEnvironment.slug}
|
||||||
|
key={`target-environment-${cloudflareEnvironment.slug}`}
|
||||||
|
>
|
||||||
|
{cloudflareEnvironment.name}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleButtonClick}
|
onClick={handleButtonClick}
|
||||||
color="mineshaft"
|
color="mineshaft"
|
||||||
|
|||||||
Reference in New Issue
Block a user