Skip to content

Commit

Permalink
[akamai] check for referenced member before deleting datacenter
Browse files Browse the repository at this point in the history
  • Loading branch information
notandy committed Oct 11, 2024
1 parent 51088c5 commit c77f7da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions internal/controller/datacenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,15 @@ func (c DatacenterController) DeleteDatacentersDatacenterID(params datacenters.D
return datacenters.NewDeleteDatacentersDatacenterIDDefault(403).WithPayload(utils.PolicyForbidden)
}

// todo: check for related members
sql := c.db.Rebind(`UPDATE datacenter SET provisioning_status = 'PENDING_DELETE' WHERE id = ?`)
var count int
sql := c.db.Rebind(`SELECT count(*) FROM member WHERE datacenter_id = ?`)
if err := c.db.Get(&count, sql, datacenter.ID); err != nil {
panic(err)
} else if count > 0 {
return datacenters.NewDeleteDatacentersDatacenterIDDefault(409).WithPayload(utils.DatacenterInUse)
}

sql = c.db.Rebind(`UPDATE datacenter SET provisioning_status = 'PENDING_DELETE' WHERE id = ?`)
res, err := c.db.Exec(sql, params.DatacenterID)
if err != nil {
var pe *pq.Error
Expand Down
3 changes: 2 additions & 1 deletion internal/driver/akamai/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func (s *AkamaiAgent) FetchAndSyncDomains(domains []string) error {
var datacenters []string
for _, domain := range res {
for _, datacenter := range domain.Datacenters {
if datacenter.ProvisioningStatus != models.DatacenterProvisioningStatusACTIVE {
if datacenter.ProvisioningStatus != models.DatacenterProvisioningStatusACTIVE &&
datacenter.ProvisioningStatus != models.DatacenterProvisioningStatusPENDINGDELETE {
datacenters = append(datacenters, datacenter.Id)
}
}
Expand Down

0 comments on commit c77f7da

Please sign in to comment.