dangogh closed pull request #1836: renames privlevel variables according to
their associated role
URL: https://github.com/apache/incubator-trafficcontrol/pull/1836
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/traffic_ops/traffic_ops_golang/auth/authorize.go
b/traffic_ops/traffic_ops_golang/auth/authorize.go
index 1f7df096ac..e1a5c772e6 100644
--- a/traffic_ops/traffic_ops_golang/auth/authorize.go
+++ b/traffic_ops/traffic_ops_golang/auth/authorize.go
@@ -39,13 +39,18 @@ type CurrentUser struct {
// PrivLevelInvalid - The Default Priv level
const PrivLevelInvalid = -1
-// PrivLevelReadOnly - The user cannot do any API updates
const PrivLevelReadOnly = 10
-// PrivLevelOperations - The user has minimal privileges
+const PrivLevelORT = 11
+
+const PrivLevelSteering = 15
+
+const PrivLevelFederation = 15
+
+const PrivLevelPortal = 15
+
const PrivLevelOperations = 20
-// PrivLevelAdmin - The user has full privileges
const PrivLevelAdmin = 30
// TenantIDInvalid - The default Tenant ID
diff --git a/traffic_ops/traffic_ops_golang/cdn/cdns.go
b/traffic_ops/traffic_ops_golang/cdn/cdns.go
index 866e9b7b46..dd5265430f 100644
--- a/traffic_ops/traffic_ops_golang/cdn/cdns.go
+++ b/traffic_ops/traffic_ops_golang/cdn/cdns.go
@@ -33,8 +33,6 @@ import (
"github.com/lib/pq"
)
-const CDNsPrivLevel = 10
-
//we need a type alias to define functions on
type TOCDN tc.CDN
diff --git a/traffic_ops/traffic_ops_golang/divisions.go
b/traffic_ops/traffic_ops_golang/divisions.go
index 7e4cfd1529..556a22a4ef 100644
--- a/traffic_ops/traffic_ops_golang/divisions.go
+++ b/traffic_ops/traffic_ops_golang/divisions.go
@@ -30,8 +30,6 @@ import (
"github.com/jmoiron/sqlx"
)
-const DivisionsPrivLevel = 10
-
func divisionsHandler(db *sqlx.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErrs := tc.GetHandleErrorsFunc(w, r)
diff --git a/traffic_ops/traffic_ops_golang/hwinfo.go
b/traffic_ops/traffic_ops_golang/hwinfo.go
index 393c43c6da..a50b949237 100644
--- a/traffic_ops/traffic_ops_golang/hwinfo.go
+++ b/traffic_ops/traffic_ops_golang/hwinfo.go
@@ -30,8 +30,6 @@ import (
"github.com/jmoiron/sqlx"
)
-const HWInfoPrivLevel = 10
-
func hwInfoHandler(db *sqlx.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErrs := tc.GetHandleErrorsFunc(w, r)
diff --git a/traffic_ops/traffic_ops_golang/monitoring.go
b/traffic_ops/traffic_ops_golang/monitoring.go
index 0de7e24321..7835b0b5c8 100644
--- a/traffic_ops/traffic_ops_golang/monitoring.go
+++ b/traffic_ops/traffic_ops_golang/monitoring.go
@@ -32,11 +32,8 @@ import (
"github.com/apache/incubator-trafficcontrol/lib/go-tc"
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/api"
-
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth"
)
-const MonitoringPrivLevel = auth.PrivLevelReadOnly
-
const CacheMonitorConfigFile = "rascal.properties"
const MonitorType = "RASCAL"
const RouterType = "CCR"
diff --git a/traffic_ops/traffic_ops_golang/parameters.go
b/traffic_ops/traffic_ops_golang/parameters.go
index 5527b32978..e3c97e7773 100644
--- a/traffic_ops/traffic_ops_golang/parameters.go
+++ b/traffic_ops/traffic_ops_golang/parameters.go
@@ -33,8 +33,6 @@ import (
"github.com/jmoiron/sqlx"
)
-const ParametersPrivLevel = auth.PrivLevelReadOnly
-
func parametersHandler(db *sqlx.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErrs := tc.GetHandleErrorsFunc(w, r)
diff --git a/traffic_ops/traffic_ops_golang/phys_locations.go
b/traffic_ops/traffic_ops_golang/phys_locations.go
index 2a08ca6d11..538970d950 100644
--- a/traffic_ops/traffic_ops_golang/phys_locations.go
+++ b/traffic_ops/traffic_ops_golang/phys_locations.go
@@ -31,8 +31,6 @@ import (
"github.com/jmoiron/sqlx"
)
-const PhysLocationsPrivLevel = 10
-
func physLocationsHandler(db *sqlx.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErrs := tc.GetHandleErrorsFunc(w, r)
diff --git a/traffic_ops/traffic_ops_golang/regions.go
b/traffic_ops/traffic_ops_golang/regions.go
index 00eadfde64..3b06f23810 100644
--- a/traffic_ops/traffic_ops_golang/regions.go
+++ b/traffic_ops/traffic_ops_golang/regions.go
@@ -31,7 +31,6 @@ import (
"github.com/jmoiron/sqlx"
)
-const RegionsPrivLevel = 10
func regionsHandler(db *sqlx.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
diff --git a/traffic_ops/traffic_ops_golang/routes.go
b/traffic_ops/traffic_ops_golang/routes.go
index 49a3fd429c..f3cac4156e 100644
--- a/traffic_ops/traffic_ops_golang/routes.go
+++ b/traffic_ops/traffic_ops_golang/routes.go
@@ -60,10 +60,10 @@ func Routes(d ServerData) ([]Route, http.Handler, error) {
{1.2, http.MethodGet, `cdns/health$`,
handlerToFunc(proxyHandler), 0, NoAuth, []Middleware{}},
{1.2, http.MethodGet, `cdns/routing$`,
handlerToFunc(proxyHandler), 0, NoAuth, []Middleware{}},
- {1.2, http.MethodGet,
`cdns/{name}/configs/monitoring(\.json)?$`, monitoringHandler(d.DB),
MonitoringPrivLevel, Authenticated, nil},
+ {1.2, http.MethodGet,
`cdns/{name}/configs/monitoring(\.json)?$`, monitoringHandler(d.DB),
auth.PrivLevelReadOnly, Authenticated, nil},
//CDN generic handlers:
- {1.3, http.MethodGet, `cdns/?(\.json)?$`,
api.ReadHandler(cdn.GetRefType(), d.DB), cdn.CDNsPrivLevel, Authenticated, nil},
- {1.3, http.MethodGet, `cdns/{id}$`,
api.ReadHandler(cdn.GetRefType(), d.DB), cdn.CDNsPrivLevel, Authenticated, nil},
+ {1.3, http.MethodGet, `cdns/?(\.json)?$`,
api.ReadHandler(cdn.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated,
nil},
+ {1.3, http.MethodGet, `cdns/{id}$`,
api.ReadHandler(cdn.GetRefType(), d.DB), auth.PrivLevelReadOnly, Authenticated,
nil},
{1.3, http.MethodPut, `cdns/{id}$`,
api.UpdateHandler(cdn.GetRefType(), d.DB), auth.PrivLevelOperations,
Authenticated, nil},
{1.3, http.MethodPost, `cdns/?$`,
api.CreateHandler(cdn.GetRefType(), d.DB), auth.PrivLevelOperations,
Authenticated, nil},
{1.3, http.MethodDelete, `cdns/{id}$`,
api.DeleteHandler(cdn.GetRefType(), d.DB), auth.PrivLevelOperations,
Authenticated, nil},
@@ -74,14 +74,14 @@ func Routes(d ServerData) ([]Route, http.Handler, error) {
{1.3, http.MethodPut, `deliveryservices/{xmlID}/urisignkeys$`,
saveDeliveryServiceURIKeysHandler(d.DB, d.Config), auth.PrivLevelAdmin,
Authenticated, nil},
{1.3, http.MethodDelete,
`deliveryservices/{xmlID}/urisignkeys$`,
removeDeliveryServiceURIKeysHandler(d.DB, d.Config), auth.PrivLevelAdmin,
Authenticated, nil},
//Divisions
- {1.2, http.MethodGet, `divisions/?(\.json)?$`,
divisionsHandler(d.DB), DivisionsPrivLevel, Authenticated, nil},
+ {1.2, http.MethodGet, `divisions/?(\.json)?$`,
divisionsHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
//HwInfo
- {1.2, http.MethodGet, `hwinfo-wip/?(\.json)?$`,
hwInfoHandler(d.DB), HWInfoPrivLevel, Authenticated, nil},
+ {1.2, http.MethodGet, `hwinfo-wip/?(\.json)?$`,
hwInfoHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
//Parameters
- {1.3, http.MethodGet, `parameters/?(\.json)?$`,
parametersHandler(d.DB), ParametersPrivLevel, Authenticated, nil},
+ {1.3, http.MethodGet, `parameters/?(\.json)?$`,
parametersHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
//Regions
- {1.2, http.MethodGet, `regions/?(\.json)?$`,
regionsHandler(d.DB), RegionsPrivLevel, Authenticated, nil},
- {1.2, http.MethodGet, `regions/{id}$`, regionsHandler(d.DB),
RegionsPrivLevel, Authenticated, nil},
+ {1.2, http.MethodGet, `regions/?(\.json)?$`,
regionsHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+ {1.2, http.MethodGet, `regions/{id}$`, regionsHandler(d.DB),
auth.PrivLevelReadOnly, Authenticated, nil},
//Servers
// explicitly passed to legacy system until fully implemented.
Auth handled by legacy system.
{1.2, http.MethodGet, `servers/checks$`,
handlerToFunc(proxyHandler), 0, NoAuth, []Middleware{}},
@@ -89,8 +89,8 @@ func Routes(d ServerData) ([]Route, http.Handler, error) {
{1.2, http.MethodGet, `servers/status$`,
handlerToFunc(proxyHandler), 0, NoAuth, []Middleware{}},
{1.2, http.MethodGet, `servers/totals$`,
handlerToFunc(proxyHandler), 0, NoAuth, []Middleware{}},
- {1.2, http.MethodGet, `servers/?(\.json)?$`,
serversHandler(d.DB), ServersPrivLevel, Authenticated, nil},
- {1.2, http.MethodGet, `servers/{id}$`, serversHandler(d.DB),
ServersPrivLevel, Authenticated, nil},
+ {1.2, http.MethodGet, `servers/?(\.json)?$`,
serversHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+ {1.2, http.MethodGet, `servers/{id}$`, serversHandler(d.DB),
auth.PrivLevelReadOnly, Authenticated, nil},
{1.2, http.MethodPost, `servers/{id}/deliveryservices$`,
assignDeliveryServicesToServerHandler(d.DB), auth.PrivLevelOperations,
Authenticated, nil},
{1.2, http.MethodGet, `servers/{host_name}/update_status$`,
getServerUpdateStatusHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
@@ -99,14 +99,14 @@ func Routes(d ServerData) ([]Route, http.Handler, error) {
{1.2, http.MethodGet,
`deliveryservices-wip/hostname/{hostName}/sslkeys$`,
getDeliveryServiceSSLKeysByHostNameHandler(d.DB, d.Config),
auth.PrivLevelAdmin, Authenticated, nil},
{1.2, http.MethodPost,
`deliveryservices-wip/hostname/{hostName}/sslkeys/add$`,
addDeliveryServiceSSLKeysHandler(d.DB, d.Config), auth.PrivLevelAdmin,
Authenticated, nil},
//Statuses
- {1.2, http.MethodGet, `statuses/?(\.json)?$`,
statusesHandler(d.DB), StatusesPrivLevel, Authenticated, nil},
- {1.2, http.MethodGet, `statuses/{id}$`, statusesHandler(d.DB),
StatusesPrivLevel, Authenticated, nil},
+ {1.2, http.MethodGet, `statuses/?(\.json)?$`,
statusesHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+ {1.2, http.MethodGet, `statuses/{id}$`, statusesHandler(d.DB),
auth.PrivLevelReadOnly, Authenticated, nil},
//System
- {1.2, http.MethodGet, `system/info/?(\.json)?$`,
systemInfoHandler(d.DB), SystemInfoPrivLevel, Authenticated, nil},
+ {1.2, http.MethodGet, `system/info/?(\.json)?$`,
systemInfoHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
//Phys_Locations
- {1.2, http.MethodGet, `phys_locations/?(\.json)?$`,
physLocationsHandler(d.DB), PhysLocationsPrivLevel, Authenticated, nil},
- {1.2, http.MethodGet, `phys_locations/{id}$`,
physLocationsHandler(d.DB), PhysLocationsPrivLevel, Authenticated, nil},
+ {1.2, http.MethodGet, `phys_locations/?(\.json)?$`,
physLocationsHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
+ {1.2, http.MethodGet, `phys_locations/{id}$`,
physLocationsHandler(d.DB), auth.PrivLevelReadOnly, Authenticated, nil},
}
return routes, proxyHandler, nil
}
diff --git a/traffic_ops/traffic_ops_golang/routing_test.go
b/traffic_ops/traffic_ops_golang/routing_test.go
index 265a558c06..e3ed1870da 100644
--- a/traffic_ops/traffic_ops_golang/routing_test.go
+++ b/traffic_ops/traffic_ops_golang/routing_test.go
@@ -28,6 +28,8 @@ import (
"bytes"
"context"
"net/http/httptest"
+
+
"github.com/apache/incubator-trafficcontrol/traffic_ops/traffic_ops_golang/auth"
)
func TestCreateRouteMap(t *testing.T) {
@@ -57,7 +59,7 @@ func TestCreateRouteMap(t *testing.T) {
}
routes := []Route{
- {1.2, http.MethodGet, `path1`, PathOneHandler,
ServersPrivLevel, true, nil},
+ {1.2, http.MethodGet, `path1`, PathOneHandler,
auth.PrivLevelReadOnly, true, nil},
{1.2, http.MethodGet, `path2`, PathTwoHandler, 0, false, nil},
{1.2, http.MethodGet, `path3`, PathThreeHandler, 0, false,
[]Middleware{}},
}
diff --git a/traffic_ops/traffic_ops_golang/servers.go
b/traffic_ops/traffic_ops_golang/servers.go
index 364f791eeb..4e7e776fd5 100644
--- a/traffic_ops/traffic_ops_golang/servers.go
+++ b/traffic_ops/traffic_ops_golang/servers.go
@@ -36,9 +36,6 @@ import (
"github.com/jmoiron/sqlx"
)
-// ServersPrivLevel - privileges for the /servers endpoint
-const ServersPrivLevel = 10
-
func serversHandler(db *sqlx.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErrs := tc.GetHandleErrorsFunc(w, r)
diff --git a/traffic_ops/traffic_ops_golang/statuses.go
b/traffic_ops/traffic_ops_golang/statuses.go
index 6ae06599a5..f9b5954658 100644
--- a/traffic_ops/traffic_ops_golang/statuses.go
+++ b/traffic_ops/traffic_ops_golang/statuses.go
@@ -34,8 +34,6 @@ import (
"github.com/jmoiron/sqlx"
)
-const StatusesPrivLevel = 10
-
func statusesHandler(db *sqlx.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErrs := tc.GetHandleErrorsFunc(w, r)
diff --git a/traffic_ops/traffic_ops_golang/system_info.go
b/traffic_ops/traffic_ops_golang/system_info.go
index da0c0815ac..62e845b247 100644
--- a/traffic_ops/traffic_ops_golang/system_info.go
+++ b/traffic_ops/traffic_ops_golang/system_info.go
@@ -30,8 +30,6 @@ import (
"github.com/jmoiron/sqlx"
)
-const SystemInfoPrivLevel = 10
-
func systemInfoHandler(db *sqlx.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
handleErrs := tc.GetHandleErrorsFunc(w, r)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services