diff --git a/README.md b/README.md index 7db85144..a4ea1bd9 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ Installing From Source ---------------------- 1. [Install go 1.10](https://golang.org/doc/install) or higher -2. `go get -u -t -d github.com/taskclustertaskcluster-worker/...` -3. `cd "${GOPATH}/src/github.com/taskcluster-worker"` +2. `go get -u -t -d github.com/taskcluster/taskcluster-worker/...` +3. `cd "${GOPATH}/src/github.com/taskcluster/taskcluster-worker"` 4. `go get -u github.com/kardianos/govendor` 5. `govendor sync` 6. `make rebuild` diff --git a/examples/docker-config.yml b/examples/docker-config.yml index 83c2a85c..57386560 100644 --- a/examples/docker-config.yml +++ b/examples/docker-config.yml @@ -36,7 +36,7 @@ config: success: {} watchdog: {} relengapi: - host: "https://api.pub.build.mozilla.org/" + domain: "mozilla-releng.net" token: "" temporaryFolder: /tmp/tc-worker-tmp webHookServer: @@ -49,4 +49,4 @@ config: provisionerId: "provisionerId" workerType: "workerType" workerGroup: "workerGroup" - workerId: "workerId" \ No newline at end of file + workerId: "workerId" diff --git a/plugins/relengapi/config.go b/plugins/relengapi/config.go index f8f199d8..1dab66cd 100644 --- a/plugins/relengapi/config.go +++ b/plugins/relengapi/config.go @@ -6,8 +6,8 @@ import ( ) type config struct { - Host string `json:"host"` - Token string `json:"token"` + Domain string `json:"domain"` + Token string `json:"token"` } var configSchema = schematypes.Object{ @@ -17,10 +17,10 @@ var configSchema = schematypes.Object{ [Releng API](https://wiki.mozilla.org/ReleaseEngineering/Applications/RelengAPI). `), Properties: schematypes.Properties{ - "host": schematypes.String{ - Title: "Releng API host endpoint", + "domain": schematypes.String{ + Title: "Releng API base domain", Description: util.Markdown(` - The releng API host endpoint. Default: api.pub.build.mozilla.org/. + The releng API base domain. Default: mozilla-releng.net. `), }, "token": schematypes.String{ diff --git a/plugins/relengapi/relengapi.go b/plugins/relengapi/relengapi.go index 9ae25641..80e1d241 100644 --- a/plugins/relengapi/relengapi.go +++ b/plugins/relengapi/relengapi.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "net/http/httputil" + "strings" "time" "github.com/pkg/errors" @@ -33,7 +34,7 @@ type taskPlugin struct { tmpToken string tmpTokenGoodUntil time.Time permissions []string - relengapiHost string + relengapiDomain string } func init() { @@ -51,8 +52,8 @@ func (p *plugin) PayloadSchema() schematypes.Object { func (provider) NewPlugin(options plugins.PluginOptions) (plugins.Plugin, error) { var c config schematypes.MustValidateAndMap(configSchema, options.Config, &c) - if c.Host == "" { - c.Host = "api.pub.build.mozilla.org" + if c.Domain == "" { + c.Domain = "mozilla-releng.net" } if c.Token == "" { @@ -99,17 +100,39 @@ func (p *plugin) NewTaskPlugin(options plugins.TaskPluginOptions) (plugins.TaskP } tp := &taskPlugin{ - monitor: options.Monitor, - context: options.TaskContext, - permissions: perms, - relengapiHost: p.config.Host, + monitor: options.Monitor, + context: options.TaskContext, + permissions: perms, + relengapiDomain: p.config.Domain, } // stolen from relengapi-proxy director := func(req *http.Request) { - req.URL.Scheme = "https" - req.URL.Host = p.config.Host - req.Host = p.config.Host + if strings.HasPrefix(req.URL.Path, "/tooltool") { + req.URL.Scheme = "https" + req.URL.Path = strings.TrimPrefix(req.URL.Path, "/tooltool") + req.URL.RawPath = "" + host := fmt.Sprintf("tooltool.%s", p.config.Domain) + req.URL.Host = host + req.Host = host + } else if strings.HasPrefix(req.URL.Path, "/treestatus") { + req.URL.Scheme = "https" + req.URL.Path = strings.TrimPrefix(req.URL.Path, "/treestatus") + req.URL.RawPath = "" + host := fmt.Sprintf("treestatus.%s", p.config.Domain) + req.URL.Host = host + req.Host = host + } else if strings.HasPrefix(req.URL.Path, "/mapper") { + req.URL.Scheme = "https" + req.URL.Path = strings.TrimPrefix(req.URL.Path, "/mapper") + req.URL.RawPath = "" + host := fmt.Sprintf("mapper.%s", p.config.Domain) + req.URL.Host = host + req.Host = host + } else { + // ignore everything else + return + } tok, err := tp.getToken(p.config.Token) if err != nil { err = errors.Wrap(err, "Error retrieving token") @@ -157,9 +180,8 @@ func (p *taskPlugin) getToken(issuingToken string) (string, error) { if now.After(p.tmpTokenGoodUntil) { expires := now.Add(tmpTokenLifetime) debug("Generating new temporary token; expires at " + expires.String()) - urlPrefix := fmt.Sprintf("https://%s", p.relengapiHost) - tok, err := getTmpToken( - urlPrefix, issuingToken, expires, p.permissions) + url := fmt.Sprintf("https://tokens.%s", p.relengapiDomain) + tok, err := getTmpToken(url, issuingToken, expires, p.permissions) if err != nil { return "", err } diff --git a/plugins/relengapi/relengapi_test.go b/plugins/relengapi/relengapi_test.go index 27b69256..87780524 100644 --- a/plugins/relengapi/relengapi_test.go +++ b/plugins/relengapi/relengapi_test.go @@ -12,7 +12,7 @@ func TestTCProxySuccess(t *testing.T) { Payload: `{ "delay": 100, "function": "ping-proxy", - "argument": "http://relengapi/versions", + "argument": "https://relengapi/tooltool/docs/index.html", "enableRelengAPIProxy": true }`, Plugin: "relengapi", @@ -32,7 +32,7 @@ func TestTCProxyFail(t *testing.T) { Payload: `{ "delay": 100, "function": "ping-proxy", - "argument": "http://relengapi/foo/bar", + "argument": "https://relengapi/foo/bar", "enableRelengAPIProxy": true }`, Plugin: "relengapi", diff --git a/plugins/relengapi/token.go b/plugins/relengapi/token.go index f11ecc3a..0e5de474 100644 --- a/plugins/relengapi/token.go +++ b/plugins/relengapi/token.go @@ -22,7 +22,7 @@ type relengapiTokenJSON struct { Token string `json:"token,omitempty"` } -func getTmpToken(urlPrefix string, issuingToken string, expires time.Time, perms []string) (tok string, err error) { +func getTmpToken(url string, issuingToken string, expires time.Time, perms []string) (tok string, err error) { request := relengapiTokenJSON{ Typ: "tmp", Expires: &expires, @@ -36,7 +36,7 @@ func getTmpToken(urlPrefix string, issuingToken string, expires time.Time, perms } client := &http.Client{} - reqURL := fmt.Sprintf("%s/tokenauth/tokens", urlPrefix) + reqURL := fmt.Sprintf("%s/tokens", url) req, err := http.NewRequest("POST", reqURL, bytes.NewBuffer(reqbody)) if err != nil { return