44 lines
1.9 KiB
JavaScript
44 lines
1.9 KiB
JavaScript
|
|
const ClusterDownloadSet = {
|
||
|
|
props: [ 'cluster', 'token', 'state' ],
|
||
|
|
data() {
|
||
|
|
return {
|
||
|
|
signReqValidity: "1d",
|
||
|
|
downloadSet: null,
|
||
|
|
};
|
||
|
|
},
|
||
|
|
methods: {
|
||
|
|
generateDownloadSet() {
|
||
|
|
event.preventDefault()
|
||
|
|
|
||
|
|
const hosts = (this.state.Hosts||[]).filter(h => h.Cluster == this.cluster.Name)
|
||
|
|
const items = hosts.map(h => ({
|
||
|
|
Kind: "host",
|
||
|
|
Name: h.Name,
|
||
|
|
Assets: ["kernel", "initrd", "uki", "bootstrap.tar", "boot.img.gz", "boot.img", "boot.qcow2", "boot.iso", "boot.tar", "bootstrap-config", "config", "config.json", "ipxe"],
|
||
|
|
}))
|
||
|
|
|
||
|
|
fetch('/sign-download-set', {
|
||
|
|
method: 'POST',
|
||
|
|
body: JSON.stringify({Expiry: this.signReqValidity, Items: items}),
|
||
|
|
headers: { 'Authorization': 'Bearer ' + this.token, 'Content-Type': 'application/json' },
|
||
|
|
}).then((resp) => {
|
||
|
|
if (resp.ok) {
|
||
|
|
resp.json().then((set) => { this.downloadSet = set })
|
||
|
|
} else {
|
||
|
|
resp.json().then((resp) => alert('failed to generate: '+resp.message))
|
||
|
|
}
|
||
|
|
}).catch((e) => { alert('failed to generate: '+e) })
|
||
|
|
},
|
||
|
|
},
|
||
|
|
template: `
|
||
|
|
<h3>Download set</h3>
|
||
|
|
<p>Validity: <input type="text" v-model="signReqValidity"/> <small>time range, ie: -5m:1w, 5m, 1M, 1y, 1d-1s, etc.</small></p>
|
||
|
|
<p><button @click="generateDownloadSet">Generate download set ({{ (state.Hosts||[]).filter(h => h.Cluster == cluster.Name).length }} hosts)</button></p>
|
||
|
|
<p v-if="downloadSet" style="word-break:break-all">
|
||
|
|
<a :href="'/public/download-set?set='+downloadSet" target="_blank">Open download set page</a>
|
||
|
|
<br/>
|
||
|
|
<button @click="navigator.clipboard.writeText(window.location.origin+'/public/download-set?set='+downloadSet)">Copy URL</button>
|
||
|
|
</p>
|
||
|
|
`
|
||
|
|
}
|