func (s *dockerImageSource) getOneSignature(ctx context.Context, url *url.URL) (signature []byte, missing bool, err error) {
	switch url.Scheme {
	case "file":
		logrus.Debugf("Reading %s", url.Path)
		sig, err := ioutil.ReadFile(url.Path)
		if err != nil {
			if os.IsNotExist(err) {
				return nil, true, nil
			}
			return nil, false, err
		}
		return sig, false, nil

	case "http", "https":
		logrus.Debugf("GET %s", url)
		req, err := http.NewRequest("GET", url.String(), nil)
		if err != nil {
			return nil, false, err
		}
		req = req.WithContext(ctx)
		res, err := s.c.doHTTP(req)
		if err != nil {
			return nil, false, err
		}
		defer res.Body.Close()
		if res.StatusCode == http.StatusNotFound {
			return nil, true, nil
		} else if res.StatusCode != http.StatusOK {
			return nil, false, errors.Errorf("Error reading signature from %s: status %d (%s)", url.String(), res.StatusCode, http.StatusText(res.StatusCode))
		}
		sig, err := ioutil.ReadAll(res.Body)
		if err != nil {
			return nil, false, err
		}
		return sig, false, nil

	default:
		return nil, false, errors.Errorf("Unsupported scheme when reading signature from %s", url.String())
	}
}
func (s *dockerImageSource) getOneSignature(ctx context.Context, url *url.URL) (signature []byte, missing bool, err error) {
	switch url.Scheme {
	case "file":
		logrus.Debugf("Reading %s", url.Path)
		sig, err := ioutil.ReadFile(url.Path)
		if err != nil {
			if os.IsNotExist(err) {
				return nil, true, nil
			}
			return nil, false, err
		}
		return sig, false, nil

	case "http", "https":
		logrus.Debugf("GET %s", url)
		req, err := http.NewRequest("GET", url.String(), nil)
		if err != nil {
			return nil, false, err
		}
		req = req.WithContext(ctx)
		res, err := s.c.doHTTP(req)
		if err != nil {
			return nil, false, err
		}
		defer res.Body.Close()
		if res.StatusCode == http.StatusNotFound {
			return nil, true, nil
		} else if res.StatusCode != http.StatusOK {
			return nil, false, errors.Errorf("Error reading signature from %s: status %d (%s)", url.String(), res.StatusCode, http.StatusText(res.StatusCode))
		}
		sig, err := ioutil.ReadAll(res.Body)
		if err != nil {
			return nil, false, err
		}
		return sig, false, nil

	default:
		return nil, false, errors.Errorf("Unsupported scheme when reading signature from %s", url.String())
	}
}
func ( s * dockerImageSource ) getOneSignature ( ctx context . Context , url * url . URL ) ( signature [ ] byte , missing bool , err error ) { switch url . Scheme { case " " : logrus . Debugf ( " " , url . Path ) sig , err := ioutil . ReadFile ( url . Path ) if err != nil { if os . IsNotExist ( err ) { return nil , true , nil } return nil , false , err } return sig , false , nil case " " , " " : logrus . Debugf ( " " , url ) req , err := http . NewRequest ( " " , url . String ( ) , nil ) if err != nil { return nil , false , err } req = req . WithContext ( ctx ) res , err := s . c . doHTTP ( req ) if err != nil { return nil , false , err } defer res . Body . Close ( ) if res . StatusCode == http . StatusNotFound { return nil , true , nil } else if res . StatusCode != http . StatusOK { return nil , false , errors . Errorf ( " " , url . String ( ) , res . StatusCode , http . StatusText ( res . StatusCode ) ) } sig , err := ioutil . ReadAll ( res . Body ) if err != nil { return nil , false , err } return sig , false , nil default : return nil , false , errors . Errorf ( " " , url . String ( ) ) } }
// getOneSignature downloads one signature from url.
// If it successfully determines that the signature does not exist, returns with missing set to true and error set to nil.
// NOTE: Keep this in sync with docs/signature-protocols.md!
getOneSignature downloads one signature from url . If it successfully determines that the signature does not exist returns with missing set to true and error set to nil . NOTE : Keep this in sync with docs / signature - protocols . md!