forked from snxraven/peardock
Expose ttl.sh in Flatten and Push Image target lists with TTL presets, auto-retag to ttl.sh/name:duration, and skip vault auth for public temp pushes.
48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
/**
|
|
* ttl.sh ephemeral registry helpers.
|
|
*/
|
|
import test from 'brittle'
|
|
import {
|
|
TTL_SH_SELECT_VALUE,
|
|
TTL_SH_DEFAULT_TTL,
|
|
isTtlShSelectValue,
|
|
isValidTtlShDuration,
|
|
stripRegistryPrefix,
|
|
ttlShRepoFromName,
|
|
credentialIdFromSelect,
|
|
} from '../libs/registryManager.js'
|
|
|
|
test('ttl.sh select sentinel', (t) => {
|
|
t.is(TTL_SH_SELECT_VALUE, '__ttl_sh__')
|
|
t.ok(isTtlShSelectValue(TTL_SH_SELECT_VALUE))
|
|
t.absent(isTtlShSelectValue(''))
|
|
t.absent(isTtlShSelectValue('abc123'))
|
|
t.is(credentialIdFromSelect(TTL_SH_SELECT_VALUE), undefined)
|
|
t.is(credentialIdFromSelect(''), undefined)
|
|
t.is(credentialIdFromSelect('vault-id'), 'vault-id')
|
|
})
|
|
|
|
test('isValidTtlShDuration accepts presets and rejects junk', (t) => {
|
|
t.ok(isValidTtlShDuration('5m'))
|
|
t.ok(isValidTtlShDuration('1h'))
|
|
t.ok(isValidTtlShDuration('24h'))
|
|
t.ok(isValidTtlShDuration(TTL_SH_DEFAULT_TTL))
|
|
t.absent(isValidTtlShDuration('latest'))
|
|
t.absent(isValidTtlShDuration('25h'))
|
|
t.absent(isValidTtlShDuration(''))
|
|
t.absent(isValidTtlShDuration('1d'))
|
|
})
|
|
|
|
test('ttlShRepoFromName builds ttl.sh paths', (t) => {
|
|
t.is(ttlShRepoFromName('apache-httpd'), 'ttl.sh/apache-httpd')
|
|
t.is(ttlShRepoFromName('ttl.sh/apache-httpd'), 'ttl.sh/apache-httpd')
|
|
t.is(ttlShRepoFromName('192.168.0.12:5555/myapp'), 'ttl.sh/myapp')
|
|
t.is(ttlShRepoFromName('ghcr.io/org/app'), 'ttl.sh/org/app')
|
|
})
|
|
|
|
test('stripRegistryPrefix', (t) => {
|
|
t.is(stripRegistryPrefix('ttl.sh/foo'), 'foo')
|
|
t.is(stripRegistryPrefix('localhost:5000/bar'), 'bar')
|
|
t.is(stripRegistryPrefix('simple'), 'simple')
|
|
})
|