fix(volumes): enable volume browsing (#4233)

* fix(docker): browse an agent volume

* refactor(volumes): get resource id from endpoint
pull/4250/head
Chaim Lev-Ari 4 years ago committed by GitHub
parent f8be9bb57a
commit 9fd38a0543
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -156,8 +156,14 @@ func (transport *Transport) proxyAgentRequest(r *http.Request) (*http.Response,
return transport.administratorOperation(r)
}
agentTargetHeader := r.Header.Get(portainer.PortainerAgentTargetHeader)
resourceID, err := transport.getVolumeResourceID(agentTargetHeader, volumeIDParameter[0])
if err != nil {
return nil, err
}
// volume browser request
return transport.restrictedResourceOperation(r, volumeIDParameter[0], portainer.VolumeResourceControl, true)
return transport.restrictedResourceOperation(r, resourceID, portainer.VolumeResourceControl, true)
}
return transport.executeDockerRequest(r)

@ -168,16 +168,30 @@ func (transport *Transport) restrictedVolumeOperation(requestPath string, reques
return transport.rewriteOperation(request, transport.volumeInspectOperation)
}
cli := transport.dockerClient
volume, err := cli.VolumeInspect(context.Background(), path.Base(requestPath))
agentTargetHeader := request.Header.Get(portainer.PortainerAgentTargetHeader)
resourceID, err := transport.getVolumeResourceID(agentTargetHeader, path.Base(requestPath))
if err != nil {
return nil, err
}
volumeID := volume.Name + volume.CreatedAt
if request.Method == http.MethodDelete {
return transport.executeGenericResourceDeletionOperation(request, volumeID, portainer.VolumeResourceControl)
return transport.executeGenericResourceDeletionOperation(request, resourceID, portainer.VolumeResourceControl)
}
return transport.restrictedResourceOperation(request, resourceID, portainer.VolumeResourceControl, false)
}
func (transport *Transport) getVolumeResourceID(nodename, volumeID string) (string, error) {
cli, err := transport.dockerClientFactory.CreateClient(transport.endpoint, nodename)
if err != nil {
return "", err
}
return transport.restrictedResourceOperation(request, volumeID, portainer.VolumeResourceControl, false)
defer cli.Close()
volume, err := cli.VolumeInspect(context.Background(), volumeID)
if err != nil {
return "", err
}
return volume.Name + volume.CreatedAt, nil
}

Loading…
Cancel
Save