Skip to content

Commit

Permalink
adding edge case fix for permissions issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Pacobart committed Nov 7, 2023
1 parent 392078d commit a24eaa5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions internal/tfagentpools/tfagentpools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
19 changes: 14 additions & 5 deletions internal/tfworkspaces/tfworkspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit a24eaa5

Please sign in to comment.