From a24eaa5b83efb52820cf9a920e65ef4f1658882c Mon Sep 17 00:00:00 2001 From: Parker Barthlome Date: Tue, 7 Nov 2023 15:18:09 -0700 Subject: [PATCH] adding edge case fix for permissions issue --- internal/tfagentpools/tfagentpools.go | 5 +++++ internal/tfworkspaces/tfworkspaces.go | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/internal/tfagentpools/tfagentpools.go b/internal/tfagentpools/tfagentpools.go index 2c9f40d..400d7f1 100644 --- a/internal/tfagentpools/tfagentpools.go +++ b/internal/tfagentpools/tfagentpools.go @@ -35,6 +35,11 @@ func GetAgentPool(baseUrl string, token string, agentPoolID string) AgentPool { helpers.Check(err) defer resp.Body.Close() + if resp.StatusCode == http.StatusNotFound { + fmt.Printf("AgentPool %s not found\n", agentPoolID) + return AgentPool{} + } + if resp.StatusCode == http.StatusTooManyRequests { fmt.Printf("Rate limit exceeded when retrieving GetAgentPool %s\n", agentPoolID) } diff --git a/internal/tfworkspaces/tfworkspaces.go b/internal/tfworkspaces/tfworkspaces.go index 4b0b525..21168f0 100644 --- a/internal/tfworkspaces/tfworkspaces.go +++ b/internal/tfworkspaces/tfworkspaces.go @@ -93,12 +93,21 @@ func GetWorkspaces(baseUrl string, token string, organization string) []Workspac // add friendly names to project and agentpool for i := range allWorkspaces { ws := &allWorkspaces[i] - project := tfprojects.GetProject(baseUrl, token, ws.Relationships.Project.Data.Id) - projectName := project.Data.Attributes.Name - ws.Relationships.Project.Data.Name = projectName + projectID := ws.Relationships.Project.Data.Id + helpers.Debug(fmt.Sprintf("Project ID is %s", projectID)) + if projectID != "" { + project := tfprojects.GetProject(baseUrl, token, projectID) + projectName := project.Data.Attributes.Name + ws.Relationships.Project.Data.Name = projectName + } - if ws.Relationships.AgentPool.Data.Id != "" { - agentpool := tfagentpools.GetAgentPool(baseUrl, token, ws.Relationships.AgentPool.Data.Id) + agentPoollID := ws.Relationships.AgentPool.Data.Id + if agentPoollID != "" { + agentpool := tfagentpools.GetAgentPool(baseUrl, token, agentPoollID) + if agentpool.Data.Attributes.Name == "" { + fmt.Println(fmt.Sprintf("Agentpool name is empty for agentpool %s. Setting Name to ID", agentpool.Data.ID)) + agentpool.Data.Attributes.Name = agentpool.Data.ID + } agentpoolName := agentpool.Data.Attributes.Name ws.Relationships.AgentPool.Data.Name = agentpoolName }