rawlinp commented on a change in pull request #2928: TO Client: no ids
required in input json
URL: https://github.com/apache/trafficcontrol/pull/2928#discussion_r230221032
##########
File path: traffic_ops/client/origin.go
##########
@@ -28,12 +29,75 @@ const (
API_v13_Origins = "/api/1.3/origins"
)
+func originIDs(to *Session, origin *tc.Origin) error {
+ if origin.CachegroupID == nil && origin.Cachegroup != nil {
+ p, _, err := to.GetCacheGroupByName(*origin.Cachegroup)
+ if err != nil {
+ return err
+ }
+ if len(p) == 0 {
+ return errors.New("no cachegroup named " +
*origin.Cachegroup)
+ }
+ origin.CachegroupID = &p[0].ID
+ }
+
+ if origin.DeliveryServiceID == nil && origin.DeliveryService != nil {
+ dses, _, err :=
to.GetDeliveryServiceByXMLID(*origin.DeliveryService)
+ if err != nil {
+ return err
+ }
+ if len(dses) == 0 {
+ return errors.New("no deliveryservice with name " +
*origin.DeliveryService)
+ }
+ origin.DeliveryServiceID = &dses[0].ID
+ }
+
+ if origin.ProfileID == nil && origin.Profile != nil {
+ profiles, _, err := to.GetProfileByName(*origin.Profile)
+ if err != nil {
+ return err
+ }
+ if len(profiles) == 0 {
+ return errors.New("no profile with name " +
*origin.Profile)
+ }
+ origin.ProfileID = &profiles[0].ID
+ }
+
+ if origin.CoordinateID == nil && origin.Coordinate != nil {
+ coordinates, _, err :=
to.GetCoordinateByName(*origin.Coordinate)
+ if err != nil {
+ return err
+ }
+ if len(coordinates) == 0 {
+ return errors.New("no coordinate with name " +
*origin.Coordinate)
+ }
+ origin.CoordinateID = &coordinates[0].ID
+ }
+
+ if origin.TenantID == nil && origin.Tenant != nil {
+ tenant, _, err := to.TenantByName(*origin.Tenant)
+ if err != nil {
+ return err
+ }
+ origin.TenantID = &tenant.ID
+ }
+
+ return nil
+}
+
// Create an Origin
func (to *Session) CreateOrigin(origin tc.Origin) (*tc.OriginDetailResponse,
ReqInf, error) {
-
var remoteAddr net.Addr
- reqBody, err := json.Marshal(origin)
reqInf := ReqInf{CacheHitStatus: CacheHitStatusMiss, RemoteAddr:
remoteAddr}
+
+ fmt.Printf("Origin before: %+v\n", origin)
Review comment:
These before/after lines should be removed.
----------------------------------------------------------------
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