Refactor Northflank connection code and improve documentation

- Cleaned up code formatting in Northflank connection functions and schemas for better readability.
- Enhanced error logging in the Northflank connection service to include additional context.
- Updated Northflank integration documentation for clarity and accuracy, including minor text corrections and URL adjustments.
- Removed unnecessary whitespace in various files for consistency.
This commit is contained in:
Your Name
2025-10-22 10:53:46 -03:00
parent 2385e85baf
commit c3899a0e81
6 changed files with 18 additions and 31 deletions
@@ -51,4 +51,3 @@ export const registerNorthflankConnectionRouter = async (server: FastifyZodProvi
} }
}); });
}; };
@@ -50,15 +50,12 @@ export const listProjects = async (appConnection: TNorthflankConnection): Promis
data: { data: {
data: { projects } data: { projects }
} }
} = await request.get<{ data: { projects: TNorthflankProject[] } }>( } = await request.get<{ data: { projects: TNorthflankProject[] } }>(`${NORTHFLANK_API_URL}/v1/projects`, {
`${NORTHFLANK_API_URL}/v1/projects`, headers: {
{ Authorization: `Bearer ${credentials.apiToken}`,
headers: { Accept: "application/json"
Authorization: `Bearer ${credentials.apiToken}`,
Accept: "application/json"
}
} }
); });
return projects; return projects;
} catch (error: unknown) { } catch (error: unknown) {
@@ -74,4 +71,3 @@ export const listProjects = async (appConnection: TNorthflankConnection): Promis
}); });
} }
}; };
@@ -11,11 +11,7 @@ import {
import { NorthflankConnectionMethod } from "./northflank-connection-enums"; import { NorthflankConnectionMethod } from "./northflank-connection-enums";
export const NorthflankConnectionApiTokenCredentialsSchema = z.object({ export const NorthflankConnectionApiTokenCredentialsSchema = z.object({
apiToken: z apiToken: z.string().trim().min(1, "API Token required").describe(AppConnections.CREDENTIALS.NORTHFLANK.apiToken)
.string()
.trim()
.min(1, "API Token required")
.describe(AppConnections.CREDENTIALS.NORTHFLANK.apiToken)
}); });
const BaseNorthflankConnectionSchema = BaseAppConnectionSchema.extend({ const BaseNorthflankConnectionSchema = BaseAppConnectionSchema.extend({
@@ -36,9 +32,9 @@ export const SanitizedNorthflankConnectionSchema = z.discriminatedUnion("method"
export const ValidateNorthflankConnectionCredentialsSchema = z.discriminatedUnion("method", [ export const ValidateNorthflankConnectionCredentialsSchema = z.discriminatedUnion("method", [
z.object({ z.object({
method: z.literal(NorthflankConnectionMethod.ApiToken).describe( method: z
AppConnections.CREATE(AppConnection.Northflank).method .literal(NorthflankConnectionMethod.ApiToken)
), .describe(AppConnections.CREATE(AppConnection.Northflank).method),
credentials: NorthflankConnectionApiTokenCredentialsSchema.describe( credentials: NorthflankConnectionApiTokenCredentialsSchema.describe(
AppConnections.CREATE(AppConnection.Northflank).credentials AppConnections.CREATE(AppConnection.Northflank).credentials
) )
@@ -62,4 +58,3 @@ export const NorthflankConnectionListItemSchema = z.object({
app: z.literal(AppConnection.Northflank), app: z.literal(AppConnection.Northflank),
methods: z.nativeEnum(NorthflankConnectionMethod).array() methods: z.nativeEnum(NorthflankConnectionMethod).array()
}); });
@@ -19,7 +19,7 @@ export const northflankConnectionService = (getAppConnection: TGetAppConnectionF
return projects; return projects;
} catch (error) { } catch (error) {
logger.error(error, "Failed to establish connection with Northflank"); logger.error({ error, connectionId, actor: actor.type }, "Failed to establish connection with Northflank");
return []; return [];
} }
}; };
@@ -28,4 +28,3 @@ export const northflankConnectionService = (getAppConnection: TGetAppConnectionF
listProjects listProjects
}; };
}; };
@@ -17,11 +17,11 @@ Infisical supports the use of [API Tokens](https://northflank.com/docs/v1/api/us
![Create API Role](/images/app-connections/northflank/step-1.png) ![Create API Role](/images/app-connections/northflank/step-1.png)
Click in **Create API role**. Click on **Create API role**.
![Create API Role](/images/app-connections/northflank/step-2.png) ![Create API Role](/images/app-connections/northflank/step-2.png)
Select all the projects you want this role to have access, or leave this unchecked if you want to give access to all project. Select all the projects you want this role to have access to, or leave this unchecked if you want to give access to all projects.
![Create API Role](/images/app-connections/northflank/step-3.png) ![Create API Role](/images/app-connections/northflank/step-3.png)
@@ -32,7 +32,7 @@ Infisical supports the use of [API Tokens](https://northflank.com/docs/v1/api/us
Scroll to the bottom and save the API role. Scroll to the bottom and save the API role.
</Step> </Step>
<Step title="Create an API Token"> <Step title="Create an API Token">
Click on the **API** -> **Tokens** menu on the left and then in the **Create API token** button. Click on the **API** -> **Tokens** menu on the left and then click the **Create API token** button.
![Create API Token](/images/app-connections/northflank/step-5.png) ![Create API Token](/images/app-connections/northflank/step-5.png)
@@ -84,7 +84,7 @@ Infisical supports the use of [API Tokens](https://northflank.com/docs/v1/api/us
```bash Request ```bash Request
curl --request POST \ curl --request POST \
--url http://localhost:8080/api/v1/app-connections/northflank \ --url https://app.infisical.com/api/v1/app-connections/northflank \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
--data '{ --data '{
"name": "my-northflank-connection", "name": "my-northflank-connection",
@@ -104,7 +104,7 @@ Infisical supports the use of [API Tokens](https://northflank.com/docs/v1/api/us
"id": "a1b2c3d4-5678-90ab-cdef-1234567890ab", "id": "a1b2c3d4-5678-90ab-cdef-1234567890ab",
"name": "my-northflank-connection", "name": "my-northflank-connection",
"description": null, "description": null,
"projectId": "7ffbb072-2575-495a-b5b0-127f88caef78", "projectId": "abcdef12-3456-7890-abcd-ef1234567890",
"version": 1, "version": 1,
"orgId": "abcdef12-3456-7890-abcd-ef1234567890", "orgId": "abcdef12-3456-7890-abcd-ef1234567890",
"createdAt": "2025-01-23T10:15:00.000Z", "createdAt": "2025-01-23T10:15:00.000Z",
@@ -112,7 +112,6 @@ Infisical supports the use of [API Tokens](https://northflank.com/docs/v1/api/us
"isPlatformManagedCredentials": false, "isPlatformManagedCredentials": false,
"credentialsHash": "d41d8cd98f00b204e9800998ecf8427e", "credentialsHash": "d41d8cd98f00b204e9800998ecf8427e",
"gatewayId":null, "gatewayId":null,
"projectId":"abcdef12-3456-7890-abcd-ef1234567890"
"app": "northflank", "app": "northflank",
"method": "api-token", "method": "api-token",
"credentials": {} "credentials": {}
@@ -13,8 +13,8 @@ import {
import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections"; import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections";
import { AppConnection } from "@app/hooks/api/appConnections/enums"; import { AppConnection } from "@app/hooks/api/appConnections/enums";
import { import {
TNorthflankConnection, NorthflankConnectionMethod,
NorthflankConnectionMethod TNorthflankConnection
} from "@app/hooks/api/appConnections/types/northflank-connection"; } from "@app/hooks/api/appConnections/types/northflank-connection";
import { import {
@@ -86,7 +86,7 @@ export const NorthflankConnectionForm = ({ appConnection, onSubmit }: Props) =>
{Object.values(NorthflankConnectionMethod).map((method) => { {Object.values(NorthflankConnectionMethod).map((method) => {
return ( return (
<SelectItem value={method} key={method}> <SelectItem value={method} key={method}>
{getAppConnectionMethodDetails(method).name}{" "} {getAppConnectionMethodDetails(method).name}
</SelectItem> </SelectItem>
); );
})} })}
@@ -133,4 +133,3 @@ export const NorthflankConnectionForm = ({ appConnection, onSubmit }: Props) =>
</FormProvider> </FormProvider>
); );
}; };