Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import React from 'react';
import ReactDOM from 'react-dom';
import TaskCreator from './taskcreator';
import Layout from '../lib/Layout';
import {fromNow} from 'taskcluster-client';
// Initial task, if nothing is stored in localStorage
const initialTask = {
provisionerId: 'aws-provisioner-v1',
workerType: 'tutorial',
created: fromNow('0 seconds'),
deadline: fromNow('1 day'),
payload: {
image: 'ubuntu:13.10',
command: ['/bin/bash', '-c', 'echo "hello World"'],
maxRunTime: 60 * 10,
},
metadata: {
name: 'Example Task',
description: 'Markdown description of **what** this task does',
owner: 'name@example.com',
source: 'https://tools.taskcluster.net/task-creator/',
},
};
ReactDOM.render((
generate: ({ rootUrl, key, exp, sub, ...rest }) => {
assert(key, `jwt.generate requires a key`);
const now = taskcluster.fromNow();
const payload = {
// If the current time is greater than the exp, the JWT is invalid
// https://github.com/auth0/node-jsonwebtoken#token-expiration-exp-claim
exp,
// If the current time is less than the nbf, the JWT is invalid
nbf: Math.floor(now.getTime() / 1000),
aud: rootUrl,
iss: rootUrl,
sub,
...rest,
};
const token = jwt.sign(payload, key, { algorithm: 'HS256' });
return {
token,
expires: new Date(exp * 1000),
load() {
// If there is no currentSecretId, we're creating a new secret
if (this.props.currentSecretId === '') {
return {
secretId: '',
secret: {
secret: {},
expires: taskcluster.fromNow('1 day'),
},
editing: true,
working: false,
error: null,
};
} else {
// Load currentSecretId
return {
secretId: this.props.currentSecretId,
secret: this.secrets.get(this.props.currentSecretId),
editing: false,
working: false,
error: null,
showSecret: false
};
}
await Promise.all([
(async () => {
await artifactStore.createContainer();
await artifactStore.setupCORS();
})(),
Artifact.ensureTable(),
publicArtifactBucket.setupCORS(),
privateArtifactBucket.setupCORS()
]);
// Notify parent process, so that this worker can run using LocalApp
base.app.notifyLocalAppInParentProcess();
// Find an artifact expiration delay
var delay = cfg.get('queue:artifactExpirationDelay');
var now = taskcluster.fromNow(delay);
assert(!_.isNaN(now), "Can't have NaN as now");
// Expire artifacts using delay
debug("Expiring artifacts at: %s, from before %s", new Date(), now);
var count = await Artifact.expire(now);
debug("Expired %s artifacts", count);
// Stop recording statistics and send any stats that we have
base.stats.stopProcessUsageReporting();
return influx.close();
};
debug(
'Failed to list keys for %s (will create project), err: %s, stack: %s',
project, err, err.stack
);
// Ignore error try to create the project, and list keys again.
await this._sentry.teams.createProject(
this._organization, this._initialTeam, {
name: project,
slug: project,
});
keys = await this._sentry.projects.keys(this._organization, project);
}
// Create new key if most recent key is too old
key = _.last(parseKeys(keys, this._keyPrefix)); // last is most recent
if (!key || key.expires < taskcluster.fromNow('25 hours')) {
// Create new key that expires in 48 hours
let expires = taskcluster.fromNow('48 hours');
let k = await this._sentry.projects.createKey(
this._organization, project, {
name: this._keyPrefix + ` managed (expires-at:${expires.toJSON()})`,
});
key = {
id: k.id,
dsn: k.dsn,
expires,
};
}
// Save to cache and return
return this._projectDSNCache[project] = key;
}
debug(`rejecting access to ${body.resource} by ${clientId}`);
return {status: 'auth-failed', message: `client ${clientId} not configured in fakeauth`};
}
if (ext.authorizedScopes) {
scopes = ext.authorizedScopes;
from = 'ext.authorizedScopes';
} else if (ext.certificate && ext.certificate.scopes) {
scopes = ext.certificate.scopes;
from = 'ext.certificate.scopes';
}
debug('authenticating access to ' + body.resource +
' by ' + clientId +
' with scopes ' + scopes.join(', ') +
' from ' + from);
let expires = taskcluster.fromNow('2 minutes');
return {status: 'auth-success', scheme: 'hawk', scopes, clientId, expires};
});
};
hostnames.push(`${workerPoolId}-${slugid.nice().replace(/_/g, '-').toLowerCase()}`);
}
const workerId = slugid.nice().replace(/_/g, '-').toLowerCase();
const workerGroup = this.providerId;
const credentials = taskcluster.createTemporaryCredentials({
clientId: `worker/packet/${this.projectId}/${workerGroup}/${workerId}`,
scopes: [
`assume:worker-type:${workerPoolId}`,
`assume:worker-id:${workerGroup}/${workerId}`,
`queue:worker-id:${workerGroup}/${workerId}`,
`secrets:get:worker-type:${workerPoolId}`,
`queue:claim-work:${workerPoolId}`,
],
start: taskcluster.fromNow('-15 minutes'),
expiry: taskcluster.fromNow('96 hours'),
credentials: this.taskclusterCredentials,
});
const resp = await this.packet.createSpotRequestAsync(this.projectId, {
instance_parameters: {
billing_cycle: config.billingCyle,
hostnames,
operating_system: config.operatingSystem,
plan: config.plan,
ip_addresses: config.ipAddresses,
end_at: taskcluster.fromNow('1 month'),
userdata: [
'#cloud-config',
`#image_repo=${config.imageRepo}`,
`#image_tag=${config.imageTag}`,
return monitor.oneShot(ownName, async () => {
const now = taskcluster.fromNow(cfg.app.cachePurgeExpirationDelay);
debug('Expiring cache-purges at: %s, from before %s', new Date(), now);
const count = await CachePurge.expire(now);
debug('Expired %s cache-purges', count);
});
},
await cb.modify(cachePurge => {
cachePurge.before = new Date();
cachePurge.expires = taskcluster.fromNow('1 day');
});
}
return monitor.oneShot(ownName, async () => {
const now = taskcluster.fromNow(cfg.app.sentryExpirationDelay);
debug('Expiring sentry keys');
await sentryManager.purgeExpiredKeys(now);
debug('Expired sentry keys');
});
},