github.com/google/osv-scalibr@v0.4.1/veles/secrets/gitbasicauth/codecatalyst/validator.go (about) 1 // Copyright 2025 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package codecatalyst 16 17 import ( 18 "fmt" 19 "net/http" 20 "net/url" 21 "strings" 22 23 "github.com/google/osv-scalibr/veles/secrets/common/simplevalidate" 24 "github.com/google/osv-scalibr/veles/secrets/gitbasicauth" 25 ) 26 27 // NewValidator creates a new Validator that validates CodeCatalyst credentials 28 func NewValidator() *simplevalidate.Validator[Credentials] { 29 return &simplevalidate.Validator[Credentials]{ 30 EndpointFunc: func(c Credentials) (string, error) { 31 u, err := url.Parse(c.FullURL) 32 if err != nil { 33 return "", fmt.Errorf("error parsing URL: %w", err) 34 } 35 36 // redundant host validation kept intentionally as a security measure in case any regression 37 // is introduced in the detector. 38 if !strings.HasSuffix(u.Host, ".codecatalyst.aws") { 39 return "", fmt.Errorf("not a valid AWS CodeCatalyst host %q", u.Host) 40 } 41 return gitbasicauth.Info(u).String(), nil 42 }, 43 HTTPMethod: http.MethodGet, 44 ValidResponseCodes: []int{http.StatusOK}, 45 InvalidResponseCodes: []int{http.StatusBadRequest}, 46 } 47 }