66 "net/http"
77 "time"
88
9+ "github.com/docker/cli/cli/trust"
910 "github.com/docker/distribution/reference"
1011 "github.com/docker/distribution/registry/client/auth"
1112 "github.com/docker/distribution/registry/client/transport"
@@ -17,6 +18,7 @@ import (
1718type repositoryEndpoint struct {
1819 info * registry.RepositoryInfo
1920 endpoint registry.APIEndpoint
21+ actions []string
2022}
2123
2224// Name returns the repository name
@@ -74,7 +76,7 @@ func getDefaultEndpointFromRepoInfo(repoInfo *registry.RepositoryInfo) (registry
7476}
7577
7678// getHTTPTransport builds a transport for use in communicating with a registry
77- func getHTTPTransport (authConfig registrytypes.AuthConfig , endpoint registry.APIEndpoint , repoName string , userAgent string ) (http.RoundTripper , error ) {
79+ func getHTTPTransport (authConfig registrytypes.AuthConfig , endpoint registry.APIEndpoint , repoName , userAgent string , actions [] string ) (http.RoundTripper , error ) {
7880 // get the http transport, this will be used in a client to upload manifest
7981 base := & http.Transport {
8082 Proxy : http .ProxyFromEnvironment ,
@@ -98,8 +100,11 @@ func getHTTPTransport(authConfig registrytypes.AuthConfig, endpoint registry.API
98100 passThruTokenHandler := & existingTokenHandler {token : authConfig .RegistryToken }
99101 modifiers = append (modifiers , auth .NewAuthorizer (challengeManager , passThruTokenHandler ))
100102 } else {
103+ if len (actions ) == 0 {
104+ actions = trust .ActionsPullOnly
105+ }
101106 creds := registry .NewStaticCredentialStore (& authConfig )
102- tokenHandler := auth .NewTokenHandler (authTransport , creds , repoName , "push" , "pull" )
107+ tokenHandler := auth .NewTokenHandler (authTransport , creds , repoName , actions ... )
103108 basicHandler := auth .NewBasicHandler (creds )
104109 modifiers = append (modifiers , auth .NewAuthorizer (challengeManager , tokenHandler , basicHandler ))
105110 }
0 commit comments