mirror of https://github.com/docker/docs.git
fix up style according to comments
Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
This commit is contained in:
parent
0014348991
commit
385bd5aa11
|
@ -115,12 +115,10 @@ func ValidRole(name string) bool {
|
||||||
|
|
||||||
// IsDelegation checks if the role is a delegation or a root role
|
// IsDelegation checks if the role is a delegation or a root role
|
||||||
func IsDelegation(role string) bool {
|
func IsDelegation(role string) bool {
|
||||||
targetsBase := fmt.Sprintf("%s/", ValidRoles[CanonicalTargetsRole])
|
targetsBase := ValidRoles[CanonicalTargetsRole] + "/"
|
||||||
|
|
||||||
whitelistedChars, err := regexp.MatchString("^[-a-z0-9_/]+$", role)
|
delegationRegexp := regexp.MustCompile("^[-a-z0-9_/]+$")
|
||||||
if err != nil {
|
whitelistedChars := delegationRegexp.MatchString(role)
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Limit size of full role string to 255 chars for db column size limit
|
// Limit size of full role string to 255 chars for db column size limit
|
||||||
correctLength := len(role) < 256
|
correctLength := len(role) < 256
|
||||||
|
@ -274,7 +272,9 @@ func mergeStrSlices(orig, new []string) []string {
|
||||||
}
|
}
|
||||||
for _, e := range new {
|
for _, e := range new {
|
||||||
if !have[e] {
|
if !have[e] {
|
||||||
orig = append(orig, e)
|
origCopy := make([]string, len(orig))
|
||||||
|
copy(origCopy, orig)
|
||||||
|
orig = append(origCopy, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return orig
|
return orig
|
||||||
|
|
|
@ -33,7 +33,7 @@ type ErrServerUnavailable struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (err ErrServerUnavailable) Error() string {
|
func (err ErrServerUnavailable) Error() string {
|
||||||
return fmt.Sprintf("Unable to reach trust server at this time: %d.", err.code)
|
return fmt.Sprintf("unable to reach trust server at this time: %d.", err.code)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrMaliciousServer indicates the server returned a response that is highly suspected
|
// ErrMaliciousServer indicates the server returned a response that is highly suspected
|
||||||
|
@ -42,7 +42,7 @@ func (err ErrServerUnavailable) Error() string {
|
||||||
type ErrMaliciousServer struct{}
|
type ErrMaliciousServer struct{}
|
||||||
|
|
||||||
func (err ErrMaliciousServer) Error() string {
|
func (err ErrMaliciousServer) Error() string {
|
||||||
return "Trust server returned a bad response."
|
return "trust server returned a bad response."
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrInvalidOperation indicates that the server returned a 400 response and
|
// ErrInvalidOperation indicates that the server returned a 400 response and
|
||||||
|
@ -53,9 +53,9 @@ type ErrInvalidOperation struct {
|
||||||
|
|
||||||
func (err ErrInvalidOperation) Error() string {
|
func (err ErrInvalidOperation) Error() string {
|
||||||
if err.msg != "" {
|
if err.msg != "" {
|
||||||
return fmt.Sprintf("Trust server rejected operation: %s", err.msg)
|
return fmt.Sprintf("trust server rejected operation: %s", err.msg)
|
||||||
}
|
}
|
||||||
return "Trust server rejected operation."
|
return "trust server rejected operation."
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTTPStore manages pulling and pushing metadata from and to a remote
|
// HTTPStore manages pulling and pushing metadata from and to a remote
|
||||||
|
|
|
@ -352,7 +352,7 @@ func (tr *Repo) InitRoot(consistent bool) error {
|
||||||
// InitTargets initializes an empty targets, and returns the new empty target
|
// InitTargets initializes an empty targets, and returns the new empty target
|
||||||
func (tr *Repo) InitTargets(role string) (*data.SignedTargets, error) {
|
func (tr *Repo) InitTargets(role string) (*data.SignedTargets, error) {
|
||||||
r := data.Role{Name: role}
|
r := data.Role{Name: role}
|
||||||
if !r.IsDelegation() && !(data.CanonicalRole(role) == data.CanonicalTargetsRole) {
|
if !r.IsDelegation() && data.CanonicalRole(role) != data.CanonicalTargetsRole {
|
||||||
return nil, data.ErrInvalidRole{
|
return nil, data.ErrInvalidRole{
|
||||||
Role: role,
|
Role: role,
|
||||||
Reason: fmt.Sprintf("role is not a valid targets role name: %s", role),
|
Reason: fmt.Sprintf("role is not a valid targets role name: %s", role),
|
||||||
|
|
|
@ -93,7 +93,7 @@ func (s *SerializableError) UnmarshalJSON(text []byte) (err error) {
|
||||||
err = json.Unmarshal(text, &e)
|
err = json.Unmarshal(text, &e)
|
||||||
theError = e.Error
|
theError = e.Error
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("do not know how to unmarshall %s", x.Name)
|
err = fmt.Errorf("do not know how to unmarshal %s", x.Name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue