Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Added `populateOrgName` param in `/v1/workspace` api which adds `orgName` and `displayName` in result
Rhythm Bhiwani756c1e509879
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex d3d01ccb5d..f6264d5803 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -341,6 +341,7 @@ export const registerRoutes = async (const projectService = projectServiceFactory({permissionService,projectDAL,+ orgDAL,projectQueue: projectQueueService,secretBlindIndexDAL,identityProjectDAL,diff --git a/backend/src/server/routes/v1/project-router.ts b/backend/src/server/routes/v1/project-router.tsindex 0a5f8d85e4..a4c385283f 100644--- a/backend/src/server/routes/v1/project-router.ts+++ b/backend/src/server/routes/v1/project-router.ts@@ -16,7 +16,9 @@ import { sanitizedServiceTokenSchema } from "../v2/service-token-router";const projectWithEnv = ProjectsSchema.merge(z.object({_id: z.string(),- environments: z.object({ name: z.string(), slug: z.string(), id: z.string() }).array()+ environments: z.object({ name: z.string(), slug: z.string(), id: z.string() }).array(),+ orgName: z.string().optional(),+ displayName: z.string().optional()}));@@ -91,6 +93,12 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {url: "/",method: "GET",schema: {+ querystring: z.object({+ populateOrgName: z+ .enum(["true", "false"])+ .default("false")+ .transform((value) => value === "true")+ }),response: {200: z.object({workspaces: projectWithEnv.array()@@ -99,7 +107,7 @@ export const registerProjectRouter = async (server: FastifyZodProvider) => {},onRequest: verifyAuth([AuthMode.JWT, AuthMode.API_KEY]),handler: async (req) => {- const workspaces = await server.services.project.getProjects(req.permission.id);+ const workspaces = await server.services.project.getProjects(req.permission.id, req.query.populateOrgName);return { workspaces };}});diff --git a/backend/src/services/project/project-service.ts b/backend/src/services/project/project-service.tsindex c7c3af6fa9..4bd322494a 100644--- a/backend/src/services/project/project-service.ts+++ b/backend/src/services/project/project-service.ts@@ -17,6 +17,7 @@ import { TProjectPermission } from "@app/lib/types";import { ActorType } from "../auth/auth-type";import { TIdentityOrgDALFactory } from "../identity/identity-org-dal";import { TIdentityProjectDALFactory } from "../identity-project/identity-project-dal";+import { TOrgDALFactory } from "../org/org-dal";import { TOrgServiceFactory } from "../org/org-service";import { TProjectBotDALFactory } from "../project-bot/project-bot-dal";import { TProjectEnvDALFactory } from "../project-env/project-env-dal";@@ -46,6 +47,7 @@ type TProjectServiceFactoryDep = {projectDAL: TProjectDALFactory;projectQueue: TProjectQueueFactory;userDAL: TUserDALFactory;+ orgDAL: TOrgDALFactory;folderDAL: TSecretFolderDALFactory;projectEnvDAL: Pick<TProjectEnvDALFactory, "insertMany" | "find">;identityOrgMembershipDAL: TIdentityOrgDALFactory;@@ -64,6 +66,7 @@ export type TProjectServiceFactory = ReturnType<typeof projectServiceFactory>;export const projectServiceFactory = ({projectDAL,projectQueue,+ orgDAL,projectKeyDAL,permissionService,userDAL,@@ -306,8 +309,19 @@ export const projectServiceFactory = ({return deletedProject;};- const getProjects = async (actorId: string) => {+ const getProjects = async (actorId: string, populateOrgName?: boolean) => {const workspaces = await projectDAL.findAllProjects(actorId);+ if (populateOrgName) {+ const orgs = await orgDAL.findAllOrgsByUserId(actorId);+ return workspaces.map((workspace) => {+ const orgName = orgs.find((org) => org.id === workspace.orgId)?.name || "";+ return {+ ...workspace,+ orgName,+ displayName: `${workspace.name} (${orgName})`+ };+ });+ }return workspaces;};diff --git a/cli/packages/api/api.go b/cli/packages/api/api.goindex eaf1c650b7..73d8b3916c 100644--- a/cli/packages/api/api.go+++ b/cli/packages/api/api.go@@ -170,6 +170,7 @@ func CallGetAllWorkSpacesUserBelongsTo(httpClient *resty.Client) (GetWorkSpacesRR().SetResult(&workSpacesResponse).SetHeader("User-Agent", USER_AGENT).+ SetQueryParam("populateOrgName", "true").Get(fmt.Sprintf("%v/v1/workspace", config.INFISICAL_URL))if err != nil {@@ -180,22 +181,6 @@ func CallGetAllWorkSpacesUserBelongsTo(httpClient *resty.Client) (GetWorkSpacesRreturn GetWorkSpacesResponse{}, fmt.Errorf("CallGetAllWorkSpacesUserBelongsTo: Unsuccessful response: [response=%v]", response)}- // Call the organization API- orgResponse, err := CallGetAllOrganizations(httpClient)- if err != nil {- return GetWorkSpacesResponse{}, err- }-- // Update organization names in workspacesResponse- for i, workspace := range workSpacesResponse.Workspaces {- for _, organization := range orgResponse.Organizations {- if workspace.Organization == organization.ID {- workSpacesResponse.Workspaces[i].Organization = organization.Name- break- }- }- }-return workSpacesResponse, nil}diff --git a/cli/packages/api/model.go b/cli/packages/api/model.goindex 5fc04dee34..de4949c173 100644--- a/cli/packages/api/model.go+++ b/cli/packages/api/model.go@@ -120,11 +120,12 @@ type PullSecretsByInfisicalTokenResponse struct {type GetWorkSpacesResponse struct {Workspaces []struct {- ID string `json:"_id"`- Name string `json:"name"`- Plan string `json:"plan,omitempty"`- V int `json:"__v"`- Organization string `json:"orgId,omitempty"`+ ID string `json:"_id"`+ Name string `json:"name"`+ Plan string `json:"plan,omitempty"`+ V int `json:"__v"`+ Organization *string `json:"orgName,omitempty"`+ DisplayName *string `json:"displayName,omitempty"`} `json:"workspaces"`}diff --git a/cli/packages/cmd/init.go b/cli/packages/cmd/init.goindex 9e7c2fe6ab..217e0842e1 100644--- a/cli/packages/cmd/init.go+++ b/cli/packages/cmd/init.go@@ -5,7 +5,6 @@ package cmdimport ("encoding/json"- "fmt""github.com/Infisical/infisical-merge/packages/api""github.com/Infisical/infisical-merge/packages/models"@@ -58,14 +57,10 @@ var initCmd = &cobra.Command{}workspaces := workspaceResponse.Workspaces- if len(workspaces) == 0 {- message := fmt.Sprintf("You don't have any projects created in Infisical. You must first create a project at %s", util.INFISICAL_TOKEN_NAME)- util.PrintErrorMessageAndExit(message)- }- var workspaceNames []string- for _, workspace := range workspaces {- workspaceNames = append(workspaceNames, fmt.Sprintf("%s (%s)", workspace.Name, workspace.Organization))+ workspaceNames, err := util.GetWorkspacesNameList(workspaceResponse)+ if err != nil {+ util.HandleError(err, "Error extracting workspace names")}prompt := promptui.Select{diff --git a/cli/packages/models/cli.go b/cli/packages/models/cli.goindex 801cfddfc3..556b700514 100644--- a/cli/packages/models/cli.go+++ b/cli/packages/models/cli.go@@ -45,11 +45,12 @@ type SingleFolder struct {}type Workspace struct {- ID string `json:"_id"`- Name string `json:"name"`- Plan string `json:"plan,omitempty"`- V int `json:"__v"`- Organization string `json:"orgId,omitempty"`+ ID string `json:"_id"`+ Name string `json:"name"`+ Plan string `json:"plan,omitempty"`+ V int `json:"__v"`+ Organization *string `json:"orgName,omitempty"`+ DisplayName *string `json:"displayName,omitempty"`}type WorkspaceConfigFile struct {diff --git a/cli/packages/util/init.go b/cli/packages/util/init.gonew file mode 100644index 0000000000..be91e811d7--- /dev/null+++ b/cli/packages/util/init.go@@ -0,0 +1,27 @@+package util++import (+ "fmt"++ "github.com/Infisical/infisical-merge/packages/api"+)++func GetWorkspacesNameList(workspaceResponse api.GetWorkSpacesResponse) ([]string, error) {+ workspaces := workspaceResponse.Workspaces++ if len(workspaces) == 0 {+ message := fmt.Sprintf("You don't have any projects created in Infisical. You must first create a project at %s", INFISICAL_TOKEN_NAME)+ PrintErrorMessageAndExit(message)+ }++ var workspaceNames []string+ for _, workspace := range workspaces {+ if workspace.DisplayName != nil {+ workspaceNames = append(workspaceNames, *workspace.DisplayName)+ } else {+ workspaceNames = append(workspaceNames, workspace.Name)+ }+ }++ return workspaceNames, nil+}