add secret groups field functionality

This commit is contained in:
Chukwunonso Frank
2023-07-17 22:00:48 +01:00
parent 112d4ec9c0
commit 6ee7081640
3 changed files with 64 additions and 0 deletions

View File

@@ -754,9 +754,35 @@ const getAppsNorthflank = async ({ accessToken }: { accessToken: string }) => {
return {
name: a.name,
appId: a.id,
secretGroups: []
};
});
for (let i = 0; i < apps.length; i++) {
const appName = apps[i].name;
const {
data: {
data: {
secrets
}
}
} = await standardRequest.get(
`${INTEGRATION_NORTHFLANK_API_URL}/v1/projects/${appName}/secrets`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
"Accept-Encoding": "application/json",
},
}
);
const secretGroups = secrets.map((a: any) => {
return a.id
});
apps[i].secretGroups = secretGroups
}
return apps;
};

View File

@@ -13,6 +13,7 @@ export type App = {
name: string;
appId?: string;
owner?: string;
secretGroups?: string[];
};
export type Team = {

View File

@@ -32,6 +32,8 @@ export default function NorthflankCreateIntegrationPage() {
const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState("");
const [secretPath, setSecretPath] = useState("/");
const [targetApp, setTargetApp] = useState("");
const [secretGroupList, setSecretGroupList] = useState<any>([]);
const [targetSecretGroup, setTargetSecretGroup] = useState<any>("");
const [isLoading, setIsLoading] = useState(false);
@@ -51,6 +53,18 @@ export default function NorthflankCreateIntegrationPage() {
}
}, [integrationAuthApps]);
useEffect(() => {
if (integrationAuthApps) {
if (integrationAuthApps.length > 0) {
const selectedApp = integrationAuthApps?.filter((integrationAuthApp) => integrationAuthApp.name === targetApp);
setSecretGroupList(selectedApp[0].secretGroups);
setTargetSecretGroup(selectedApp[0]?.secretGroups[0]);
} else {
setTargetSecretGroup("none");
}
}
}, [targetApp])
const handleButtonClick = async () => {
try {
if (!integrationAuth?._id) return;
@@ -137,6 +151,29 @@ export default function NorthflankCreateIntegrationPage() {
)}
</Select>
</FormControl>
<FormControl label="Secret Group" className="mt-4">
<Select
value={targetSecretGroup}
onValueChange={(val) => setTargetSecretGroup(val)}
className="w-full border border-mineshaft-500"
isDisabled={secretGroupList.length === 0}
>
{secretGroupList.length > 0 ? (
secretGroupList.map((group: any) => (
<SelectItem
value={group}
key={`target-secret-group-${group}`}
>
{group}
</SelectItem>
))
) : (
<SelectItem value="none" key="target-secret-group-none">
No secret groups found
</SelectItem>
)}
</Select>
</FormControl>
<Button
onClick={handleButtonClick}
color="mineshaft"