Skip to content

Commit 025e663

Browse files
djmitcheowlishDeveloper
authored andcommitted
Merge pull request taskcluster#51 from djmitche/bug1499859
Bug 1499859 - use pulseCredentials instead of claimedCredentials
1 parent 97a058e commit 025e663

File tree

5 files changed

+54
-54
lines changed

5 files changed

+54
-54
lines changed

services/web-server/README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ $ eval $(./taskcluster signin --name taskcluster-web-server)
4646

4747
### Pulse
4848

49-
To receive pulse messages, you will also need a Pulse namespace and the
50-
Taskcluster credentials you select must have the scope
51-
`pulse:namespace:<namespace>`. A member of the administrators for the
52-
Taskcluster instance you are using can help set that up. Add the namespace in
53-
`user-config.yml` as `pulse.namespace`.
49+
Pulse messages are entirely optional, and most server components do not require
50+
them. If you do not configure pulse, the server will act as if no pulse
51+
messages are received, which is sufficient for most development work.
52+
53+
To receive pulse messages, you will also need a Pulse user. For Mozilla's
54+
Pulse, you can get such credentials at https://pulseguardian.mozilla.org. Use
55+
hostname `pulse.mozilla.org` and vhost `/`. In this situation, set the
56+
namespace to match the username.
5457

5558
### Starting
5659

services/web-server/config.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ defaults:
2424
# Pulse credentials
2525
pulse:
2626
namespace: !env PULSE_NAMESPACE
27-
contact: !env PULSE_CONTACT
28-
expiresAfter: !env PULSE_EXPIRES_AFTER
27+
username: !env PULSE_USERNAME
28+
password: !env PULSE_PASSWORD
29+
hostname: !env PULSE_HOSTNAME
30+
vhost: !env PULSE_VHOST
2931

3032
# config for the github login strategy
3133
githubLogin:
@@ -44,3 +46,7 @@ development:
4446
monitoring:
4547
project: taskcluster-web-server
4648
mock: true
49+
50+
production:
51+
pulse:
52+
namespace: taskcluster-web-server

services/web-server/src/PulseEngine/index.js

+5-40
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import Debug from 'debug';
2-
import assert from 'assert';
3-
import { Client, claimedCredentials } from 'taskcluster-lib-pulse';
42
import { slugid } from 'taskcluster-client';
53
import { serialize } from 'async-decorators';
64
import PulseIterator from './PulseIterator';
@@ -106,51 +104,18 @@ export default class PulseEngine {
106104
* connection recycles, and rely on the caller to re-subscribe on service
107105
* restart. */
108106

109-
constructor({
110-
monitor,
111-
rootUrl,
112-
credentials,
113-
namespace,
114-
contact,
115-
expiresAfter,
116-
}) {
107+
constructor({ monitor, pulseClient }) {
117108
this.monitor = monitor;
118109
this.subscriptions = new Map();
119110

120-
if (process.env.NODE_ENV === 'production') {
121-
assert(namespace, 'namespace is required');
122-
assert(
123-
credentials && credentials.clientId && credentials.accessToken,
124-
'credentials are required'
125-
);
126-
} else if (
127-
!namespace ||
128-
!credentials ||
129-
!credentials.clientId ||
130-
!credentials.accessToken
131-
) {
132-
debug(
133-
'NOTE: pulse.namespace or taskcluster.credentials not set; no subscription messages will be recieved'
134-
);
111+
this.client = pulseClient;
135112

136-
// bail out of setup; this.connected will never be called, so no
137-
// subscriptions will ever return messages, but subscription requests
138-
// will succeed.
113+
if (this.client.isFakeClient) {
114+
// we are now set up to accept subscription requests, but won't do
115+
// anything with them.
139116
return;
140117
}
141118

142-
this.client = new Client({
143-
monitor,
144-
namespace,
145-
credentials: claimedCredentials({
146-
rootUrl,
147-
credentials,
148-
namespace,
149-
contact,
150-
expiresAfter,
151-
}),
152-
});
153-
154119
this.reset();
155120
this.client.onConnected(conn => this.connected(conn));
156121
}

services/web-server/src/index.js

+27-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import loader from 'taskcluster-lib-loader';
55
import config from 'typed-env-config';
66
import monitor from 'taskcluster-lib-monitor';
77
import { createServer as httpServer } from 'http';
8+
import { FakeClient, Client, pulseCredentials } from 'taskcluster-lib-pulse';
89
import createApp from './servers/createApp';
910
import createContext from './createContext';
1011
import createSchema from './createSchema';
@@ -43,12 +44,34 @@ const load = loader(
4344
}),
4445
},
4546

46-
pulseEngine: {
47+
pulseClient: {
4748
requires: ['cfg', 'monitor'],
48-
setup: ({ cfg, monitor }) =>
49+
setup: ({ cfg, monitor }) => {
50+
if (!cfg.pulse.namespace) {
51+
assert(
52+
process.env.NODE_ENV !== 'production',
53+
'cfg.pulse.namespace is required'
54+
);
55+
// eslint-disable-next-line no-console
56+
console.log(
57+
`\n\nNo Pulse namespace defined; no Pulse messages will be received.`
58+
);
59+
return new FakeClient();
60+
}
61+
62+
return new Client({
63+
monitor,
64+
namespace: cfg.pulse.namespace,
65+
credentials: pulseCredentials(cfg.pulse),
66+
});
67+
},
68+
},
69+
70+
pulseEngine: {
71+
requires: ['pulseClient', 'monitor'],
72+
setup: ({ pulseClient, monitor }) =>
4973
new PulseEngine({
50-
...cfg.taskcluster,
51-
...cfg.pulse,
74+
pulseClient,
5275
monitor,
5376
}),
5477
},
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
defaults:
22
taskcluster:
33
rootUrl: ...
4-
# only set this if you want to receive pulse messages; see the README
5-
#pulse:
6-
#namespace:
4+
pulse:
5+
namespace:
6+
username: ..
7+
password: ..
8+
hostname: ..
9+
vhost: ..

0 commit comments

Comments
 (0)