You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by oc...@apache.org on 2020/04/07 19:40:00 UTC

[trafficcontrol] branch master updated: fixed internal server error for dns challenge records (#4580)

This is an automated email from the ASF dual-hosted git repository.

ocket8888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new d24fedb  fixed internal server error for dns challenge records (#4580)
d24fedb is described below

commit d24fedb668f126323ba98e32d175490a67461bf9
Author: mattjackson220 <33...@users.noreply.github.com>
AuthorDate: Tue Apr 7 13:39:52 2020 -0600

    fixed internal server error for dns challenge records (#4580)
    
    Co-authored-by: mjacks258 <ma...@comcast.com>
---
 .../deliveryservice/letsencrypt_dns_challenge.go   | 27 +++++++++++-----------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/traffic_ops/traffic_ops_golang/deliveryservice/letsencrypt_dns_challenge.go b/traffic_ops/traffic_ops_golang/deliveryservice/letsencrypt_dns_challenge.go
index 4cc9c6f..4de104a 100644
--- a/traffic_ops/traffic_ops_golang/deliveryservice/letsencrypt_dns_challenge.go
+++ b/traffic_ops/traffic_ops_golang/deliveryservice/letsencrypt_dns_challenge.go
@@ -20,13 +20,14 @@ package deliveryservice
  */
 
 import (
-	"database/sql"
 	"errors"
 	"net/http"
 
 	"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/jmoiron/sqlx"
 )
 
 type DnsRecord struct {
@@ -44,20 +45,18 @@ func GetDnsChallengeRecords(w http.ResponseWriter, r *http.Request) {
 
 	getQuery := `SELECT fqdn, record FROM dnschallenges`
 
-	if inf.Params["fqdn"] != "" {
-		queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
-			"fqdn": dbhelpers.WhereColumnInfo{"fqdn", nil},
-		}
+	queryParamsToQueryCols := map[string]dbhelpers.WhereColumnInfo{
+		"fqdn": dbhelpers.WhereColumnInfo{"fqdn", nil},
+	}
 
-		where, _, _, _, errs := dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
-		if len(errs) > 0 {
-			api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, util.JoinErrs(errs))
-			return
-		}
-		getQuery += where
+	where, _, _, queryValues, errs := dbhelpers.BuildWhereAndOrderByAndPagination(inf.Params, queryParamsToQueryCols)
+	if len(errs) > 0 {
+		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, util.JoinErrs(errs))
+		return
 	}
+	getQuery += where
 
-	dnsRecord, err := getDnsRecords(inf.Tx.Tx, getQuery)
+	dnsRecord, err := getDnsRecords(inf.Tx, getQuery, queryValues)
 	if err != nil {
 		api.HandleErr(w, r, inf.Tx.Tx, http.StatusInternalServerError, nil, errors.New("checking dns records: "+err.Error()))
 		return
@@ -65,9 +64,9 @@ func GetDnsChallengeRecords(w http.ResponseWriter, r *http.Request) {
 	api.WriteResp(w, r, dnsRecord)
 }
 
-func getDnsRecords(tx *sql.Tx, getQuery string) ([]DnsRecord, error) {
+func getDnsRecords(tx *sqlx.Tx, getQuery string, queryValues map[string]interface{}) ([]DnsRecord, error) {
 	records := []DnsRecord{}
-	rows, err := tx.Query(getQuery)
+	rows, err := tx.NamedQuery(getQuery, queryValues)
 	if err != nil {
 		return nil, errors.New("getting dns challenge records: " + err.Error())
 	}