Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions traffic_ops/traffic_ops_golang/server/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,20 +475,23 @@ func validateCommonV40(s *tc.ServerV40, tx *sql.Tx) ([]error, error) {
}

var cdnID int
if err := tx.QueryRow("SELECT cdn from profile WHERE name=$1", s.ProfileNames[0]).Scan(&cdnID); err != nil {
log.Errorf("could not execute select cdnID from profile: %s\n", err)
if errors.Is(err, sql.ErrNoRows) {
errs = append(errs, fmt.Errorf("no such profileName: '%s'", s.ProfileNames[0]))
} else {
return nil, fmt.Errorf("unable to get CDN ID for profile name '%s': %w", s.ProfileNames[0], err)
for _, profile := range s.ProfileNames {
if err := tx.QueryRow("SELECT cdn from profile WHERE name=$1", profile).Scan(&cdnID); err != nil {
log.Errorf("could not execute select cdnID from profile: %s\n", err)
if errors.Is(err, sql.ErrNoRows) {
errs = append(errs, fmt.Errorf("no such profileName: '%s'", profile))
} else {
return nil, fmt.Errorf("unable to get CDN ID for profile name '%s': %w", profile, err)
}
return errs, nil
}
return errs, nil
}

log.Infof("got cdn id: %d from profile and cdn id: %d from server", cdnID, *s.CDNID)
if cdnID != *s.CDNID {
errs = append(errs, fmt.Errorf("CDN id '%d' for profile '%v' does not match Server CDN '%d'", cdnID, s.ProfileNames[0], *s.CDNID))
log.Infof("got cdn id: %d from profile and cdn id: %d from server", cdnID, *s.CDNID)
if cdnID != *s.CDNID {
errs = append(errs, fmt.Errorf("CDN id '%d' for profile '%v' does not match Server CDN '%d'", cdnID, profile, *s.CDNID))
}
}

return errs, nil
}

Expand Down Expand Up @@ -1859,7 +1862,6 @@ func createV2(inf *api.APIInfo, w http.ResponseWriter, r *http.Request) {
}
}

origProfiles := []string{*server.Profile}
serverID, err := createServerV2(inf.Tx, server)
if err != nil {
userErr, sysErr, errCode := api.ParseDBError(err)
Expand All @@ -1878,6 +1880,14 @@ func createV2(inf *api.APIInfo, w http.ResponseWriter, r *http.Request) {
return
}

var origProfile string
err = inf.Tx.Tx.QueryRow("SELECT name from profile where id = $1", server.ProfileID).Scan(&origProfile)
if err != nil && err != sql.ErrNoRows {
api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("retreiving profile with id %d", *server.ProfileID))
return
}
var origProfiles = []string{origProfile}

userErr, sysErr, statusCode := insertServerProfile(int(serverID), origProfiles, inf.Tx.Tx)
if userErr != nil || sysErr != nil {
api.HandleErr(w, r, inf.Tx.Tx, statusCode, userErr, sysErr)
Expand Down Expand Up @@ -1978,7 +1988,6 @@ func createV3(inf *api.APIInfo, w http.ResponseWriter, r *http.Request) {

currentTime := time.Now()
server.StatusLastUpdated = &currentTime
origProfiles := []string{*server.Profile}

if server.CDNName != nil {
userErr, sysErr, statusCode := dbhelpers.CheckIfCurrentUserCanModifyCDN(inf.Tx.Tx, *server.CDNName, inf.User.UserName)
Expand Down Expand Up @@ -2012,6 +2021,14 @@ func createV3(inf *api.APIInfo, w http.ResponseWriter, r *http.Request) {
return
}

var origProfile string
err = inf.Tx.Tx.QueryRow("SELECT name from profile where id = $1", server.ProfileID).Scan(&origProfile)
if err != nil && err != sql.ErrNoRows {
api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("retreiving profile with id %d", *server.ProfileID))
return
}
var origProfiles = []string{origProfile}

userErr, sysErr, statusCode := insertServerProfile(int(serverID), origProfiles, inf.Tx.Tx)
if userErr != nil || sysErr != nil {
api.HandleErr(w, r, inf.Tx.Tx, statusCode, userErr, sysErr)
Expand Down