Taskcluster URL Building Library
A simple library to generate URLs for various Taskcluster resources across our various deployment methods.
This serves as both a simple shim for projects that use JavaScript but also is the reference implementation for how we define these paths.
URLs are defined in the 'Taskcluster URL Format.
Changelog
View the changelog on the releases page.
Requirements
This is tested on and should run on any of Node.js {8, 10}
.
General Usage
While the capitalization and punctunation of the function names varies depending on the language, each language provides the following methods:
method | result |
---|---|
api(rootUrl, service, version, path) -> | <rootUrl>/api/<service>/<version>/<path> |
apiReference(rootUrl, service, version) -> | <rootUrl>/references/<service>/<version>/api.json |
docs(rootUrl, path) -> | <rootUrl>/docs/<path> |
exchangeReference(rootUrl, service, version) -> | <rootUrl>/references/<service>/<version>/exchanges.json |
schema(rootUrl, service, schema) -> | <rootUrl>/schemas/<service>/<schema> |
apiSchema(rootUrl, version) -> | <rootUrl>/schemas/common/api-reference-<version>.json |
exchangesSchema(rootUrl, version) -> | <rootUrl>/schemas/common/exchanges-reference-<version>.json |
apiManifestSchema(rootUrl, version) -> | <rootUrl>/schemas/common/manifest-<version>.json |
metadataMchema(rootUrl) -> | <rootUrl>/schemas/common/metadata-metaschema.json |
ui(rootUrl, path) -> | <rootUrl>/<path> |
apiManifest(rootUrl) -> | <rootUrl>/references/manifest.json |
normalizeRootUrl(rootUrl) -> | the normal form of the given rootUrl |
testRootUrl() -> | https://tc-tests.example.com |
testRootUrl()
is used to share a common fake rootUrl
between various Taskcluster mocks in testing.
The URL does not resolve.
JS Usage
This package exports several methods for generating URLs conditionally based on a root URL, as well as a few helper classes for generating URLs for a pre-determined root URL:
api(rootUrl, service, version, path)
->String
apiReference(rootUrl, service, version)
->String
docs(rootUrl, path)
->String
exchangeReference(rootUrl, service, version)
->String
schema(rootUrl, service, schema)
->String
apiManifestSchema(rootUrl, version)
->String
apiReferenceSchema(rootUrl, version)
->String
exchangesReferenceSchema(rootUrl, version)
->String
metadataMetaschema(rootUrl)
->String
ui(rootUrl, path)
->String
apiManifest(rootUrl)
->String
testRootUrl()
->String
withRootUrl(rootUrl)
->Class
instance for above methodsnormalizeRootUrl(rootUrl)
->String
(the "normalized" form of the given rootUrl)
// Specifying root URL every time:const libUrls = ; libUrls;libUrls; // Note that schema names have versions in themlibUrls;libUrls;libUrls;libUrls;libUrls;
// Specifying root URL in advance:const libUrls = ; const urls = libUrls; urls;urls;urls;urls;urls;urls;urls;
If you would like, you can set this up via taskcluster-lib-loader as follows:
libUrlss: require: 'cfg'
Test with:
yarn install
yarn test
Go Usage
The go package exports the following functions:
func API(rootURL string, service string, version string, path string) stringfunc APIReference(rootURL string, service string, version string) stringfunc Docs(rootURL string, path string) stringfunc ExchangeReference(rootURL string, service string, version string) stringfunc Schema(rootURL string, service string, name string) stringfunc APIManifestSchema(rootURL string, version string) stringfunc APIReferenceSchema(rootURL string, version string) stringfunc ExchangesReferenceSchema(rootURL string, version string) stringfunc MetadataMetaschema(rootURL string) stringfunc UI(rootURL string, path string) stringfunc APIManifest(rootURL string) stringfunc NormalizeRootURL(rootURL string) string
Install with:
go install ./..
Test with:
go test -v ./...
Python Usage
You can install the python client with pip install taskcluster-urls
;
import taskcluster_urls # Note that schema names have versions in them
Test with:
tox
Java Usage
In order to use this library from your maven project, simply include it as a project dependency:
<project>
...
<dependencies>
...
<dependency>
<groupId>org.mozilla.taskcluster</groupId>
<artifactId>taskcluster-lib-urls</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
The taskcluster-lib-urls artifacts are now available from the maven central repository:
To use the library, do as follows:
... URLProvider urlProvider = URLs.; String fooBarAPI = urlProvider.; String fooSchema = urlProvider.; // Note that schema names have versions in them String apiSchema = urlProvider.; String exchangesSchema = urlProvider.; String manifestSchema = urlProvider.; String metaschema = urlProvider.; String authAPIRef = urlProvider.; String authExchangesRef = urlProvider.; String uiFooBar = urlProvider.; String apiManifest = urlProvider.; String docsFooBar = urlProvider.; ...
Install with:
mvn install
Test with:
mvn test
Releasing
New releases should be tested on Travis and Taskcluster to allow for all supported versions of various languages to be tested. Once satisfied that it works, new versions should be created with
npm version
rather than by manually editing package.json
and tags should be pushed to Github.
Make the Node release first, as Python's version depends on its package.json
. This follows the typical tag-and-push-to-publish approach:
$ npm version minor # or patch, or major $ git push upstream
Once that's done, build the Python sdists (only possible by the maintainers on pypi):
rm -rf dist/*python setup.py sdist bdist_wheelpython3 setup.py bdist_wheelpip install twinetwine upload dist/*
Make sure to update the changelog!