You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2018/07/04 02:39:40 UTC
[trafficcontrol] 15/15: fix up places where IsTenancyEnabledTx now
returns an error
This is an automated email from the ASF dual-hosted git repository.
dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit 71972efed58a8670e1a76693e416ac962c8eb36d
Author: Dylan Volz <Dy...@comcast.com>
AuthorDate: Mon Jul 2 17:31:46 2018 -0600
fix up places where IsTenancyEnabledTx now returns an error
---
.../deliveryservice/deliveryservicesv13.go | 8 +++++++-
.../deliveryservice/request/requests.go | 7 ++++++-
traffic_ops/traffic_ops_golang/origin/origins.go | 19 +++++++++++++++----
traffic_ops/traffic_ops_golang/test/helpers.go | 3 +--
4 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservicesv13.go b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservicesv13.go
index efc385d..cd6bfa9 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservicesv13.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/deliveryservicesv13.go
@@ -615,7 +615,13 @@ func readGetDeliveryServices(params map[string]string, tx *sqlx.Tx, user *auth.C
return nil, errs, tc.DataConflictError
}
- if tenant.IsTenancyEnabledTx(tx) {
+ tenancyEnabled, err := tenant.IsTenancyEnabledTx(tx.Tx)
+ if err != nil {
+ log.Errorln("checking if tenancy is enabled: " + err.Error())
+ return nil, []error{tc.DBError}, tc.SystemError
+ }
+
+ if tenancyEnabled {
log.Debugln("Tenancy is enabled")
tenantIDs, err := tenant.GetUserTenantIDListTx(user, tx)
if err != nil {
diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go b/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go
index f367480..85a1389 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/request/requests.go
@@ -101,7 +101,12 @@ func (req *TODeliveryServiceRequest) Read(parameters map[string]string) ([]inter
if len(errs) > 0 {
return nil, errs, tc.DataConflictError
}
- if tenant.IsTenancyEnabledTx(req.ReqInfo.Tx) {
+ tenancyEnabled, err := tenant.IsTenancyEnabledTx(req.ReqInfo.Tx.Tx)
+ if err != nil {
+ log.Errorln("checking if tenancy is enabled: " + err.Error())
+ return nil, []error{tc.DBError}, tc.SystemError
+ }
+ if tenancyEnabled {
log.Debugln("Tenancy is enabled")
tenantIDs, err := tenant.GetUserTenantIDListTx(req.ReqInfo.User, req.ReqInfo.Tx)
if err != nil {
diff --git a/traffic_ops/traffic_ops_golang/origin/origins.go b/traffic_ops/traffic_ops_golang/origin/origins.go
index 0693ff5..16b32e7 100644
--- a/traffic_ops/traffic_ops_golang/origin/origins.go
+++ b/traffic_ops/traffic_ops_golang/origin/origins.go
@@ -131,8 +131,11 @@ func (origin *TOOrigin) IsTenantAuthorized(user *auth.CurrentUser) (bool, error)
if err != nil {
return false, err
}
-
- if currentTenantID != nil && tenant.IsTenancyEnabledTx(origin.ReqInfo.Tx) {
+ tenancyEnabled, err := tenant.IsTenancyEnabledTx(origin.ReqInfo.Tx.Tx)
+ if err != nil {
+ return false, err
+ }
+ if currentTenantID != nil && tenancyEnabled {
return tenant.IsResourceAuthorizedToUserTx(*currentTenantID, user, origin.ReqInfo.Tx.Tx)
}
@@ -178,7 +181,11 @@ func (origin *TOOrigin) Read(params map[string]string) ([]interface{}, []error,
}
var err error
- if tenant.IsTenancyEnabledTx(origin.ReqInfo.Tx) {
+ tenancyEnabled, err := tenant.IsTenancyEnabledTx(origin.ReqInfo.Tx.Tx)
+ if err != nil {
+ return nil, []error{errors.New("Error checking if tenancy enabled.")}, tc.SystemError
+ }
+ if tenancyEnabled {
origins, err = filterAuthorized(origins, origin.ReqInfo.User, origin.ReqInfo.Tx)
if err != nil {
log.Errorln("Checking tenancy: " + err.Error())
@@ -271,7 +278,11 @@ LEFT JOIN tenant t ON o.tenant = t.id`
}
func checkTenancy(originTenantID, deliveryserviceID *int, tx *sqlx.Tx, user *auth.CurrentUser) (error, tc.ApiErrorType) {
- if tenant.IsTenancyEnabledTx(tx) {
+ tenancyEnabled, err := tenant.IsTenancyEnabledTx(tx.Tx)
+ if err != nil {
+ return errors.New("Error checking if tenancy enabled."), tc.SystemError
+ }
+ if tenancyEnabled {
if originTenantID == nil {
return tc.NilTenantError, tc.ForbiddenError
}
diff --git a/traffic_ops/traffic_ops_golang/test/helpers.go b/traffic_ops/traffic_ops_golang/test/helpers.go
index 0c63660..8c0a57d 100644
--- a/traffic_ops/traffic_ops_golang/test/helpers.go
+++ b/traffic_ops/traffic_ops_golang/test/helpers.go
@@ -20,11 +20,10 @@ package test
*/
import (
+ "errors"
"reflect"
"sort"
"strings"
-
- "github.com/pkg/errors"
)
// Extract the tag annotations from a struct into a string array