You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by "rimashah25 (via GitHub)" <gi...@apache.org> on 2023/06/07 04:52:20 UTC

[GitHub] [trafficcontrol] rimashah25 opened a new pull request, #7561: Fixed ASN(APIv5) REST calls to respond with RFC3339 timestamp

rimashah25 opened a new pull request, #7561:
URL: https://github.com/apache/trafficcontrol/pull/7561

   <!--
   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.
   -->
   
   
   <!-- **^ 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 Control Cache Config (`t3c`, formerly ORT)
   - Traffic Control Health Client (tc-health-client)
   - Traffic Control Client <!-- Please specify which (Python, Go, or Java) -->
   - Traffic Monitor
   - Traffic Ops
   - Traffic Portal
   - Traffic Router
   - Traffic Stats
   - Grove
   - CDN in a Box
   - Automation <!-- Please specify which (GitHub Actions, Docker images, Ansible Roles, etc.) -->
   - unknown
   
   ## What is the best way to verify this PR?
   <!-- 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. -->
   
   
   ## If this is a bugfix, which Traffic Control versions contained the bug?
   <!-- 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. -->
   - [x] 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] srijeet0406 merged pull request #7561: Fixed ASN(APIv5) REST calls to respond with RFC3339 timestamp

Posted by "srijeet0406 (via GitHub)" <gi...@apache.org>.
srijeet0406 merged PR #7561:
URL: https://github.com/apache/trafficcontrol/pull/7561


-- 
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 #7561: Fixed ASN(APIv5) REST calls to respond with RFC3339 timestamp

Posted by "rimashah25 (via GitHub)" <gi...@apache.org>.
rimashah25 commented on code in PR #7561:
URL: https://github.com/apache/trafficcontrol/pull/7561#discussion_r1237151106


##########
traffic_ops/traffic_ops_golang/asn/asns.go:
##########
@@ -204,3 +209,229 @@ RETURNING
 func deleteQuery() string {
 	return `DELETE FROM asn WHERE id=:id`
 }
+
+// Read gets list of ASNs for APIv5
+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{
+		"asn": {Column: "a.asn", Checker: api.IsInt},
+		"id":  {Column: "a.id", Checker: api.IsInt},
+	}
+	if _, ok := inf.Params["orderby"]; !ok {
+		inf.Params["orderby"] = "asn"
+	}
+	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() + where + orderBy + pagination
+	rows, err := tx.NamedQuery(query, queryValues)
+	if err != nil {
+		api.HandleErr(w, r, tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("asn read: error getting asn(s): %w", err))
+	}
+	defer log.Close(rows, "unable to close DB connection")
+
+	asn := tc.ASNV5{}
+	asnList := []tc.ASNV5{}

Review Comment:
   not necessary. There are two ways to initiate and define a variable.



-- 
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 #7561: Fixed ASN(APIv5) REST calls to respond with RFC3339 timestamp

Posted by "rimashah25 (via GitHub)" <gi...@apache.org>.
rimashah25 commented on code in PR #7561:
URL: https://github.com/apache/trafficcontrol/pull/7561#discussion_r1240358898


##########
lib/go-tc/asns.go:
##########
@@ -38,6 +40,25 @@ type ASNResponse struct {
 	Alerts
 }
 
+// ASNsResponseV5 is a list of ASNs (Autonomous System Numbers) as a response.
+// swagger:response ASNsResponse
+// in: body
+type ASNsResponseV5 struct {

Review Comment:
   I can answer my own questions: we are future preparing ourselves.



-- 
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 #7561: Fixed ASN(APIv5) REST calls to respond with RFC3339 timestamp

Posted by "rimashah25 (via GitHub)" <gi...@apache.org>.
rimashah25 commented on code in PR #7561:
URL: https://github.com/apache/trafficcontrol/pull/7561#discussion_r1237151637


##########
traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go:
##########
@@ -2202,3 +2202,18 @@ func ServiceCategoryExists(tx *sql.Tx, name string) (bool, error) {
 	}
 	return true, nil
 }
+
+// GetASNInfo confirms whether the asn exists, and an error (if one occurs).
+func GetASNInfo(tx *sql.Tx, id string) (bool, error) {

Review Comment:
   Agreed.



-- 
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 #7561: Fixed ASN(APIv5) REST calls to respond with RFC3339 timestamp

Posted by "rimashah25 (via GitHub)" <gi...@apache.org>.
rimashah25 commented on code in PR #7561:
URL: https://github.com/apache/trafficcontrol/pull/7561#discussion_r1240274621


##########
lib/go-tc/asns.go:
##########
@@ -38,6 +40,25 @@ type ASNResponse struct {
 	Alerts
 }
 
+// ASNsResponseV5 is a list of ASNs (Autonomous System Numbers) as a response.
+// swagger:response ASNsResponse
+// in: body
+type ASNsResponseV5 struct {

Review Comment:
   > convention across all others structs
   
   What convention? I see both ways this is being done, one, that you mentioned above, two what I have. So, the question is, which one is better?



-- 
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 #7561: Fixed ASN(APIv5) REST calls to respond with RFC3339 timestamp

Posted by "rimashah25 (via GitHub)" <gi...@apache.org>.
rimashah25 commented on code in PR #7561:
URL: https://github.com/apache/trafficcontrol/pull/7561#discussion_r1240274621


##########
lib/go-tc/asns.go:
##########
@@ -38,6 +40,25 @@ type ASNResponse struct {
 	Alerts
 }
 
+// ASNsResponseV5 is a list of ASNs (Autonomous System Numbers) as a response.
+// swagger:response ASNsResponse
+// in: body
+type ASNsResponseV5 struct {

Review Comment:
   > convention across all others structs
   
   What convention? And the only time I see V40, V41, is when a minor version changes.
   So the question is, why for an unreleased version do I need V50?



-- 
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 #7561: Fixed ASN(APIv5) REST calls to respond with RFC3339 timestamp

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #7561:
URL: https://github.com/apache/trafficcontrol/pull/7561#issuecomment-1591825538

   ## [Codecov](https://app.codecov.io/gh/apache/trafficcontrol/pull/7561?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > Merging [#7561](https://app.codecov.io/gh/apache/trafficcontrol/pull/7561?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (735d9a4) into [master](https://app.codecov.io/gh/apache/trafficcontrol/commit/927fe2878b5188222b5a14f99017a162ea2e1358?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (927fe28) will **increase** coverage by `2.88%`.
   > The diff coverage is `2.89%`.
   
   ```diff
   @@             Coverage Diff              @@
   ##             master    #7561      +/-   ##
   ============================================
   + Coverage     25.56%   28.44%   +2.88%     
     Complexity       98       98              
   ============================================
     Files           574      680     +106     
     Lines         74260    79195    +4935     
     Branches         90      885     +795     
   ============================================
   + Hits          18982    22528    +3546     
   - Misses        53384    54716    +1332     
   - Partials       1894     1951      +57     
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | golib_unit | `48.58% <ø> (ø)` | |
   | grove_unit | `4.60% <ø> (ø)` | |
   | t3c_unit | `5.31% <ø> (ø)` | |
   | traffic_monitor_unit | `21.35% <ø> (ø)` | |
   | traffic_ops_unit | `23.18% <2.89%> (-0.13%)` | :arrow_down: |
   | traffic_portal_v2 | `74.93% <ø> (?)` | |
   | traffic_stats_unit | `10.14% <ø> (ø)` | |
   | unit_tests | `27.41% <2.89%> (+3.06%)` | :arrow_up: |
   
   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/7561?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [traffic\_ops/traffic\_ops\_golang/asn/asns.go](https://app.codecov.io/gh/apache/trafficcontrol/pull/7561?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dHJhZmZpY19vcHMvdHJhZmZpY19vcHNfZ29sYW5nL2Fzbi9hc25zLmdv) | `14.60% <0.00%> (-21.91%)` | :arrow_down: |
   | [...fic\_ops/traffic\_ops\_golang/dbhelpers/db\_helpers.go](https://app.codecov.io/gh/apache/trafficcontrol/pull/7561?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dHJhZmZpY19vcHMvdHJhZmZpY19vcHNfZ29sYW5nL2RiaGVscGVycy9kYl9oZWxwZXJzLmdv) | `20.58% <0.00%> (-0.16%)` | :arrow_down: |
   | [traffic\_ops/v5-client/asn.go](https://app.codecov.io/gh/apache/trafficcontrol/pull/7561?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dHJhZmZpY19vcHMvdjUtY2xpZW50L2Fzbi5nbw==) | `100.00% <ø> (ø)` | |
   | [traffic\_ops/traffic\_ops\_golang/routing/routes.go](https://app.codecov.io/gh/apache/trafficcontrol/pull/7561?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dHJhZmZpY19vcHMvdHJhZmZpY19vcHNfZ29sYW5nL3JvdXRpbmcvcm91dGVzLmdv) | `95.53% <100.00%> (-0.01%)` | :arrow_down: |
   
   ... and [106 files with indirect coverage changes](https://app.codecov.io/gh/apache/trafficcontrol/pull/7561/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] rimashah25 commented on a diff in pull request #7561: Fixed ASN(APIv5) REST calls to respond with RFC3339 timestamp

Posted by "rimashah25 (via GitHub)" <gi...@apache.org>.
rimashah25 commented on code in PR #7561:
URL: https://github.com/apache/trafficcontrol/pull/7561#discussion_r1237151106


##########
traffic_ops/traffic_ops_golang/asn/asns.go:
##########
@@ -204,3 +209,229 @@ RETURNING
 func deleteQuery() string {
 	return `DELETE FROM asn WHERE id=:id`
 }
+
+// Read gets list of ASNs for APIv5
+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{
+		"asn": {Column: "a.asn", Checker: api.IsInt},
+		"id":  {Column: "a.id", Checker: api.IsInt},
+	}
+	if _, ok := inf.Params["orderby"]; !ok {
+		inf.Params["orderby"] = "asn"
+	}
+	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() + where + orderBy + pagination
+	rows, err := tx.NamedQuery(query, queryValues)
+	if err != nil {
+		api.HandleErr(w, r, tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("asn read: error getting asn(s): %w", err))
+	}
+	defer log.Close(rows, "unable to close DB connection")
+
+	asn := tc.ASNV5{}
+	asnList := []tc.ASNV5{}

Review Comment:
   not necessary. There are two way to initiate and define a variable.



-- 
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 #7561: Fixed ASN(APIv5) REST calls to respond with RFC3339 timestamp

Posted by "github-code-scanning[bot] (via GitHub)" <gi...@apache.org>.
github-code-scanning[bot] commented on code in PR #7561:
URL: https://github.com/apache/trafficcontrol/pull/7561#discussion_r1230048316


##########
traffic_ops/traffic_ops_golang/asn/asns.go:
##########
@@ -204,3 +209,229 @@
 func deleteQuery() string {
 	return `DELETE FROM asn WHERE id=:id`
 }
+
+// Read gets list of ASNs for APIv5
+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{
+		"asn": {Column: "a.asn", Checker: api.IsInt},
+		"id":  {Column: "a.id", Checker: api.IsInt},
+	}
+	if _, ok := inf.Params["orderby"]; !ok {
+		inf.Params["orderby"] = "asn"
+	}
+	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() + 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/279)



-- 
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 #7561: Fixed ASN(APIv5) REST calls to respond with RFC3339 timestamp

Posted by "jagan-parthiban (via GitHub)" <gi...@apache.org>.
jagan-parthiban commented on code in PR #7561:
URL: https://github.com/apache/trafficcontrol/pull/7561#discussion_r1237037418


##########
lib/go-tc/asns.go:
##########
@@ -99,3 +120,29 @@ type ASNNullable struct {
 type ASNsV11 struct {
 	ASNs []interface{} `json:"asns"`
 }
+
+// ASNsV5 is used for RFC3339 format timestamp
+type ASNV5 struct {

Review Comment:
   Same as Above
   
   type ASNV5 = ASNV50



##########
lib/go-tc/asns.go:
##########
@@ -38,6 +40,25 @@ type ASNResponse struct {
 	Alerts
 }
 
+// ASNsResponseV5 is a list of ASNs (Autonomous System Numbers) as a response.
+// swagger:response ASNsResponse
+// in: body
+type ASNsResponseV5 struct {

Review Comment:
   As per convention across all others structs, we have a specific version that does not changes, and then an alias for the most recent version. 
   
   So in this case, we'd want to have a ASNsResponseV50 that looks like what you have here, and then a type named ASNsResponseV5 that is just an alias of that like
   
   type ASNsResponseV5 = ASNsResponseV50



##########
lib/go-tc/asns.go:
##########
@@ -38,6 +40,25 @@ type ASNResponse struct {
 	Alerts
 }
 
+// ASNsResponseV5 is a list of ASNs (Autonomous System Numbers) as a response.
+// swagger:response ASNsResponse
+// in: body
+type ASNsResponseV5 struct {
+	// in: body
+	Response []ASNV5 `json:"response"`
+	Alerts
+}
+
+// ASNResponseV5 is a single ASN response for Update and Create to depict what
+// changed.
+// swagger:response ASNResponse
+// in: body
+type ASNResponseV5 struct {

Review Comment:
   Same as Above
   
   type ASNResponseV5 = ASNResponseV50



##########
traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go:
##########
@@ -2202,3 +2202,18 @@ func ServiceCategoryExists(tx *sql.Tx, name string) (bool, error) {
 	}
 	return true, nil
 }
+
+// GetASNInfo confirms whether the asn exists, and an error (if one occurs).
+func GetASNInfo(tx *sql.Tx, id string) (bool, error) {

Review Comment:
   As this function does not get the ASNInfo and it only confirms the existence of the ASN, should we rename the funcion to something like `ASNExists`



##########
traffic_ops/traffic_ops_golang/asn/asns.go:
##########
@@ -204,3 +209,229 @@ RETURNING
 func deleteQuery() string {
 	return `DELETE FROM asn WHERE id=:id`
 }
+
+// Read gets list of ASNs for APIv5
+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{
+		"asn": {Column: "a.asn", Checker: api.IsInt},
+		"id":  {Column: "a.id", Checker: api.IsInt},
+	}
+	if _, ok := inf.Params["orderby"]; !ok {
+		inf.Params["orderby"] = "asn"
+	}
+	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() + where + orderBy + pagination
+	rows, err := tx.NamedQuery(query, queryValues)
+	if err != nil {
+		api.HandleErr(w, r, tx.Tx, http.StatusInternalServerError, nil, fmt.Errorf("asn read: error getting asn(s): %w", err))
+	}
+	defer log.Close(rows, "unable to close DB connection")
+
+	asn := tc.ASNV5{}
+	asnList := []tc.ASNV5{}

Review Comment:
   Should we change  the empty slice declaration Semantics to `var asnList []tc.ASNV5`



##########
lib/go-tc/asns.go:
##########
@@ -1,5 +1,7 @@
 package tc
 
+import "time"

Review Comment:
   For Uniformity across all files, Import statement can be below the Licence text.



-- 
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