Skip to content

Commit

Permalink
Remove support for rootUrl=https://taskcluster.net
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Nov 19, 2019
1 parent 3f43a21 commit 6267b88
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 234 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Welcome to the team!
[bugsahoy]: https://www.joshmatthews.net/bugsahoy/?taskcluster=1
[goodfirstbug]: http://www.joshmatthews.net/bugsahoy/?taskcluster=1&simple=1
[irc]: https://wiki.mozilla.org/IRC
[bestpractices]: https://docs.taskcluster.net/docs/manual/design/devel/best-practices
[testing]: https://docs.taskcluster.net/docs/manual/design/devel/best-practices/testing
[commit]: https://docs.taskcluster.net/docs/manual/design/devel/best-practices/commits
[bestpractices]: https://github.com/taskcluster/taskcluster/tree/master/dev-docs/best-practices/
[testing]: https://github.com/taskcluster/taskcluster/blob/master/dev-docs/best-practices/testing.md
[commit]: https://github.com/taskcluster/taskcluster/blob/master/dev-docs/best-practices/commits.md

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ root URL:
* `withRootUrl(rootUrl)` -> `Class` instance for above methods
* `normalizeRootUrl(rootUrl)` -> `String` (the "normalized" form of the given rootUrl)

When the `rootUrl` is `https://taskcluster.net`, the generated URLs will be to the Heroku cluster. Otherwise they will follow the
[spec defined in this project](https://github.com/taskcluster/taskcluster-lib-urls/tree/master/docs/urls-spec.md).
The generated URLs follow the [spec defined in this project](https://github.com/taskcluster/taskcluster-lib-urls/tree/master/docs/urls-spec.md).

`testRootUrl()` is used to share a common fake `rootUrl` between various Taskcluster mocks in testing.
The URL does not resolve.
Expand Down
116 changes: 5 additions & 111 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,11 @@
const assert = require('assert');

const TASKCLUSTER_NET = 'https://taskcluster.net';

const cleanRoot = rootUrl => rootUrl.replace(/\/*$/, '');
const normalizeRootUrl = rootUrl => rootUrl.replace(/\/*$/, '');
const cleanPath = path => path.replace(/^\/*/, '');

class LegacyUrls {
/**
* Generate URL for path in a Taskcluster service.
*/
api(service, version, path) {
return `https://${service}.taskcluster.net/${version}/${cleanPath(path)}`;
}

/**
* Generate URL for the api reference of a Taskcluster service.
*/
apiReference(service, version) {
return `https://references.taskcluster.net/${service}/${version}/api.json`;
}

/**
* Generate URL for path in the Taskcluster docs website.
*/
docs(path) {
return `https://docs.taskcluster.net/${cleanPath(path)}`;
}

/**
* Generate URL for the exchange reference of a Taskcluster service.
*/
exchangeReference(service, version) {
return `https://references.taskcluster.net/${service}/${
version
}/exchanges.json`;
}

/**
* Generate URL for the schemas of a Taskcluster service.
* The schema usually have the version in its name i.e. "v1/whatever.json"
*/
schema(service, schema) {
return `https://schemas.taskcluster.net/${service}/${cleanPath(schema)}`;
}

/**
* Generate URL for the api reference schema
*/
apiReferenceSchema(version) {
return this.schema('common', `api-reference-${version}.json`);
}

/**
* Generate URL for the exchanges reference schema
*/
exchangesReferenceSchema(version) {
return this.schema('common', `exchanges-reference-${version}.json`);
}

/**
* Generate URL for the api manifest schema
*/
apiManifestSchema(version) {
return this.schema('common', `manifest-${version}.json`);
}

/**
* Generate URL for the metadata metaschema
*/
metadataMetaschema() {
return this.schema('common', 'metadata-metaschema.json');
}

/**
* Generate URL for Taskcluser UI.
*/
ui(path) {
return `https://tools.taskcluster.net/${cleanPath(path)}`;
}

/**
* Returns a URL for the service manifest of a taskcluster deployment.
*/
apiManifest() {
return 'https://references.taskcluster.net/manifest.json';
}
}

class Urls {
constructor(rootUrl) {
this.rootUrl = cleanRoot(rootUrl);
this.rootUrl = normalizeRootUrl(rootUrl);
}

/**
Expand Down Expand Up @@ -171,10 +87,7 @@ class Urls {
}
}

const withRootUrl = rootUrl =>
cleanRoot(rootUrl) === TASKCLUSTER_NET ?
new LegacyUrls() :
new Urls(rootUrl);
const withRootUrl = rootUrl => new Urls(rootUrl);

module.exports = {
/**
Expand All @@ -183,12 +96,6 @@ module.exports = {
*/
Urls,

/**
* Generate URLs for legacy services and entities like Heroku
* from an initial root URL.
*/
LegacyUrls,

/**
* Generate URLs for either redeployable or legacy services and entities
* from an initial root URL.
Expand Down Expand Up @@ -259,18 +166,7 @@ module.exports = {
},

/**
* Generate URL for Taskcluser UI. The purpose of the function is to switch on rootUrl:
* "The driver for having a ui method is so we can just call ui with a path and any root url,
* and the returned url should work for both our current deployment (with root URL = https://taskcluster.net)
* and any future deployment. The returned value is essentially rootURL == 'https://taskcluster.net'
* ? 'https://tools.taskcluster.net/${path}'
* : '${rootURL}/${path}'. "
*
* @param rootUrl - string. Expected to be without a trailing slash
* @param path - string. The rest of the path to append to the rootUrl.
* Can start either with a slash or not.
*
* @returns string. The resulting url
* Generate URL for Taskcluster UI.
*/
ui(rootUrl, path) {
return withRootUrl(rootUrl).ui(path);
Expand All @@ -294,7 +190,5 @@ module.exports = {
/**
* Return the normal form of this rootUrl
*/
normalizeRootUrl(rootUrl) {
return cleanRoot(rootUrl);
},
normalizeRootUrl,
};
61 changes: 15 additions & 46 deletions taskcluster_urls/__init__.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,30 @@
OLD_ROOT_URL = 'https://taskcluster.net'

def api(root_url, service, version, path):
"""Generate URL for path in a Taskcluster service."""
root_url = root_url.rstrip('/')
root_url = normalize_root_url(root_url)
path = path.lstrip('/')
if root_url == OLD_ROOT_URL:
return 'https://{}.taskcluster.net/{}/{}'.format(service, version, path)
else:
return '{}/api/{}/{}/{}'.format(root_url, service, version, path)
return '{}/api/{}/{}/{}'.format(root_url, service, version, path)

def api_reference(root_url, service, version):
"""Generate URL for a Taskcluster api reference."""
root_url = root_url.rstrip('/')
if root_url == OLD_ROOT_URL:
return 'https://references.taskcluster.net/{}/{}/api.json'.format(service, version)
else:
return '{}/references/{}/{}/api.json'.format(root_url, service, version)
root_url = normalize_root_url(root_url)
return '{}/references/{}/{}/api.json'.format(root_url, service, version)

def docs(root_url, path):
"""Generate URL for path in the Taskcluster docs."""
root_url = root_url.rstrip('/')
root_url = normalize_root_url(root_url)
path = path.lstrip('/')
if root_url == OLD_ROOT_URL:
return 'https://docs.taskcluster.net/{}'.format(path)
else:
return '{}/docs/{}'.format(root_url, path)
return '{}/docs/{}'.format(root_url, path)

def exchange_reference(root_url, service, version):
"""Generate URL for a Taskcluster exchange reference."""
root_url = root_url.rstrip('/')
if root_url == OLD_ROOT_URL:
return 'https://references.taskcluster.net/{}/{}/exchanges.json'.format(service, version)
else:
return '{}/references/{}/{}/exchanges.json'.format(root_url, service, version)
root_url = normalize_root_url(root_url)
return '{}/references/{}/{}/exchanges.json'.format(root_url, service, version)

def schema(root_url, service, name):
"""Generate URL for a schema in a Taskcluster service."""
root_url = root_url.rstrip('/')
root_url = normalize_root_url(root_url)
name = name.lstrip('/')
if root_url == OLD_ROOT_URL:
return 'https://schemas.taskcluster.net/{}/{}'.format(service, name)
else:
return '{}/schemas/{}/{}'.format(root_url, service, name)
return '{}/schemas/{}/{}'.format(root_url, service, name)

def api_reference_schema(root_url, version):
"""Generate URL for the api reference schema."""
Expand All @@ -60,29 +43,15 @@ def metadata_metaschema(root_url, version):
return schema(root_url, 'common', 'metadata-metaschema.json')

def ui(root_url, path):
"""
Generate URL for a path in the Taskcluster ui.
The purpose of the function is to switch on rootUrl:
"The driver for having a ui method is so we can just call ui with a path and any root url,
and the returned url should work for both our current deployment (with root URL = https://taskcluster.net)
and any future deployment. The returned value is essentially rootURL == 'https://taskcluster.net'
'https://tools.taskcluster.net/${path}'
'${rootURL}/${path}' "
"""
root_url = root_url.rstrip('/')
"""Generate URL for a path in the Taskcluster ui."""
root_url = normalize_root_url(root_url)
path = path.lstrip('/')
if root_url == OLD_ROOT_URL:
return 'https://tools.taskcluster.net/{}'.format(path)
else:
return '{}/{}'.format(root_url, path)
return '{}/{}'.format(root_url, path)

def api_manifest(root_url):
"""Returns a URL for the API manifest of a taskcluster deployment."""
root_url = root_url.rstrip('/')
if root_url == OLD_ROOT_URL:
return 'https://references.taskcluster.net/manifest.json'
else:
return '{}/references/manifest.json'.format(root_url)
root_url = normalize_root_url(root_url)
return '{}/references/manifest.json'.format(root_url)

def test_root_url():
"""Returns a standardized "testing" rootUrl that does not resolve but
Expand Down
65 changes: 11 additions & 54 deletions tcurls.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,106 +5,63 @@ import (
"strings"
)

const oldRootURL = "https://taskcluster.net"

// API generates a url for a resource in a taskcluster service
func API(rootURL string, service string, version string, path string) string {
path = strings.TrimLeft(path, "/")
switch r := strings.TrimRight(rootURL, "/"); r {
case oldRootURL:
return fmt.Sprintf("https://%s.taskcluster.net/%s/%s", service, version, path)
default:
return fmt.Sprintf("%s/api/%s/%s/%s", r, service, version, path)
}
return fmt.Sprintf("%s/api/%s/%s/%s", NormalizeRootURL(rootURL), service, version, path)
}

// APIReference enerates a url for a taskcluster service reference doc
func APIReference(rootURL string, service string, version string) string {
switch r := strings.TrimRight(rootURL, "/"); r {
case oldRootURL:
return fmt.Sprintf("https://references.taskcluster.net/%s/%s/api.json", service, version)
default:
return fmt.Sprintf("%s/references/%s/%s/api.json", r, service, version)
}
return fmt.Sprintf("%s/references/%s/%s/api.json", NormalizeRootURL(rootURL), service, version)
}

// Docs generates a url for a taskcluster docs-site page
func Docs(rootURL string, path string) string {
path = strings.TrimLeft(path, "/")
switch r := strings.TrimRight(rootURL, "/"); r {
case oldRootURL:
return fmt.Sprintf("https://docs.taskcluster.net/%s", path)
default:
return fmt.Sprintf("%s/docs/%s", r, path)
}
return fmt.Sprintf("%s/docs/%s", NormalizeRootURL(rootURL), path)
}

// ExchangeReference generates a url for a taskcluster exchange reference doc
func ExchangeReference(rootURL string, service string, version string) string {
switch r := strings.TrimRight(rootURL, "/"); r {
case oldRootURL:
return fmt.Sprintf("https://references.taskcluster.net/%s/%s/exchanges.json", service, version)
default:
return fmt.Sprintf("%s/references/%s/%s/exchanges.json", r, service, version)
}
return fmt.Sprintf("%s/references/%s/%s/exchanges.json", NormalizeRootURL(rootURL), service, version)
}

// Schema generates a url for a taskcluster schema
func Schema(rootURL string, service string, name string) string {
name = strings.TrimLeft(name, "/")
switch r := strings.TrimRight(rootURL, "/"); r {
case oldRootURL:
return fmt.Sprintf("https://schemas.taskcluster.net/%s/%s", service, name)
default:
return fmt.Sprintf("%s/schemas/%s/%s", r, service, name)
}
return fmt.Sprintf("%s/schemas/%s/%s", NormalizeRootURL(rootURL), service, name)
}

// APIReferenceSchema generates a url for the api reference schema
func APIReferenceSchema(rootURL string, version string) string {
return Schema(rootURL, "common", fmt.Sprintf("api-reference-%s.json", version))
return Schema(NormalizeRootURL(rootURL), "common", fmt.Sprintf("api-reference-%s.json", version))
}

// ExchangesReferenceSchema generates a url for the exchanges reference schema
func ExchangesReferenceSchema(rootURL string, version string) string {
return Schema(rootURL, "common", fmt.Sprintf("exchanges-reference-%s.json", version))
return Schema(NormalizeRootURL(rootURL), "common", fmt.Sprintf("exchanges-reference-%s.json", version))
}

// APIManifestSchema generates a url for the api manifest schema
func APIManifestSchema(rootURL string, version string) string {
return Schema(rootURL, "common", fmt.Sprintf("manifest-%s.json", version))
return Schema(NormalizeRootURL(rootURL), "common", fmt.Sprintf("manifest-%s.json", version))
}

// MetadataMetaschema generates a url for the metadata metaschema
func MetadataMetaschema(rootURL string) string {
return Schema(rootURL, "common", "metadata-metaschema.json")
return Schema(NormalizeRootURL(rootURL), "common", "metadata-metaschema.json")
}

// UI generates a url for a page in taskcluster tools site
// The purpose of the function is to switch on rootUrl:
// "The driver for having a ui method is so we can just call ui with a path and any root url,
// and the returned url should work for both our current deployment (with root URL = https://taskcluster.net)
// and any future deployment. The returned value is essentially rootURL == 'https://taskcluster.net'
// ? 'https://tools.taskcluster.net/${path}'
// : '${rootURL}/${path}' "
func UI(rootURL string, path string) string {
path = strings.TrimLeft(path, "/")
switch r := strings.TrimRight(rootURL, "/"); r {
case oldRootURL:
return fmt.Sprintf("https://tools.taskcluster.net/%s", path)
default:
return fmt.Sprintf("%s/%s", r, path)
}
return fmt.Sprintf("%s/%s", NormalizeRootURL(rootURL), path)
}

// APIManifest returns a URL for the service manifest of a taskcluster deployment
func APIManifest(rootURL string) string {
switch r := strings.TrimRight(rootURL, "/"); r {
case oldRootURL:
return "https://references.taskcluster.net/manifest.json"
default:
return fmt.Sprintf("%s/references/manifest.json", r)
}
return fmt.Sprintf("%s/references/manifest.json", NormalizeRootURL(rootURL))
}

// NormalizeRootURL returns the normal form of the given rootURL.
Expand Down
Loading

0 comments on commit 6267b88

Please sign in to comment.