Skip to content

Commit

Permalink
Fixes apache#7704
Browse files Browse the repository at this point in the history
  • Loading branch information
jagan-parthiban committed Aug 8, 2023
1 parent da7bd38 commit 16722cd
Show file tree
Hide file tree
Showing 4 changed files with 432 additions and 4 deletions.
46 changes: 46 additions & 0 deletions lib/go-tc/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"fmt"
"strconv"
"strings"
"time"

"github.com/apache/trafficcontrol/lib/go-util"

Expand Down Expand Up @@ -69,6 +70,51 @@ type ParameterNullable struct {
Value *string `json:"value" db:"value"`
}

// ParametersResponseV5 is an alias for the latest minor version for the major version 5.
type ParametersResponseV5 = ParametersResponseV50

// ParametersResponseV50 is the type of the response from Traffic Ops to GET
// requests made to the /parameters and /profiles/name/{{Name}}/parameters
// endpoints of its API.
type ParametersResponseV50 struct {
Response []Parameter `json:"response"`
Alerts
}

// ParameterV5 is an alias for the latest minor version for the major version 5.
type ParameterV5 = ParameterV50

// A ParameterV50 defines some configuration setting (which is usually but
// definitely not always a line in a configuration file) used by some Profile
// or Cache Group.
type ParameterV50 struct {
ConfigFile string `json:"configFile" db:"config_file"`
ID int `json:"id" db:"id"`
LastUpdated time.Time `json:"lastUpdated" db:"last_updated"`
Name string `json:"name" db:"name"`
Profiles json.RawMessage `json:"profiles" db:"profiles"`
Secure bool `json:"secure" db:"secure"`
Value string `json:"value" db:"value"`
}

// ParameterNullableV5 is an alias for the latest minor version for the major version 5.
type ParameterNullableV5 = ParameterNullableV50

// ParameterNullableV50 is exactly like Parameter except that its properties are
// reference values, so they can be nil.
type ParameterNullableV50 struct {
//
// NOTE: the db: struct tags are used for testing to map to their equivalent database column (if there is one)
//
ConfigFile *string `json:"configFile" db:"config_file"`
ID *int `json:"id" db:"id"`
LastUpdated *time.Time `json:"lastUpdated" db:"last_updated"`
Name *string `json:"name" db:"name"`
Profiles json.RawMessage `json:"profiles" db:"profiles"`
Secure *bool `json:"secure" db:"secure"`
Value *string `json:"value" db:"value"`
}

// ProfileParameterByName is a structure that's used to represent a Parameter
// in a context where they are associated with some Profile specified by a
// client of the Traffic Ops API by its Name.
Expand Down
15 changes: 15 additions & 0 deletions traffic_ops/traffic_ops_golang/dbhelpers/db_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,21 @@ func PhysLocationExists(tx *sql.Tx, id string) (bool, error) {
return true, nil
}

// ParameterExists confirms whether the Parameter exists, and an error (if one occurs).
func ParameterExists(tx *sql.Tx, id string) (bool, error) {
var count int
if err := tx.QueryRow("SELECT count(name) FROM parameter WHERE id=$1", id).Scan(&count); err != nil {
return false, fmt.Errorf("error getting Parameter info: %w", err)
}
if count == 0 {
return false, nil
}
if count != 1 {
return false, fmt.Errorf("getting Parameter info - expected row count: 1, actual: %d", count)
}
return true, nil
}

// GetCoordinateID obtains coordinateID, and an error (if one occurs)
func GetCoordinateID(tx *sql.Tx, id int) (*int, error) {
q := `SELECT coordinate FROM cachegroup WHERE id = $1`
Expand Down
Loading

0 comments on commit 16722cd

Please sign in to comment.