rob05c commented on a change in pull request #3964: Add GET/POST/DELETE for server_server_capabilities URL: https://github.com/apache/trafficcontrol/pull/3964#discussion_r334682320
########## File path: traffic_ops/traffic_ops_golang/server/servers_server_capability.go ########## @@ -0,0 +1,167 @@ +package server + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import ( + "errors" + "net/http" + + "github.com/apache/trafficcontrol/lib/go-tc" + "github.com/apache/trafficcontrol/lib/go-tc/tovalidate" + "github.com/apache/trafficcontrol/lib/go-util" + "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api" + "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/dbhelpers" + validation "github.com/go-ozzo/ozzo-validation" +) + +const ( + ServerCapabilityQueryParam = "serverCapability" + ServerQueryParam = "serverId" + ServerHostNameQueryParam = "serverHostName" +) + +// we need a type alias to define functions on +type TOServerServerCapability struct { + api.APIInfoImpl `json:"-"` + tc.ServerServerCapability +} + +func (ssc *TOServerServerCapability) SetLastUpdated(t tc.TimeNoMod) { ssc.LastUpdated = &t } +func (ssc *TOServerServerCapability) NewReadObj() interface{} { + return &tc.ServerServerCapability{} +} +func (ssc *TOServerServerCapability) SelectQuery() string { return scSelectQuery() } +func (ssc *TOServerServerCapability) ParamColumns() map[string]dbhelpers.WhereColumnInfo { + return map[string]dbhelpers.WhereColumnInfo{ + ServerCapabilityQueryParam: dbhelpers.WhereColumnInfo{"sc.server_capability", nil}, + ServerQueryParam: dbhelpers.WhereColumnInfo{"s.id", api.IsInt}, + ServerHostNameQueryParam: dbhelpers.WhereColumnInfo{"s.host_name", nil}, + } + +} +func (ssc *TOServerServerCapability) DeleteQuery() string { return scDeleteQuery() } + +func (ssc TOServerServerCapability) GetKeyFieldsInfo() []api.KeyFieldInfo { + return []api.KeyFieldInfo{ + {ServerQueryParam, api.GetIntKey}, + {ServerCapabilityQueryParam, api.GetStringKey}, + } +} + +// Need to satisfy Identifier interface but is a no-op as path does not have Update +func (ssc TOServerServerCapability) GetKeys() (map[string]interface{}, bool) { + if ssc.ServerID == nil { + return map[string]interface{}{ServerQueryParam: 0}, false + } + if ssc.ServerCapability == nil { + return map[string]interface{}{ServerCapabilityQueryParam: 0}, false + } + return map[string]interface{}{ + ServerQueryParam: *ssc.ServerID, + ServerCapabilityQueryParam: *ssc.ServerCapability, + }, true +} + +func (ssc *TOServerServerCapability) SetKeys(keys map[string]interface{}) { + sID, _ := keys[ServerQueryParam].(int) + ssc.ServerID = &sID + + sc, _ := keys[ServerCapabilityQueryParam].(string) + ssc.ServerCapability = &sc +} + +func (ssc *TOServerServerCapability) GetAuditName() string { + if ssc.ServerCapability != nil { + return *ssc.ServerCapability + } + return "unknown" +} + +func (ssc *TOServerServerCapability) GetType() string { + return "server server_capability" +} + +// Validate fulfills the api.Validator interface +func (ssc TOServerServerCapability) Validate() error { + errs := validation.Errors{ + ServerQueryParam: validation.Validate(ssc.ServerID, validation.Required), + ServerCapabilityQueryParam: validation.Validate(ssc.ServerCapability, validation.Required), + } + + return util.JoinErrs(tovalidate.ToErrors(errs)) +} + +func (ssc *TOServerServerCapability) Update() (error, error, int) { + return nil, nil, http.StatusNotImplemented Review comment: Yeah, Not Implemented is fine. It isn't really an error in the sense of something that went wrong on the server which can be potentially exploited by an attacker. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services