You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by "shamrickus (via GitHub)" <gi...@apache.org> on 2023/06/01 15:36:27 UTC
[GitHub] [trafficcontrol] shamrickus opened a new pull request, #7549: Update CDN v5 endpoints to use RFC3339 timestamps
shamrickus opened a new pull request, #7549:
URL: https://github.com/apache/trafficcontrol/pull/7549
<!--
Thank you for contributing! Please be sure to read our contribution guidelines: https://github.com/apache/trafficcontrol/blob/master/CONTRIBUTING.md
If this closes or relates to an existing issue, please reference it using one of the following:
Closes: #ISSUE
Related: #ISSUE
If this PR fixes a security vulnerability, DO NOT submit! Instead, contact
the Apache Traffic Control Security Team at security@trafficcontrol.apache.org and follow the
guidelines at https://apache.org/security regarding vulnerability disclosure.
-->
This PR updates the `cdns` v5 TO endpoints to return `lastUpdated` in the format of `RFC3339`
<!-- **^ Add meaningful description above** --><hr/>
## Which Traffic Control components are affected by this PR?
<!-- Please delete all components from this list that are NOT affected by this PR.
Feel free to add the name of a tool or script that is affected but not on the list.
-->
- Documentation
- Traffic Ops
## What is the best way to verify this PR?
Query the CRUD CDNs endpoint in API version 5 to confirm RFC3339 format, also query version 4 to confirm the time format has _not_ changed.
<!-- Please include here ALL the steps necessary to test your PR.
If your PR has tests (and most should), provide the steps needed to run the tests.
If not, please provide step-by-step instructions to test the PR manually and explain why your PR does not need tests. -->
<!-- Delete this section if the PR is not a bugfix, or if the bug is only in the master branch.
Examples:
- 5.1.2
- 5.1.3 (RC1)
-->
## PR submission checklist
- [x] This PR has tests <!-- If not, please delete this text and explain why this PR does not need tests. -->
- [x] This PR has documentation <!-- If not, please delete this text and explain why this PR does not need documentation. -->
- [ ] This PR has a CHANGELOG.md entry <!-- A fix for a bug from an ATC release, an improvement, or a new feature should have a changelog entry. -->
- [x] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://apache.org/security) for details)
<!--
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.
-->
--
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.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficcontrol] github-code-scanning[bot] commented on a diff in pull request #7549: Update CDN v5 endpoints to use RFC3339 timestamps
Posted by "github-code-scanning[bot] (via GitHub)" <gi...@apache.org>.
github-code-scanning[bot] commented on code in PR #7549:
URL: https://github.com/apache/trafficcontrol/pull/7549#discussion_r1275267630
##########
traffic_ops/traffic_ops_golang/cdn/cdns.go:
##########
@@ -20,71 +20,297 @@
*/
import (
+ "database/sql"
+ "encoding/json"
+ "errors"
"fmt"
"net/http"
"strconv"
"strings"
"time"
+ "github.com/apache/trafficcontrol/lib/go-log"
"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"
+ "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/util/ims"
"github.com/asaskevich/govalidator"
validation "github.com/go-ozzo/ozzo-validation"
)
-// we need a type alias to define functions on
+// TOCDN is the struct needed for the CRUDer
type TOCDN struct {
api.APIInfoImpl `json:"-"`
tc.CDNNullable
}
-func (v *TOCDN) GetLastUpdated() (*time.Time, bool, error) {
- return api.GetLastUpdated(v.APIInfo().Tx, *v.ID, "cdn")
+func Read(w http.ResponseWriter, r *http.Request) {
+ var runSecond bool
+ var maxTime time.Time
+ inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+ tx := inf.Tx
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, tx.Tx, errCode, userErr, sysErr)
+ return
+ }
+ defer inf.Close()
+
+ // Query Parameters to Database Query column mappings
+ queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+ "domainName": dbhelpers.WhereColumnInfo{Column: "domain_name"},
+ "dnssecEnabled": dbhelpers.WhereColumnInfo{Column: "dnssec_enabled"},
+ "id": dbhelpers.WhereColumnInfo{Column: "id", Checker: api.IsInt},
+ "name": dbhelpers.WhereColumnInfo{Column: "name"},
+ }
+ if inf.Version.GreaterThanOrEqualTo(&api.Version{Major: 4, Minor: 1}) {
+ queryParamsToQueryCols["ttlOverride"] = dbhelpers.WhereColumnInfo{Column: "ttl_override", Checker: api.IsInt}
+ }
+
+ if _, ok := inf.Params["orderby"]; !ok {
+ inf.Params["orderby"] = "name"
+ }
+ where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+ if len(errs) > 0 {
+ api.HandleErr(w, r, tx.Tx, http.StatusBadRequest, util.JoinErrs(errs), nil)
+ }
+
+ if inf.Config.UseIMS {
+ runSecond, maxTime = ims.TryIfModifiedSinceQuery(tx, r.Header, queryValues, SelectMaxLastUpdatedQuery(where))
+ if !runSecond {
+ log.Debugln("IMS HIT")
+ api.AddLastModifiedHdr(w, maxTime)
+ w.WriteHeader(http.StatusNotModified)
+ return
+ }
+ log.Debugln("IMS MISS")
+ } else {
+ log.Debugln("Non IMS request")
+ }
+
+ query := selectQuery(inf.Version) + where + orderBy + pagination
+ rows, err := tx.NamedQuery(query, queryValues)
Review Comment:
## Database query built from user-controlled sources
This query depends on a [user-provided value](1).
[Show more details](https://github.com/apache/trafficcontrol/security/code-scanning/295)
--
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.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficcontrol] rimashah25 commented on a diff in pull request #7549: Update CDN v5 endpoints to use RFC3339 timestamps
Posted by "rimashah25 (via GitHub)" <gi...@apache.org>.
rimashah25 commented on code in PR #7549:
URL: https://github.com/apache/trafficcontrol/pull/7549#discussion_r1220837137
##########
docs/source/api/v5/cdns.rst:
##########
@@ -89,15 +89,15 @@ Response Structure
"dnssecEnabled": false,
"domainName": "-",
"id": 1,
- "lastUpdated": "2018-11-14 18:21:06+00",
+ "lastUpdated": "2018-11-14T18:21.516553Z",
Review Comment:
RFC3339 format is as follows: 2023-06-06T22:44:53.557642-06:00. Why is it different in this file?
##########
traffic_ops/traffic_ops_golang/cdn/cdns.go:
##########
Review Comment:
Aren't we trying to get rid of cruder? If yes, then why add cruder functionality in V5 instead of adding Read/Update/Create/Delete functions?
##########
traffic_ops/traffic_ops_golang/routing/routes.go:
##########
@@ -367,10 +367,10 @@ func Routes(d ServerData) ([]Route, http.Handler, error) {
{Version: api.Version{Major: 5, Minor: 0}, Method: http.MethodDelete, Path: `cdn_notifications/?$`, Handler: cdnnotification.Delete, RequiredPrivLevel: auth.PrivLevelOperations, RequiredPermissions: []string{"CDN:UPDATE"}, Authenticated: Authenticated, Middlewares: nil, ID: 27224118511},
//CDN generic handlers:
Review Comment:
Wouldn't it make more sense to get rid of cruder functionality?
--
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.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficcontrol] github-code-scanning[bot] commented on a diff in pull request #7549: Update CDN v5 endpoints to use RFC3339 timestamps
Posted by "github-code-scanning[bot] (via GitHub)" <gi...@apache.org>.
github-code-scanning[bot] commented on code in PR #7549:
URL: https://github.com/apache/trafficcontrol/pull/7549#discussion_r1276568867
##########
traffic_ops/traffic_ops_golang/cdn/cdns.go:
##########
@@ -20,71 +20,324 @@
*/
import (
+ "database/sql"
+ "encoding/json"
+ "errors"
"fmt"
"net/http"
"strconv"
"strings"
"time"
+ "github.com/apache/trafficcontrol/lib/go-log"
"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"
+ "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/util/ims"
"github.com/asaskevich/govalidator"
validation "github.com/go-ozzo/ozzo-validation"
)
-// we need a type alias to define functions on
+// TOCDN is the struct needed for the CRUDer
type TOCDN struct {
api.APIInfoImpl `json:"-"`
tc.CDNNullable
}
-func (v *TOCDN) GetLastUpdated() (*time.Time, bool, error) {
- return api.GetLastUpdated(v.APIInfo().Tx, *v.ID, "cdn")
+func Read(w http.ResponseWriter, r *http.Request) {
+ var runSecond bool
+ var maxTime time.Time
+ inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+ tx := inf.Tx
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, tx.Tx, errCode, userErr, sysErr)
+ return
+ }
+ defer inf.Close()
+
+ // Query Parameters to Database Query column mappings
+ queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+ "domainName": dbhelpers.WhereColumnInfo{Column: "domain_name"},
+ "dnssecEnabled": dbhelpers.WhereColumnInfo{Column: "dnssec_enabled"},
+ "id": dbhelpers.WhereColumnInfo{Column: "id", Checker: api.IsInt},
+ "name": dbhelpers.WhereColumnInfo{Column: "name"},
+ "ttlOverride": dbhelpers.WhereColumnInfo{Column: "ttl_override", Checker: api.IsInt},
+ }
+
+ if _, ok := inf.Params["orderby"]; !ok {
+ inf.Params["orderby"] = "name"
+ }
+ where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+ if len(errs) > 0 {
+ api.HandleErr(w, r, tx.Tx, http.StatusBadRequest, util.JoinErrs(errs), nil)
+ return
+ }
+
+ if inf.Config.UseIMS {
+ runSecond, maxTime = ims.TryIfModifiedSinceQuery(tx, r.Header, queryValues, SelectMaxLastUpdatedQuery(where))
+ if !runSecond {
+ log.Debugln("IMS HIT")
+ api.AddLastModifiedHdr(w, maxTime)
+ w.WriteHeader(http.StatusNotModified)
+ return
+ }
+ log.Debugln("IMS MISS")
+ } else {
+ log.Debugln("Non IMS request")
+ }
+
+ query := selectQuery(inf.Version) + where + orderBy + pagination
+ rows, err := tx.NamedQuery(query, queryValues)
Review Comment:
## Database query built from user-controlled sources
This query depends on a [user-provided value](1).
[Show more details](https://github.com/apache/trafficcontrol/security/code-scanning/296)
--
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.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficcontrol] rimashah25 commented on a diff in pull request #7549: Update CDN v5 endpoints to use RFC3339 timestamps
Posted by "rimashah25 (via GitHub)" <gi...@apache.org>.
rimashah25 commented on code in PR #7549:
URL: https://github.com/apache/trafficcontrol/pull/7549#discussion_r1220864972
##########
docs/source/api/v5/cdns.rst:
##########
@@ -89,15 +89,15 @@ Response Structure
"dnssecEnabled": false,
"domainName": "-",
"id": 1,
- "lastUpdated": "2018-11-14 18:21:06+00",
+ "lastUpdated": "2018-11-14T18:21.516553Z",
Review Comment:
Is `516553` seconds? Shouldn't it be two digits and have a `:` after minute? or are we missing seconds and this is milliseconds?
--
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.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficcontrol] shamrickus commented on a diff in pull request #7549: Update CDN v5 endpoints to use RFC3339 timestamps
Posted by "shamrickus (via GitHub)" <gi...@apache.org>.
shamrickus commented on code in PR #7549:
URL: https://github.com/apache/trafficcontrol/pull/7549#discussion_r1279313937
##########
traffic_ops/traffic_ops_golang/cdn/cdns.go:
##########
@@ -20,71 +20,324 @@ package cdn
*/
import (
+ "database/sql"
+ "encoding/json"
+ "errors"
"fmt"
"net/http"
"strconv"
"strings"
"time"
+ "github.com/apache/trafficcontrol/lib/go-log"
"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"
+ "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/util/ims"
"github.com/asaskevich/govalidator"
validation "github.com/go-ozzo/ozzo-validation"
)
-// we need a type alias to define functions on
+// TOCDN is the struct needed for the CRUDer
type TOCDN struct {
api.APIInfoImpl `json:"-"`
tc.CDNNullable
}
-func (v *TOCDN) GetLastUpdated() (*time.Time, bool, error) {
- return api.GetLastUpdated(v.APIInfo().Tx, *v.ID, "cdn")
+func Read(w http.ResponseWriter, r *http.Request) {
+ var runSecond bool
+ var maxTime time.Time
+ inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+ tx := inf.Tx
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, tx.Tx, errCode, userErr, sysErr)
+ return
+ }
+ defer inf.Close()
+
+ // Query Parameters to Database Query column mappings
+ queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+ "domainName": dbhelpers.WhereColumnInfo{Column: "domain_name"},
+ "dnssecEnabled": dbhelpers.WhereColumnInfo{Column: "dnssec_enabled"},
+ "id": dbhelpers.WhereColumnInfo{Column: "id", Checker: api.IsInt},
+ "name": dbhelpers.WhereColumnInfo{Column: "name"},
+ "ttlOverride": dbhelpers.WhereColumnInfo{Column: "ttl_override", Checker: api.IsInt},
+ }
+
+ if _, ok := inf.Params["orderby"]; !ok {
+ inf.Params["orderby"] = "name"
+ }
+ where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+ if len(errs) > 0 {
+ api.HandleErr(w, r, tx.Tx, http.StatusBadRequest, util.JoinErrs(errs), nil)
+ return
+ }
+
+ if inf.Config.UseIMS {
+ runSecond, maxTime = ims.TryIfModifiedSinceQuery(tx, r.Header, queryValues, SelectMaxLastUpdatedQuery(where))
+ if !runSecond {
+ log.Debugln("IMS HIT")
+ api.AddLastModifiedHdr(w, maxTime)
+ w.WriteHeader(http.StatusNotModified)
+ return
+ }
+ log.Debugln("IMS MISS")
+ } else {
+ log.Debugln("Non IMS request")
+ }
+
+ query := selectQuery(inf.Version) + where + orderBy + pagination
+ rows, err := tx.NamedQuery(query, queryValues)
+ if err != nil {
+ api.HandleErr(w, r, tx.Tx, http.StatusNotFound, nil, fmt.Errorf("cdn get: error getting cdn(s): %w", err))
+ return
+ }
+ defer log.Close(rows, "unable to close DB connection")
+
+ cdn := tc.CDNV5{}
+ cdns := []tc.CDNV5{}
+ for rows.Next() {
+ if err = rows.Scan(&cdn.DNSSECEnabled, &cdn.DomainName, &cdn.ID, &cdn.LastUpdated, &cdn.TTLOverride, &cdn.Name); err != nil {
+ api.HandleErr(w, r, tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("error getting cdn(s): %w", err))
+ return
+ }
+ cdns = append(cdns, cdn)
+ }
+
+ api.WriteResp(w, r, cdns)
+ return
+}
+
+func Create(w http.ResponseWriter, r *http.Request) {
+ cdn := tc.CDNV5{}
+
+ inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+ return
+ }
+ defer inf.Close()
+ tx := inf.Tx.Tx
+
+ cdn, err := validateRequest(r, inf.Version)
+ if err != nil {
+ api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
+ return
+ }
+
+ var exists bool
+ if err = tx.QueryRow("SELECT EXISTS(SELECT id from cdn where name = $1)", cdn.Name).Scan(&exists); err != nil {
+ api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, fmt.Errorf("error: %w, when checking if cdn with name %s exists", err, cdn.Name))
+ return
+ }
+ if exists {
+ api.HandleErr(w, r, tx, http.StatusBadRequest, fmt.Errorf("cdn name '%s' already exists.", cdn.Name), nil)
+ return
+ }
+
+ cdn.DomainName = strings.ToLower(cdn.DomainName)
+
+ rows, err := inf.Tx.NamedQuery(insertQuery(inf.Version), cdn)
+ if err != nil {
+ if errors.Is(err, sql.ErrNoRows) {
+ api.HandleErr(w, r, tx, http.StatusInternalServerError, fmt.Errorf("error: %w in creating cdn with name: %s", err, cdn.Name), nil)
+ return
+ }
+ usrErr, sysErr, code := api.ParseDBError(err)
+ api.HandleErr(w, r, tx, code, usrErr, sysErr)
+ return
+ }
+ if rows.Next() {
+ if err = rows.Scan(&cdn.ID, &cdn.LastUpdated); err != nil {
+ usrErr, sysErr, code := api.ParseDBError(err)
+ api.HandleErr(w, r, tx, code, usrErr, sysErr)
+ return
+ }
+ }
+
+ alerts := tc.CreateAlerts(tc.SuccessLevel, "cdn was created.")
+ w.Header().Set("Location", fmt.Sprintf("/api/%d.%d/cdns?name=%s", inf.Version.Major, inf.Version.Minor, cdn.Name))
+ api.WriteAlertsObj(w, r, http.StatusCreated, alerts, cdn)
+ return
+}
+
+func Update(w http.ResponseWriter, r *http.Request) {
Review Comment:
Good catch.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficcontrol] jagan-parthiban commented on a diff in pull request #7549: Update CDN v5 endpoints to use RFC3339 timestamps
Posted by "jagan-parthiban (via GitHub)" <gi...@apache.org>.
jagan-parthiban commented on code in PR #7549:
URL: https://github.com/apache/trafficcontrol/pull/7549#discussion_r1279375077
##########
traffic_ops/traffic_ops_golang/cdn/cdns.go:
##########
@@ -20,71 +20,324 @@ package cdn
*/
import (
+ "database/sql"
+ "encoding/json"
+ "errors"
"fmt"
"net/http"
"strconv"
"strings"
"time"
+ "github.com/apache/trafficcontrol/lib/go-log"
"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"
+ "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/util/ims"
"github.com/asaskevich/govalidator"
validation "github.com/go-ozzo/ozzo-validation"
)
-// we need a type alias to define functions on
+// TOCDN is the struct needed for the CRUDer
type TOCDN struct {
api.APIInfoImpl `json:"-"`
tc.CDNNullable
}
-func (v *TOCDN) GetLastUpdated() (*time.Time, bool, error) {
- return api.GetLastUpdated(v.APIInfo().Tx, *v.ID, "cdn")
+func Read(w http.ResponseWriter, r *http.Request) {
+ var runSecond bool
+ var maxTime time.Time
+ inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+ tx := inf.Tx
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, tx.Tx, errCode, userErr, sysErr)
+ return
+ }
+ defer inf.Close()
+
+ // Query Parameters to Database Query column mappings
+ queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+ "domainName": dbhelpers.WhereColumnInfo{Column: "domain_name"},
+ "dnssecEnabled": dbhelpers.WhereColumnInfo{Column: "dnssec_enabled"},
+ "id": dbhelpers.WhereColumnInfo{Column: "id", Checker: api.IsInt},
+ "name": dbhelpers.WhereColumnInfo{Column: "name"},
+ "ttlOverride": dbhelpers.WhereColumnInfo{Column: "ttl_override", Checker: api.IsInt},
+ }
+
+ if _, ok := inf.Params["orderby"]; !ok {
+ inf.Params["orderby"] = "name"
+ }
+ where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+ if len(errs) > 0 {
+ api.HandleErr(w, r, tx.Tx, http.StatusBadRequest, util.JoinErrs(errs), nil)
+ return
+ }
+
+ if inf.Config.UseIMS {
+ runSecond, maxTime = ims.TryIfModifiedSinceQuery(tx, r.Header, queryValues, SelectMaxLastUpdatedQuery(where))
+ if !runSecond {
+ log.Debugln("IMS HIT")
+ api.AddLastModifiedHdr(w, maxTime)
+ w.WriteHeader(http.StatusNotModified)
+ return
+ }
+ log.Debugln("IMS MISS")
+ } else {
+ log.Debugln("Non IMS request")
+ }
+
+ query := selectQuery(inf.Version) + where + orderBy + pagination
+ rows, err := tx.NamedQuery(query, queryValues)
+ if err != nil {
+ api.HandleErr(w, r, tx.Tx, http.StatusNotFound, nil, fmt.Errorf("cdn get: error getting cdn(s): %w", err))
+ return
+ }
+ defer log.Close(rows, "unable to close DB connection")
+
+ cdn := tc.CDNV5{}
+ cdns := []tc.CDNV5{}
+ for rows.Next() {
+ if err = rows.Scan(&cdn.DNSSECEnabled, &cdn.DomainName, &cdn.ID, &cdn.LastUpdated, &cdn.TTLOverride, &cdn.Name); err != nil {
+ api.HandleErr(w, r, tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("error getting cdn(s): %w", err))
+ return
+ }
+ cdns = append(cdns, cdn)
+ }
+
+ api.WriteResp(w, r, cdns)
+ return
+}
+
+func Create(w http.ResponseWriter, r *http.Request) {
+ cdn := tc.CDNV5{}
+
+ inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+ return
+ }
+ defer inf.Close()
+ tx := inf.Tx.Tx
+
+ cdn, err := validateRequest(r, inf.Version)
+ if err != nil {
+ api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
+ return
+ }
+
+ var exists bool
+ if err = tx.QueryRow("SELECT EXISTS(SELECT id from cdn where name = $1)", cdn.Name).Scan(&exists); err != nil {
+ api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, fmt.Errorf("error: %w, when checking if cdn with name %s exists", err, cdn.Name))
+ return
+ }
+ if exists {
+ api.HandleErr(w, r, tx, http.StatusBadRequest, fmt.Errorf("cdn name '%s' already exists.", cdn.Name), nil)
+ return
+ }
+
+ cdn.DomainName = strings.ToLower(cdn.DomainName)
+
+ rows, err := inf.Tx.NamedQuery(insertQuery(inf.Version), cdn)
+ if err != nil {
+ if errors.Is(err, sql.ErrNoRows) {
+ api.HandleErr(w, r, tx, http.StatusInternalServerError, fmt.Errorf("error: %w in creating cdn with name: %s", err, cdn.Name), nil)
+ return
+ }
+ usrErr, sysErr, code := api.ParseDBError(err)
+ api.HandleErr(w, r, tx, code, usrErr, sysErr)
+ return
+ }
+ if rows.Next() {
+ if err = rows.Scan(&cdn.ID, &cdn.LastUpdated); err != nil {
+ usrErr, sysErr, code := api.ParseDBError(err)
+ api.HandleErr(w, r, tx, code, usrErr, sysErr)
+ return
+ }
+ }
+
+ alerts := tc.CreateAlerts(tc.SuccessLevel, "cdn was created.")
+ w.Header().Set("Location", fmt.Sprintf("/api/%d.%d/cdns?name=%s", inf.Version.Major, inf.Version.Minor, cdn.Name))
+ api.WriteAlertsObj(w, r, http.StatusCreated, alerts, cdn)
+ return
+}
+
+func Update(w http.ResponseWriter, r *http.Request) {
Review Comment:
Verified. PUT operation returning CDN ID.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficcontrol] jagan-parthiban commented on a diff in pull request #7549: Update CDN v5 endpoints to use RFC3339 timestamps
Posted by "jagan-parthiban (via GitHub)" <gi...@apache.org>.
jagan-parthiban commented on code in PR #7549:
URL: https://github.com/apache/trafficcontrol/pull/7549#discussion_r1279027359
##########
traffic_ops/traffic_ops_golang/cdn/cdns.go:
##########
@@ -20,71 +20,324 @@ package cdn
*/
import (
+ "database/sql"
+ "encoding/json"
+ "errors"
"fmt"
"net/http"
"strconv"
"strings"
"time"
+ "github.com/apache/trafficcontrol/lib/go-log"
"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"
+ "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/util/ims"
"github.com/asaskevich/govalidator"
validation "github.com/go-ozzo/ozzo-validation"
)
-// we need a type alias to define functions on
+// TOCDN is the struct needed for the CRUDer
type TOCDN struct {
api.APIInfoImpl `json:"-"`
tc.CDNNullable
}
-func (v *TOCDN) GetLastUpdated() (*time.Time, bool, error) {
- return api.GetLastUpdated(v.APIInfo().Tx, *v.ID, "cdn")
+func Read(w http.ResponseWriter, r *http.Request) {
+ var runSecond bool
+ var maxTime time.Time
+ inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+ tx := inf.Tx
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, tx.Tx, errCode, userErr, sysErr)
+ return
+ }
+ defer inf.Close()
+
+ // Query Parameters to Database Query column mappings
+ queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+ "domainName": dbhelpers.WhereColumnInfo{Column: "domain_name"},
+ "dnssecEnabled": dbhelpers.WhereColumnInfo{Column: "dnssec_enabled"},
+ "id": dbhelpers.WhereColumnInfo{Column: "id", Checker: api.IsInt},
+ "name": dbhelpers.WhereColumnInfo{Column: "name"},
+ "ttlOverride": dbhelpers.WhereColumnInfo{Column: "ttl_override", Checker: api.IsInt},
+ }
+
+ if _, ok := inf.Params["orderby"]; !ok {
+ inf.Params["orderby"] = "name"
+ }
+ where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+ if len(errs) > 0 {
+ api.HandleErr(w, r, tx.Tx, http.StatusBadRequest, util.JoinErrs(errs), nil)
+ return
+ }
+
+ if inf.Config.UseIMS {
+ runSecond, maxTime = ims.TryIfModifiedSinceQuery(tx, r.Header, queryValues, SelectMaxLastUpdatedQuery(where))
+ if !runSecond {
+ log.Debugln("IMS HIT")
+ api.AddLastModifiedHdr(w, maxTime)
+ w.WriteHeader(http.StatusNotModified)
+ return
+ }
+ log.Debugln("IMS MISS")
+ } else {
+ log.Debugln("Non IMS request")
+ }
+
+ query := selectQuery(inf.Version) + where + orderBy + pagination
+ rows, err := tx.NamedQuery(query, queryValues)
+ if err != nil {
+ api.HandleErr(w, r, tx.Tx, http.StatusNotFound, nil, fmt.Errorf("cdn get: error getting cdn(s): %w", err))
+ return
+ }
+ defer log.Close(rows, "unable to close DB connection")
+
+ cdn := tc.CDNV5{}
+ cdns := []tc.CDNV5{}
+ for rows.Next() {
+ if err = rows.Scan(&cdn.DNSSECEnabled, &cdn.DomainName, &cdn.ID, &cdn.LastUpdated, &cdn.TTLOverride, &cdn.Name); err != nil {
+ api.HandleErr(w, r, tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("error getting cdn(s): %w", err))
+ return
+ }
+ cdns = append(cdns, cdn)
+ }
+
+ api.WriteResp(w, r, cdns)
+ return
+}
+
+func Create(w http.ResponseWriter, r *http.Request) {
+ cdn := tc.CDNV5{}
+
+ inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, inf.Tx.Tx, errCode, userErr, sysErr)
+ return
+ }
+ defer inf.Close()
+ tx := inf.Tx.Tx
+
+ cdn, err := validateRequest(r, inf.Version)
+ if err != nil {
+ api.HandleErr(w, r, tx, http.StatusBadRequest, err, nil)
+ return
+ }
+
+ var exists bool
+ if err = tx.QueryRow("SELECT EXISTS(SELECT id from cdn where name = $1)", cdn.Name).Scan(&exists); err != nil {
+ api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, fmt.Errorf("error: %w, when checking if cdn with name %s exists", err, cdn.Name))
+ return
+ }
+ if exists {
+ api.HandleErr(w, r, tx, http.StatusBadRequest, fmt.Errorf("cdn name '%s' already exists.", cdn.Name), nil)
+ return
+ }
+
+ cdn.DomainName = strings.ToLower(cdn.DomainName)
+
+ rows, err := inf.Tx.NamedQuery(insertQuery(inf.Version), cdn)
+ if err != nil {
+ if errors.Is(err, sql.ErrNoRows) {
+ api.HandleErr(w, r, tx, http.StatusInternalServerError, fmt.Errorf("error: %w in creating cdn with name: %s", err, cdn.Name), nil)
+ return
+ }
+ usrErr, sysErr, code := api.ParseDBError(err)
+ api.HandleErr(w, r, tx, code, usrErr, sysErr)
+ return
+ }
+ if rows.Next() {
+ if err = rows.Scan(&cdn.ID, &cdn.LastUpdated); err != nil {
+ usrErr, sysErr, code := api.ParseDBError(err)
+ api.HandleErr(w, r, tx, code, usrErr, sysErr)
+ return
+ }
+ }
+
+ alerts := tc.CreateAlerts(tc.SuccessLevel, "cdn was created.")
+ w.Header().Set("Location", fmt.Sprintf("/api/%d.%d/cdns?name=%s", inf.Version.Major, inf.Version.Minor, cdn.Name))
+ api.WriteAlertsObj(w, r, http.StatusCreated, alerts, cdn)
+ return
+}
+
+func Update(w http.ResponseWriter, r *http.Request) {
Review Comment:
V5 Update Function not returning CDN ID like V4.
**V5 Response**
```{
"alerts": [
{
"text": "cdn was updated.",
"level": "success"
}
],
"response": {
"dnssecEnabled": false,
"domainName": "test1new",
"id": 0,
"lastUpdated": "2023-07-31T12:20:17.617043+05:30",
"name": "a-test11",
"ttlOverride": 60
}
}
```
**V4 Response**
```{
"alerts": [
{
"text": "cdn was updated.",
"level": "success"
}
],
"response": {
"dnssecEnabled": false,
"domainName": "test1new",
"id": 1779,
"lastUpdated": "2023-07-31 12:20:41+05",
"name": "a-test111",
"ttlOverride": 60
}
}
```
--
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.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficcontrol] rimashah25 merged pull request #7549: Update CDN v5 endpoints to use RFC3339 timestamps
Posted by "rimashah25 (via GitHub)" <gi...@apache.org>.
rimashah25 merged PR #7549:
URL: https://github.com/apache/trafficcontrol/pull/7549
--
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.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficcontrol] codecov[bot] commented on pull request #7549: Update CDN v5 endpoints to use RFC3339 timestamps
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #7549:
URL: https://github.com/apache/trafficcontrol/pull/7549#issuecomment-1572300245
## [Codecov](https://app.codecov.io/gh/apache/trafficcontrol/pull/7549?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
> Merging [#7549](https://app.codecov.io/gh/apache/trafficcontrol/pull/7549?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (2ffc68f) into [master](https://app.codecov.io/gh/apache/trafficcontrol/commit/ff5a606a9eca2040b09a1fa37f312825296ef5fd?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (ff5a606) will **decrease** coverage by `38.09%`.
> The diff coverage is `52.71%`.
```diff
@@ Coverage Diff @@
## master #7549 +/- ##
=============================================
- Coverage 65.39% 27.30% -38.09%
Complexity 98 98
=============================================
Files 312 665 +353
Lines 12200 70645 +58445
Branches 885 885
=============================================
+ Hits 7978 19291 +11313
- Misses 3874 49872 +45998
- Partials 348 1482 +1134
```
| Flag | Coverage Δ | |
|---|---|---|
| grove_unit | `4.60% <ø> (?)` | |
| t3c_unit | `5.32% <ø> (?)` | |
| traffic_monitor_unit | `21.35% <ø> (?)` | |
| traffic_ops_unit | `23.48% <52.71%> (?)` | |
| traffic_portal_v2 | `74.95% <ø> (ø)` | |
| traffic_stats_unit | `10.14% <ø> (?)` | |
| unit_tests | `23.53% <52.71%> (-51.42%)` | :arrow_down: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Impacted Files](https://app.codecov.io/gh/apache/trafficcontrol/pull/7549?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...raffic\_ops/traffic\_ops\_golang/cdn\_lock/cdn\_lock.go](https://app.codecov.io/gh/apache/trafficcontrol/pull/7549?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dHJhZmZpY19vcHMvdHJhZmZpY19vcHNfZ29sYW5nL2Nkbl9sb2NrL2Nkbl9sb2NrLmdv) | `0.00% <0.00%> (ø)` | |
| [traffic\_ops/v5-client/cdn.go](https://app.codecov.io/gh/apache/trafficcontrol/pull/7549?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dHJhZmZpY19vcHMvdjUtY2xpZW50L2Nkbi5nbw==) | `100.00% <ø> (ø)` | |
| [traffic\_ops/traffic\_ops\_golang/cdn/cdns.go](https://app.codecov.io/gh/apache/trafficcontrol/pull/7549?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dHJhZmZpY19vcHMvdHJhZmZpY19vcHNfZ29sYW5nL2Nkbi9jZG5zLmdv) | `58.46% <51.61%> (ø)` | |
| [traffic\_ops/traffic\_ops\_golang/routing/routes.go](https://app.codecov.io/gh/apache/trafficcontrol/pull/7549?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dHJhZmZpY19vcHMvdHJhZmZpY19vcHNfZ29sYW5nL3JvdXRpbmcvcm91dGVzLmdv) | `95.54% <100.00%> (ø)` | |
... and [351 files with indirect coverage changes](https://app.codecov.io/gh/apache/trafficcontrol/pull/7549/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
--
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.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficcontrol] shamrickus commented on a diff in pull request #7549: Update CDN v5 endpoints to use RFC3339 timestamps
Posted by "shamrickus (via GitHub)" <gi...@apache.org>.
shamrickus commented on code in PR #7549:
URL: https://github.com/apache/trafficcontrol/pull/7549#discussion_r1223339394
##########
docs/source/api/v5/cdns.rst:
##########
@@ -89,15 +89,15 @@ Response Structure
"dnssecEnabled": false,
"domainName": "-",
"id": 1,
- "lastUpdated": "2018-11-14 18:21:06+00",
+ "lastUpdated": "2018-11-14T18:21.516553Z",
Review Comment:
You are right, it is missing the seconds
--
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.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [trafficcontrol] shamrickus commented on a diff in pull request #7549: Update CDN v5 endpoints to use RFC3339 timestamps
Posted by "shamrickus (via GitHub)" <gi...@apache.org>.
shamrickus commented on code in PR #7549:
URL: https://github.com/apache/trafficcontrol/pull/7549#discussion_r1276587912
##########
traffic_ops/traffic_ops_golang/cdn/cdns.go:
##########
@@ -20,71 +20,324 @@
*/
import (
+ "database/sql"
+ "encoding/json"
+ "errors"
"fmt"
"net/http"
"strconv"
"strings"
"time"
+ "github.com/apache/trafficcontrol/lib/go-log"
"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"
+ "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/util/ims"
"github.com/asaskevich/govalidator"
validation "github.com/go-ozzo/ozzo-validation"
)
-// we need a type alias to define functions on
+// TOCDN is the struct needed for the CRUDer
type TOCDN struct {
api.APIInfoImpl `json:"-"`
tc.CDNNullable
}
-func (v *TOCDN) GetLastUpdated() (*time.Time, bool, error) {
- return api.GetLastUpdated(v.APIInfo().Tx, *v.ID, "cdn")
+func Read(w http.ResponseWriter, r *http.Request) {
+ var runSecond bool
+ var maxTime time.Time
+ inf, userErr, sysErr, errCode := api.NewInfo(r, nil, nil)
+ tx := inf.Tx
+ if userErr != nil || sysErr != nil {
+ api.HandleErr(w, r, tx.Tx, errCode, userErr, sysErr)
+ return
+ }
+ defer inf.Close()
+
+ // Query Parameters to Database Query column mappings
+ queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+ "domainName": dbhelpers.WhereColumnInfo{Column: "domain_name"},
+ "dnssecEnabled": dbhelpers.WhereColumnInfo{Column: "dnssec_enabled"},
+ "id": dbhelpers.WhereColumnInfo{Column: "id", Checker: api.IsInt},
+ "name": dbhelpers.WhereColumnInfo{Column: "name"},
+ "ttlOverride": dbhelpers.WhereColumnInfo{Column: "ttl_override", Checker: api.IsInt},
+ }
+
+ if _, ok := inf.Params["orderby"]; !ok {
+ inf.Params["orderby"] = "name"
+ }
+ where, orderBy, pagination, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+ if len(errs) > 0 {
+ api.HandleErr(w, r, tx.Tx, http.StatusBadRequest, util.JoinErrs(errs), nil)
+ return
+ }
+
+ if inf.Config.UseIMS {
+ runSecond, maxTime = ims.TryIfModifiedSinceQuery(tx, r.Header, queryValues, SelectMaxLastUpdatedQuery(where))
+ if !runSecond {
+ log.Debugln("IMS HIT")
+ api.AddLastModifiedHdr(w, maxTime)
+ w.WriteHeader(http.StatusNotModified)
+ return
+ }
+ log.Debugln("IMS MISS")
+ } else {
+ log.Debugln("Non IMS request")
+ }
+
+ query := selectQuery(inf.Version) + where + orderBy + pagination
+ rows, err := tx.NamedQuery(query, queryValues)
Review Comment:
Pretty sure this is properly handled, if not then this is a problem with most of our endpoints.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org