跳转到主要内容

为taskcluster资源提供标准化的URL生成器。

项目描述

Taskcluster URL构建库

License

一个简单的库,用于生成各种Taskcluster资源在不同部署方法下的URL。

这既是一个使用JavaScript的项目的一个简单垫片,也是我们定义这些路径的参考实现。

URL在《Taskcluster URL格式》中定义。

变更日志

发布页面上查看变更日志。

需求

该软件已在Node.js {8, 10}上测试,并且应该在任何这些版本上运行。

通用用法

尽管函数名称的大小写和标点符号因语言而异,但每种语言都提供了以下方法

方法 结果
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) -> 给定根URL的规范形式
testRootUrl() -> https://tc-tests.example.com

testRootUrl()用于在测试中在不同Taskcluster模拟之间共享一个公共的假rootUrl。此URL无法解析。

JavaScript用法

Node.js Build Status npm

此包导出了一些方法,可以根据根URL有条件地生成URL,以及一些用于生成预定义根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) -> 用于上述方法的对象实例
  • normalizeRootUrl(rootUrl) -> String(给定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');

如果您愿意,可以通过taskcluster-lib-loader设置如下

{
  libUrlss: {
    require: ['cfg'],
    setup: ({cfg}) => withRootUrl(cfg.rootURl),
  },
}

测试方法

yarn install
yarn test

Go用法

GoDoc

此Go包导出以下函数

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

安装方法

go install ./..

测试方法

go test -v ./...

Python用法

您可以使用pip install taskcluster-urls安装Python客户端

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()

测试方法

tox

Java用法

JavaDoc

要在此Maven项目中使用此库,只需将其作为项目依赖项包含即可

<project>
  ...
  <dependencies>
    ...
    <dependency>
      <groupId>org.mozilla.taskcluster</groupId>
      <artifactId>taskcluster-lib-urls</artifactId>
      <version>1.0.0</version>
    </dependency>
  </dependencies>
</project>

taskcluster-lib-urls工件现在可以从Maven中央仓库获取

要使用此库,请按以下方法操作

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");

...

安装方法

mvn install

测试方法

mvn test

发布

应该在Travis和Taskcluster上测试新版本,以便测试所有支持的语言版本的各个版本。一旦满意它的工作,就应该使用npm version而不是手动编辑package.json来创建新版本,并将标签推送到Github。

首先制作Node版本,因为Python的版本依赖于其package.json。这遵循了典型的打标签和推送到发布的做法

$ npm version minor  # or patch, or major
$ git push upstream

完成此操作后,构建Python的sdists(只能由pypi上的维护者完成)

rm -rf dist/*
python setup.py sdist bdist_wheel
python3 setup.py bdist_wheel
pip install twine
twine upload dist/*

确保更新变更日志

许可证

Mozilla公共许可证版本2.0

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

taskcluster-urls-13.0.1.tar.gz (10.7 kB 查看哈希)

上传时间 源代码

构建分发

taskcluster_urls-13.0.1-py3-none-any.whl (10.2 kB 查看哈希)

上传时间 Python 3

taskcluster_urls-13.0.1-py2-none-any.whl (10.2 kB 查看哈希)

上传时间 Python 2