Skip to content

Commit

Permalink
incusd/api_project: Fix UsedBy
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Jun 27, 2024
1 parent 6a42aa1 commit ad228b6
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions cmd/incusd/api_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,49 +208,65 @@ func projectUsedBy(ctx context.Context, tx *db.ClusterTx, project *cluster.Proje
return nil, err
}

profiles, err := cluster.GetProfiles(ctx, tx.Tx(), cluster.ProfileFilter{Project: &project.Name})
if err != nil {
return nil, err
for _, instance := range instances {
apiInstance := api.Instance{Name: instance.Name}
usedBy = append(usedBy, apiInstance.URL(version.APIVersion, project.Name).String())
}

images, err := cluster.GetImages(ctx, tx.Tx(), cluster.ImageFilter{Project: &project.Name})
if err != nil {
return nil, err
}

for _, instance := range instances {
apiInstance := api.Instance{Name: instance.Name}
usedBy = append(usedBy, apiInstance.URL(version.APIVersion, project.Name).String())
for _, image := range images {
apiImage := api.Image{Fingerprint: image.Fingerprint}
usedBy = append(usedBy, apiImage.URL(version.APIVersion, project.Name).String())
}

for _, profile := range profiles {
apiProfile := api.Profile{Name: profile.Name}
usedBy = append(usedBy, apiProfile.URL(version.APIVersion, project.Name).String())
networks, err := tx.GetNetworkURIs(ctx, project.ID, project.Name)
if err != nil {
return nil, err
}

for _, image := range images {
apiImage := api.Image{Fingerprint: image.Fingerprint}
usedBy = append(usedBy, apiImage.URL(version.APIVersion, project.Name).String())
usedBy = append(usedBy, networks...)

networkACLs, err := tx.GetNetworkACLURIs(ctx, project.ID, project.Name)
if err != nil {
return nil, err
}

volumes, err := tx.GetStorageVolumeURIs(ctx, project.Name)
usedBy = append(usedBy, networkACLs...)

networkZones, err := tx.GetNetworkZoneURIs(ctx, project.ID, project.Name)
if err != nil {
return nil, err
}

networks, err := tx.GetNetworkURIs(ctx, project.ID, project.Name)
usedBy = append(usedBy, networkZones...)

profiles, err := cluster.GetProfiles(ctx, tx.Tx(), cluster.ProfileFilter{Project: &project.Name})
if err != nil {
return nil, err
}

for _, profile := range profiles {
apiProfile := api.Profile{Name: profile.Name}
usedBy = append(usedBy, apiProfile.URL(version.APIVersion, project.Name).String())
}

storageBuckets, err := tx.GetStorageBucketURIs(ctx, project.Name)
if err != nil {
return nil, err
}

acls, err := tx.GetNetworkACLURIs(ctx, project.ID, project.Name)
usedBy = append(usedBy, storageBuckets...)

storageVolumes, err := tx.GetStorageVolumeURIs(ctx, project.Name)
if err != nil {
return nil, err
}

usedBy = append(usedBy, volumes...)
usedBy = append(usedBy, networks...)
usedBy = append(usedBy, acls...)
usedBy = append(usedBy, storageVolumes...)

return usedBy, nil
}
Expand Down

0 comments on commit ad228b6

Please sign in to comment.