Standardized url generator for taskcluster resources.
Project description
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 = require('taskcluster-lib-urls');
libUrls.api(rootUrl, 'auth', 'v1', 'foo/bar');
libUrls.schema(rootUrl, 'auth', 'v1/foo.yml'); // Note that schema names have versions in them
libUrls.apiReference(rootUrl, 'auth', 'v1');
libUrls.exchangeReference(rootUrl, 'auth', 'v1');
libUrls.ui(rootUrl, 'foo/bar');
libUrls.apiManifest(rootUrl);
libUrls.docs(rootUrl, 'foo/bar');
// Specifying root URL in advance:
const libUrls = require('taskcluster-lib-urls');
const urls = libUrls.withRoot(rootUrl);
urls.api('auth', 'v1', 'foo/bar');
urls.schema('auth', 'v1/foo.yml');
urls.apiReference('auth', 'v1');
urls.exchangeReference('auth', 'v1');
urls.ui('foo/bar');
urls.apiManifest();
urls.docs('foo/bar');
If you would like, you can set this up via taskcluster-lib-loader as follows:
{
libUrlss: {
require: ['cfg'],
setup: ({cfg}) => withRootUrl(cfg.rootURl),
},
}
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) string
func APIReference(rootURL string, service string, version string) string
func Docs(rootURL string, path string) string
func ExchangeReference(rootURL string, service string, version string) string
func Schema(rootURL string, service string, name string) string
func APIManifestSchema(rootURL string, version string) string
func APIReferenceSchema(rootURL string, version string) string
func ExchangesReferenceSchema(rootURL string, version string) string
func MetadataMetaschema(rootURL string) string
func UI(rootURL string, path string) string
func APIManifest(rootURL string) string
func 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
taskcluster_urls.api(root_url, 'auth', 'v1', 'foo/bar')
taskcluster_urls.schema(root_url, 'auth', 'v1/foo.yml') # Note that schema names have versions in them
taskcluster_urls.api_manifest_schema(root_url, 'v1')
taskcluster_urls.api_reference_schema(root_url, 'v1')
taskcluster_urls.exchanges_reference_schema(root_url, 'v1')
taskcluster_urls.metadata_metaschema(root_url, 'v1')
taskcluster_urls.api_reference(root_url, 'auth', 'v1')
taskcluster_urls.exchange_reference(root_url, 'auth', 'v1')
taskcluster_urls.ui(root_url, 'foo/bar')
taskcluster_urls.apiManifest(root_url)
taskcluster_urls.docs(root_url, 'foo/bar')
taskcluster_urls.normalize_root_url(root_url)
taskcluster_urls.test_root_url()
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:
import org.mozilla.taskcluster.urls.*;
...
URLProvider urlProvider = URLs.provider("https://mytaskcluster.acme.org");
String fooBarAPI = urlProvider.api("auth", "v1", "foo/bar");
String fooSchema = urlProvider.schema("auth", "v1/foo.yml"); // Note that schema names have versions in them
String apiSchema = urlProvider.apiReferenceSchema("v1");
String exchangesSchema = urlProvider.exchangesReferenceSchema("v1");
String manifestSchema = urlProvider.apiManifestSchema("v1");
String metaschema = urlProvider.metadataMetaschema();
String authAPIRef = urlProvider.apiReference("auth", "v1");
String authExchangesRef = urlProvider.exchangeReference("auth", "v1");
String uiFooBar = urlProvider.ui("foo/bar");
String apiManifest = urlProvider.apiManifest();
String docsFooBar = urlProvider.docs("foo/bar");
...
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_wheel
python3 setup.py bdist_wheel
pip install twine
twine upload dist/*
Make sure to update the changelog!
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file taskcluster-urls-13.0.1.tar.gz
.
File metadata
- Download URL: taskcluster-urls-13.0.1.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/2.7.15+
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b25e122ecec249c4299ac7b20b08db76e3e2025bdaeb699a9d444556de5fd367 |
|
MD5 | 656aca209d52aeb8aef78a79d21487f5 |
|
BLAKE2b-256 | fb482a94e0cca71acab9d5e6874c400594dafa9348b49fa226683fc815f1089d |
File details
Details for the file taskcluster_urls-13.0.1-py3-none-any.whl
.
File metadata
- Download URL: taskcluster_urls-13.0.1-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/2.7.15+
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f66dcbd6572a6216ab65949f0fa0b91f2df647918028436c384e6af5cd12ae2b |
|
MD5 | 01765472c1daf27de72a75c299eabd19 |
|
BLAKE2b-256 | 247aa2462a171675fab3de5f8e9d7e7d1624a7cd81e305c07c00fbe39b860626 |
File details
Details for the file taskcluster_urls-13.0.1-py2-none-any.whl
.
File metadata
- Download URL: taskcluster_urls-13.0.1-py2-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/2.7.15+
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e25e7e6818e8877178b175ff43d2e6548afad72694aa125f404a7329ece0973 |
|
MD5 | 307f462d34842f82522d86d2e389c981 |
|
BLAKE2b-256 | 37afa4a16ff107498d056489410907c2ac140d10c00abbf0df5f42f75d8131ab |