Skip to content

Commit 9114e1f

Browse files
committed
feat: add tenant_site_capability_association table, DAO, and conservative backfill migration
1 parent 8b4188b commit 9114e1f

22 files changed

Lines changed: 2814 additions & 15 deletions

rest-api/api/pkg/api/handler/expectedmachine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func ValidateProviderOrTenantSiteAccess(ctx context.Context, logger zerolog.Logg
5959
hasAccess = tsCount > 0
6060

6161
// Check if Tenant is privileged
62-
if !hasAccess && tenant.Config.TargetedInstanceCreation {
62+
if !hasAccess && common.TenantHasTargetedInstanceCreation(tenant) {
6363
// Check if privileged tenant has an account with the Site's Infrastructure Provider
6464
taDAO := cdbm.NewTenantAccountDAO(dbSession)
6565
_, taCount, err := taDAO.GetAll(ctx, nil, cdbm.TenantAccountFilterInput{

rest-api/api/pkg/api/handler/instance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ func (cih CreateInstanceHandler) Handle(c echo.Context) error {
831831

832832
// Begin validating Machine ID
833833
if apiRequest.MachineID != nil {
834-
if tenant.Config == nil || !tenant.Config.TargetedInstanceCreation {
834+
if !common.TenantHasTargetedInstanceCreation(tenant) {
835835
logger.Warn().Msg("tenant does not have capability to create instances from specific machine")
836836
return cutil.NewAPIError(http.StatusForbidden, "Tenant does not have capability to create Instances using specific Machine ID", nil)
837837
}
@@ -4742,7 +4742,7 @@ func (dih DeleteInstanceHandler) Handle(c echo.Context) error {
47424742
// capability. By the time `ToProto` runs the request is safe
47434743
// to trust.
47444744
if apiRequest.IsRepairTenant != nil && *apiRequest.IsRepairTenant {
4745-
if instance.Tenant.Config == nil || !instance.Tenant.Config.TargetedInstanceCreation {
4745+
if !common.TenantHasTargetedInstanceCreation(instance.Tenant) {
47464746
logger.Warn().Msg("tenant does not have capability to set IsRepairTenant")
47474747
return cutil.NewAPIError(http.StatusForbidden, "Tenant does not have capability to set IsRepairTenant", nil)
47484748
}

rest-api/api/pkg/api/handler/machine.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func (gamh GetAllMachineHandler) Handle(c echo.Context) error {
241241

242242
if tenant != nil {
243243
// Check if Tenant is privileged
244-
if tenant.Config.TargetedInstanceCreation {
244+
if common.TenantHasTargetedInstanceCreation(tenant) {
245245
// Get IDs for all Providers the privileged Tenant has an account with
246246
taDAO := cdbm.NewTenantAccountDAO(gamh.dbSession)
247247
tas, _, serr := taDAO.GetAll(ctx, nil, cdbm.TenantAccountFilterInput{
@@ -614,7 +614,7 @@ func (gmh GetMachineHandler) Handle(c echo.Context) error {
614614
isProviderOrPrivilegedTenant = true
615615
} else if tenant != nil {
616616
// Check if Tenant is privileged
617-
if tenant.Config.TargetedInstanceCreation {
617+
if common.TenantHasTargetedInstanceCreation(tenant) {
618618
// Check if privileged Tenant has an account with Infrastructure Provider
619619
taDAO := cdbm.NewTenantAccountDAO(gmh.dbSession)
620620
_, taCount, serr := taDAO.GetAll(ctx, nil, cdbm.TenantAccountFilterInput{
@@ -758,7 +758,7 @@ func (umh UpdateMachineHandler) Handle(c echo.Context) error {
758758
// Validate if Tenant is allowed to update Machine
759759
if tenant != nil {
760760
// Check if Tenant is privileged
761-
if tenant.Config.TargetedInstanceCreation {
761+
if common.TenantHasTargetedInstanceCreation(tenant) {
762762
// Check if privileged Tenant has an account with Infrastructure Provider
763763
taDAO := cdbm.NewTenantAccountDAO(umh.dbSession)
764764
_, taCount, serr := taDAO.GetAll(ctx, nil, cdbm.TenantAccountFilterInput{

rest-api/api/pkg/api/handler/site.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ func (gsh GetSiteHandler) Handle(c echo.Context) error {
649649

650650
if !isAssociated {
651651
// Check if Tenant is privileged
652-
if tenant.Config != nil && tenant.Config.TargetedInstanceCreation {
652+
if common.TenantHasTargetedInstanceCreation(tenant) {
653653
taDAO := cdbm.NewTenantAccountDAO(gsh.dbSession)
654654
tas, _, serr := taDAO.GetAll(ctx, nil, cdbm.TenantAccountFilterInput{
655655
InfrastructureProviderID: &st.InfrastructureProviderID,
@@ -894,7 +894,7 @@ func (gash GetAllSiteHandler) Handle(c echo.Context) error {
894894

895895
// If Tenant is privileged (has TargetedInstanceCreation capability),
896896
// also retrieve all Sites from Providers they have a Tenant Account with
897-
if tenant.Config != nil && tenant.Config.TargetedInstanceCreation {
897+
if common.TenantHasTargetedInstanceCreation(tenant) {
898898
taDAO := cdbm.NewTenantAccountDAO(gash.dbSession)
899899
tas, _, serr := taDAO.GetAll(ctx, nil, cdbm.TenantAccountFilterInput{
900900
TenantIDs: []uuid.UUID{tenant.ID},
@@ -1224,7 +1224,7 @@ func (gssdh GetSiteStatusDetailsHandler) Handle(c echo.Context) error {
12241224

12251225
if !isAssociated {
12261226
// Check if Tenant is privileged
1227-
if tenant.Config != nil && tenant.Config.TargetedInstanceCreation {
1227+
if common.TenantHasTargetedInstanceCreation(tenant) {
12281228
taDAO := cdbm.NewTenantAccountDAO(gssdh.dbSession)
12291229
tas, _, serr := taDAO.GetAll(ctx, nil, cdbm.TenantAccountFilterInput{
12301230
InfrastructureProviderID: &st.InfrastructureProviderID,

rest-api/api/pkg/api/handler/sku.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (gash GetAllSkuHandler) Handle(c echo.Context) error {
105105
}
106106
} else if tenant != nil {
107107
// Check if Tenant is privileged
108-
if !tenant.Config.TargetedInstanceCreation {
108+
if !common.TenantHasTargetedInstanceCreation(tenant) {
109109
logger.Warn().Msg("Tenant doesn't have targeted Instance creation capability, access denied")
110110
return cutil.NewAPIErrorResponse(c, http.StatusForbidden, "Tenant must have targeted Instance creation capability in order to retrieve SKUs", nil)
111111
}
@@ -274,7 +274,7 @@ func (gsh GetSkuHandler) Handle(c echo.Context) error {
274274
}
275275
} else if tenant != nil {
276276
// Check if Tenant is privileged
277-
if !tenant.Config.TargetedInstanceCreation {
277+
if !common.TenantHasTargetedInstanceCreation(tenant) {
278278
logger.Warn().Msg("Tenant doesn't have targeted Instance creation capability, access denied")
279279
return cutil.NewAPIErrorResponse(c, http.StatusForbidden, "Tenant must have targeted Instance creation capability in order to retrieve SKU", nil)
280280
}

0 commit comments

Comments
 (0)