Skip to content

Commit 2b2f52d

Browse files
authored
Merge pull request #12 from taskcluster/bug1468606
Bug 1468606 - add servicesManifest method
2 parents b9e35ff + a5b9272 commit 2b2f52d

File tree

10 files changed

+81
-11
lines changed

10 files changed

+81
-11
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jspm_packages
3434
# Optional npm cache directory
3535
.npm
3636

37+
# npm package lock file
38+
package-lock.json
39+
3740
# Optional REPL history
3841
.node_repl_history
3942

.gometalinter.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"Enable": [
33
"deadcode",
44
"errcheck",
5-
"gas",
65
"goconst",
76
"goimports",
87
"golint",

.taskcluster.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ tasks:
2424
- "-lc"
2525
- "git clone {{event.head.repo.url}} repo && cd repo && git checkout {{event.head.sha}} && yarn install && yarn test"
2626
metadata:
27-
name: "taskcluster-lib-urls test"
27+
name: "taskcluster-lib-urls node.js test"
2828
description: "Library for building taskcluster urls"
2929
owner: "{{ event.head.user.email }}"
3030
source: "{{ event.head.repo.url }}"
@@ -87,7 +87,7 @@ tasks:
8787
gometalinter --install &&
8888
gometalinter
8989
metadata:
90-
name: taskcluster-lib-urls go test
90+
name: "taskcluster-lib-urls go test"
9191
description: Run library test suite - golang 1.10
9292
owner: '{{ event.head.user.email }}'
9393
source: '{{ event.head.repo.url }}'
@@ -114,7 +114,7 @@ tasks:
114114
pip install tox &&
115115
tox -e py27
116116
metadata:
117-
name: taskcluster-lib-urls python 2.7 test
117+
name: "taskcluster-lib-urls python 2.7 test"
118118
description: Run library test suite - python2.7
119119
owner: '{{ event.head.user.email }}'
120120
source: '{{ event.head.repo.url }}'

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ root URL:
3333
* `exchangeReference(rootUrl, service, version)` -> `String`
3434
* `schema(rootUrl, service, schema)` -> `String`
3535
* `ui(rootUrl, path)` -> `String`
36+
* `servicesManifest(rootUrl)` -> `String`
3637
* `testRootUrl()` -> `String`
3738
* `withRootUrl(rootUrl)` -> `Class` instance for above methods
3839

@@ -50,6 +51,7 @@ libUrls.schema(rootUrl, 'auth', 'v1/foo.yml'); // Note that schema names have ve
5051
libUrls.apiReference(rootUrl, 'auth', 'v1');
5152
libUrls.exchangeReference(rootUrl, 'auth', 'v1');
5253
libUrls.ui(rootUrl, 'foo/bar');
54+
libUrls.servicesManifest(rootUrl);
5355
libUrls.docs(rootUrl, 'foo/bar');
5456
```
5557

@@ -64,6 +66,7 @@ urls.schema('auth', 'v1/foo.yml');
6466
urls.apiReference('auth', 'v1');
6567
urls.exchangeReference('auth', 'v1');
6668
urls.ui('foo/bar');
69+
urls.servicesManifest();
6770
urls.docs('foo/bar');
6871
```
6972

@@ -90,6 +93,7 @@ func Docs(rootURL string, path string) string
9093
func ExchangeReference(rootURL string, service string, version string) string
9194
func Schema(rootURL string, service string, name string) string
9295
func UI(rootURL string, path string) string
96+
func ServicesManifest(rootURL string) string
9397
```
9498

9599
Python Usage
@@ -105,6 +109,7 @@ taskcluster_urls.schema(root_url, 'auth', 'v1/foo.yml') # Note that schema names
105109
taskcluster_urls.api_reference(root_url, 'auth', 'v1')
106110
taskcluster_urls.exchange_reference(root_url, 'auth', 'v1')
107111
taskcluster_urls.ui(root_url, 'foo/bar')
112+
taskcluster_urls.servicesManifest(root_url)
108113
taskcluster_urls.docs(root_url, 'foo/bar')
109114
```
110115

docs/urls-spec.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Taskcluster uses URLs with the following pattern:
2525
| exchangeReference(rootUrl, service, version) | `<rootUrl>/references/<service>/<version>/exchanges.json` |
2626
| schema(rootUrl, service, schema) | `<rootUrl>/schemas/<service>/<schema>` |
2727
| ui(rootUrl, path) | `<rootUrl>/<path>` |
28+
| servicesManifest(rootUrl) | `<rootUrl>/references/manifest.json` |
2829

2930
*NOTE*: you should *always* use this library to generate URLs, rather than
3031
hard-coding any of the above patterns.

specification.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,8 @@ specs:
6464
argSets:
6565
- ['']
6666
- [/]
67+
- type: servicesManifest
68+
expectedUrl: https://taskcluster.example.com/references/manifest.json
69+
oldExpectedUrl: https://references.taskcluster.net/manifest.json
70+
argSets:
71+
- []

src/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ class LegacyUrls {
5050
ui(path) {
5151
return `https://tools.taskcluster.net/${cleanPath(path)}`;
5252
}
53+
54+
/**
55+
* Returns a URL for the service manifest of a taskcluster deployment.
56+
*/
57+
servicesManifest() {
58+
return 'https://references.taskcluster.net/manifest.json';
59+
}
5360
}
5461

5562
class Urls {
@@ -100,6 +107,13 @@ class Urls {
100107
ui(path) {
101108
return `${this.rootUrl}/${cleanPath(path)}`;
102109
}
110+
111+
/**
112+
* Returns a URL for the service manifest of a taskcluster deployment.
113+
*/
114+
servicesManifest() {
115+
return `${this.rootUrl}/references/manifest.json`;
116+
}
103117
}
104118

105119
const withRootUrl = rootUrl =>
@@ -168,6 +182,13 @@ module.exports = {
168182
return withRootUrl(rootUrl).ui(path);
169183
},
170184

185+
/**
186+
* Returns a URL for the service manifest of a taskcluster deployment.
187+
*/
188+
servicesManifest(rootUrl) {
189+
return withRootUrl(rootUrl).servicesManifest();
190+
},
191+
171192
/**
172193
* Return the standardized taskcluster "testing" rootUrl.
173194
* Useful for nock and such things.

taskcluster_urls/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,11 @@ def ui(root_url, path):
5151
return 'https://tools.taskcluster.net/{}'.format(path)
5252
else:
5353
return '{}/{}'.format(root_url, path)
54+
55+
def services_manifest(root_url):
56+
"""Returns a URL for the service manifest of a taskcluster deployment."""
57+
root_url = root_url.rstrip('/')
58+
if root_url == OLD_ROOT_URL:
59+
return 'https://references.taskcluster.net/manifest.json'
60+
else:
61+
return '{}/references/manifest.json'.format(root_url)

tcurls.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,13 @@ func UI(rootURL string, path string) string {
7070
return fmt.Sprintf("%s/%s", r, path)
7171
}
7272
}
73+
74+
// ServicesManifest returns a URL for the service manifest of a taskcluster deployment
75+
func ServicesManifest(rootURL string) string {
76+
switch r := strings.TrimRight(rootURL, "/"); r {
77+
case oldRootURL:
78+
return "https://references.taskcluster.net/manifest.json"
79+
default:
80+
return fmt.Sprintf("%s/references/manifest.json", r)
81+
}
82+
}

tcurls_test.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tcurls
33
import (
44
"fmt"
55
"io/ioutil"
6+
"strings"
67
"testing"
78

89
"gopkg.in/yaml.v2"
@@ -35,12 +36,14 @@ func testFunc(t *testing.T, functionType string, root string, args ...string) (s
3536
return Schema(root, args[0], args[1]), nil
3637
case "ui":
3738
return UI(root, args[0]), nil
39+
case "servicesManifest":
40+
return ServicesManifest(root), nil
3841
default:
3942
return "", fmt.Errorf("Unknown function type: %s", functionType)
4043
}
4144
}
4245

43-
func TestUrls(t *testing.T) {
46+
func TestURLs(t *testing.T) {
4447
data, err := ioutil.ReadFile("specification.yml")
4548
if err != nil {
4649
t.Error(err)
@@ -52,41 +55,56 @@ func TestUrls(t *testing.T) {
5255
}
5356

5457
for _, test := range specs.Specs {
55-
// First test "new" urls
5658
for _, argSet := range test.ArgSets {
59+
60+
// Test "new" URLs
5761
result, err := testFunc(t, test.FunctionType, rootURL, argSet...)
5862
if err != nil {
5963
t.Error(err)
6064
continue
6165
}
6266
if result != test.ExpectedURL {
63-
t.Errorf("Url is not correct. Got %s wanted %s", result, test.ExpectedURL)
67+
t.Errorf("URL is not correct. Got %q wanted %q", result, test.ExpectedURL)
6468
continue
6569
}
6670
result, err = testFunc(t, test.FunctionType, fmt.Sprintf("%s/", rootURL), argSet...)
6771
if err != nil {
6872
t.Error(err)
6973
}
7074
if result != test.ExpectedURL {
71-
t.Errorf("Url is not correct. Got %s wanted %s", result, test.ExpectedURL)
75+
t.Errorf("URL is not correct. Got %q wanted %q", result, test.ExpectedURL)
7276
continue
7377
}
78+
t.Logf(`%v %v(%v) = %q`, greenTick(), test.FunctionType, quotedList(rootURL, argSet), result)
7479

75-
// Now the old ones
80+
// Test "old" URLs
7681
result, err = testFunc(t, test.FunctionType, oldRootURL, argSet...)
7782
if err != nil {
7883
t.Error(err)
7984
}
8085
if result != test.OldExpectedURL {
81-
t.Errorf("Url is not correct. Got %s wanted %s", result, test.OldExpectedURL)
86+
t.Errorf("URL is not correct. Got %q wanted %q", result, test.OldExpectedURL)
8287
}
8388
result, err = testFunc(t, test.FunctionType, fmt.Sprintf("%s/", oldRootURL), argSet...)
8489
if err != nil {
8590
t.Error(err)
8691
}
8792
if result != test.OldExpectedURL {
88-
t.Errorf("Url is not correct. Got %s wanted %s", result, test.OldExpectedURL)
93+
t.Errorf("URL is not correct. Got %q wanted %q", result, test.OldExpectedURL)
8994
}
95+
t.Logf(`%v %v(%v) = %q`, greenTick(), test.FunctionType, quotedList(oldRootURL, argSet), result)
9096
}
9197
}
9298
}
99+
100+
// quotedList returns a quoted list of the arguments passed in
101+
func quotedList(url string, args []string) string {
102+
all := append([]string{url}, args...)
103+
return `'` + strings.Join(all, `', '`) + `'`
104+
}
105+
106+
// greenTick returns an ANSI string including escape codes to render a light
107+
// green tick (✓) in a color console
108+
func greenTick() string {
109+
return string([]byte{0x1b, 0x5b, 0x33, 0x32, 0x6d, 0xe2, 0x9c, 0x93, 0x1b, 0x5b, 0x30, 0x6d})
110+
}

0 commit comments

Comments
 (0)