mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-24 21:11:53 +00:00
feat(ui): add org lookup and secret update server actions
This commit is contained in:
@@ -38,6 +38,24 @@ export const createOrganization = async (formData: FormData) => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Lists AWS Organizations filtered by external ID.
|
||||
* GET /api/v1/organizations?filter[external_id]={externalId}&filter[org_type]=aws
|
||||
*/
|
||||
export const listOrganizationsByExternalId = async (externalId: string) => {
|
||||
const headers = await getAuthHeaders({ contentType: false });
|
||||
const url = new URL(`${apiBaseUrl}/organizations`);
|
||||
url.searchParams.set("filter[external_id]", externalId);
|
||||
url.searchParams.set("filter[org_type]", "aws");
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), { headers });
|
||||
return handleApiResponse(response);
|
||||
} catch (error) {
|
||||
return handleApiError(error);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an organization secret (role-based credentials).
|
||||
* POST /api/v1/organization-secrets
|
||||
@@ -82,6 +100,68 @@ export const createOrganizationSecret = async (formData: FormData) => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates an organization secret (role-based credentials).
|
||||
* PATCH /api/v1/organization-secrets/{id}
|
||||
*/
|
||||
export const updateOrganizationSecret = async (formData: FormData) => {
|
||||
const headers = await getAuthHeaders({ contentType: true });
|
||||
const organizationSecretId = formData.get("organizationSecretId") as string;
|
||||
const roleArn = formData.get("roleArn") as string;
|
||||
const externalId = formData.get("externalId") as string;
|
||||
|
||||
if (!organizationSecretId) {
|
||||
return { error: "Organization secret ID is required" };
|
||||
}
|
||||
|
||||
const url = new URL(
|
||||
`${apiBaseUrl}/organization-secrets/${organizationSecretId}`,
|
||||
);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), {
|
||||
method: "PATCH",
|
||||
headers,
|
||||
body: JSON.stringify({
|
||||
data: {
|
||||
type: "organization-secrets",
|
||||
id: organizationSecretId,
|
||||
attributes: {
|
||||
secret_type: "role",
|
||||
secret: {
|
||||
role_arn: roleArn,
|
||||
external_id: externalId,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
return handleApiResponse(response);
|
||||
} catch (error) {
|
||||
return handleApiError(error);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Lists organization secrets for an organization.
|
||||
* GET /api/v1/organization-secrets?filter[organization_id]={organizationId}
|
||||
*/
|
||||
export const listOrganizationSecretsByOrganizationId = async (
|
||||
organizationId: string,
|
||||
) => {
|
||||
const headers = await getAuthHeaders({ contentType: false });
|
||||
const url = new URL(`${apiBaseUrl}/organization-secrets`);
|
||||
url.searchParams.set("filter[organization_id]", organizationId);
|
||||
|
||||
try {
|
||||
const response = await fetch(url.toString(), { headers });
|
||||
return handleApiResponse(response);
|
||||
} catch (error) {
|
||||
return handleApiError(error);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Triggers an async discovery of the AWS Organization.
|
||||
* POST /api/v1/organizations/{id}/discover
|
||||
|
||||
Reference in New Issue
Block a user