-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkafka.js
97 lines (81 loc) · 2.07 KB
/
kafka.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const name = 'kafka';
const pkgs = [
'debug',
'elytron',
'underscore',
];
let error;
let produce;
const next = () => {
log = require('debug')(`${name}:log`);
error = require('debug')(`${name}:error`);
produce = require('elytron').produce;
};
const render_input = (values = {}) => {
const html = `
<p>This harbor submits manifests to a Kafka broker.</p>
<label><h5>Kafka Broker Connection String:</h5>
<input
type=text
name=kafka-broker-connection-string
placeholder="kafka1,kafka2,kafka3 (etc., comma separated)"
required
value="${values['kafka-broker-connection-string'] || ''}"
>
</label>
<label><h5>Topic:</h5>
<input
type=text
name=kafka-topic
placeholder="Example-Topic_Name.1 (alphanum, dash, underscore, dot)"
required
value="${values['kafka-topic'] || ''}"
>
</label>
`;
return html;
};
const render_work_preview = (manifest) => {
return `
<figure>
<figcaption>
A message will be produced to <code>${
manifest['kafka-broker-connection-string']
}</code>
on topic <code>${
manifest['kafka-topic']
}</code>.
</figcaption>
</figure>
`;
};
const register = () => ({ name, pkgs });
const update = (lane, values) => {
if (! check_topic(values['kafka-topic'])) {
error(`Invalid values passed for harbormaster-kafka config: ${values}`);
return false;
}
return true;
};
const check_topic = (topic_name) => {
const allowed_characters = /[a-z0-9_\.-]/gi;
const results = topic_name.match(allowed_characters);
return results.length == topic_name.length;
};
const work = (lane, manifest) => {
const topic = manifest['kafka-topic'];
const brokers = manifest['kafka-broker-connection-string'];
let exit_code = 1;
produce(topic, manifest, null, $H.bindEnvironment((code) => {
exit_code = code;
$H.end_shipment(lane, exit_code, manifest);
}), brokers);
};
module.exports = {
render_input,
render_work_preview,
register,
update,
work,
next,
};