1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | import { logger } from "@atomist/automation-client";
|
18 | import {
|
19 | ArtifactStore,
|
20 | DeployableArtifact,
|
21 | StoredArtifact,
|
22 | } from "@atomist/sdm";
|
23 | import { AppInfo } from "@atomist/sdm/lib/spi/deploy/Deployment";
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | export class EphemeralLocalArtifactStore implements ArtifactStore {
|
36 |
|
37 | private readonly entries: Array<StoredArtifact & { url: string }> = [];
|
38 |
|
39 | public async storeFile(appInfo: AppInfo, what: string): Promise<string> {
|
40 | const entry = {
|
41 | appInfo,
|
42 | deploymentUnitUrl: "http://" + what,
|
43 | url: `http://${what}/x`,
|
44 | };
|
45 | this.entries.push(entry);
|
46 | logger.info("EphemeralLocalArtifactStore: storing %j at %s", appInfo, entry.url);
|
47 | return entry.url;
|
48 | }
|
49 |
|
50 | protected async retrieve(url: string): Promise<StoredArtifact> {
|
51 | return this.entries.find(e => e.url === url);
|
52 | }
|
53 |
|
54 | public async checkout(url: string): Promise<DeployableArtifact> {
|
55 | const storedArtifact = await this.retrieve(url);
|
56 | if (!storedArtifact) {
|
57 | logger.error("No stored artifact for [%s]: Known=%s", url,
|
58 | this.entries.map(e => e.url).join(","));
|
59 | return Promise.reject(new Error("No artifact found"));
|
60 | }
|
61 |
|
62 | const local: DeployableArtifact = {
|
63 | ...storedArtifact.appInfo,
|
64 | ...parseUrl(storedArtifact.deploymentUnitUrl),
|
65 | };
|
66 | logger.info("EphemeralLocalArtifactStore: checking out %s at %j", url, local);
|
67 | return local;
|
68 | }
|
69 | }
|
70 |
|
71 | function parseUrl(targetUrl: string): { cwd: string, filename: string } {
|
72 |
|
73 | const lastSlash = targetUrl.lastIndexOf("/");
|
74 | const filename = targetUrl.substr(lastSlash + 1);
|
75 | const cwd = targetUrl.substring(7, lastSlash);
|
76 |
|
77 | logger.debug("Parsing results: url [%s]\n filename [%s]\n cwd [%s]", targetUrl, filename, cwd);
|
78 |
|
79 | return { cwd, filename };
|
80 | }
|