|
@@ -72,15 +72,19 @@ type endpointAuthorizer struct {
|
|
|
}
|
|
|
|
|
|
func (ea *endpointAuthorizer) ModifyRequest(req *http.Request) error {
|
|
|
- v2Root := strings.Index(req.URL.Path, "/v2/")
|
|
|
- if v2Root == -1 {
|
|
|
+ pingPath := req.URL.Path
|
|
|
+ if v2Root := strings.Index(req.URL.Path, "/v2/"); v2Root != -1 {
|
|
|
+ pingPath = pingPath[:v2Root+4]
|
|
|
+ } else if v1Root := strings.Index(req.URL.Path, "/v1/"); v1Root != -1 {
|
|
|
+ pingPath = pingPath[:v1Root] + "/v2/"
|
|
|
+ } else {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
ping := url.URL{
|
|
|
Host: req.URL.Host,
|
|
|
Scheme: req.URL.Scheme,
|
|
|
- Path: req.URL.Path[:v2Root+4],
|
|
|
+ Path: pingPath,
|
|
|
}
|
|
|
|
|
|
challenges, err := ea.challenges.GetChallenges(ping)
|
|
@@ -151,6 +155,19 @@ func (rs RepositoryScope) String() string {
|
|
|
return fmt.Sprintf("repository:%s:%s", rs.Repository, strings.Join(rs.Actions, ","))
|
|
|
}
|
|
|
|
|
|
+// RegistryScope represents a token scope for access
|
|
|
+// to resources in the registry.
|
|
|
+type RegistryScope struct {
|
|
|
+ Name string
|
|
|
+ Actions []string
|
|
|
+}
|
|
|
+
|
|
|
+// String returns the string representation of the user
|
|
|
+// using the scope grammar
|
|
|
+func (rs RegistryScope) String() string {
|
|
|
+ return fmt.Sprintf("registry:%s:%s", rs.Name, strings.Join(rs.Actions, ","))
|
|
|
+}
|
|
|
+
|
|
|
// TokenHandlerOptions is used to configure a new token handler
|
|
|
type TokenHandlerOptions struct {
|
|
|
Transport http.RoundTripper
|