allow discovery without trailing slash

This commit is contained in:
James Bardin 2017-12-05 15:06:17 -05:00
parent 0e7dab09e6
commit 34b4000be9
2 changed files with 8 additions and 5 deletions

View File

@ -66,7 +66,11 @@ func NewClient(services *disco.Disco, creds auth.CredentialsSource, client *http
// Discover qeuries the host, and returns the url for the registry.
func (c *Client) Discover(host svchost.Hostname) *url.URL {
return c.services.DiscoverServiceURL(host, serviceID)
service := c.services.DiscoverServiceURL(host, serviceID)
if !strings.HasSuffix(service.Path, "/") {
service.Path += "/"
}
return service
}
// Versions queries the registry for a module, and returns the available versions.
@ -80,9 +84,6 @@ func (c *Client) Versions(module *regsrc.Module) (*response.ModuleVersions, erro
if service == nil {
return nil, fmt.Errorf("host %s does not provide Terraform modules", host)
}
if !strings.HasSuffix(service.Path, "/") {
service.Path += "/"
}
p, err := url.Parse(path.Join(module.Module(), "versions"))
if err != nil {

View File

@ -23,7 +23,9 @@ import (
// localhost.localdomain, and example.com to the test server.
func Disco(s *httptest.Server) *disco.Disco {
services := map[string]interface{}{
"modules.v1": fmt.Sprintf("%s/v1/modules/", s.URL),
// Note that both with and without trailing slashes are supported behaviours
// TODO: add specific tests to enumerate both possibilities.
"modules.v1": fmt.Sprintf("%s/v1/modules", s.URL),
}
d := disco.NewDisco()