-
Notifications
You must be signed in to change notification settings - Fork 0
/
playground.ts
73 lines (65 loc) · 2.21 KB
/
playground.ts
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
import { readFileSync } from 'node:fs'
import { load } from 'js-yaml'
import type { ServiceSpec } from './src/index.ts'
import { ApiError, Docker } from './src/index.ts'
import { getQueryString } from './src/schema/core/request.ts';
const docker = new Docker()
interface Filters {
dangling?: boolean
driver?: string
label?: string | Record<string, string>
name?: string
}
// Function to convert the Filters object to a JSON-encoded string
function encodeFilters(filters: Record<string, string>): string {
const filterStrings: string[] = []
for (const key in filters) {
if (filters.hasOwnProperty(key)) {
const value = filters[key]
if (value)
filterStrings.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
}
}
return filterStrings.join('&')
}
try {
const filters = { name: 'project_default' }
const encodedFilters = encodeURIComponent(JSON.stringify(filters))
const string = getQueryString({name:'project_default'})
const networks = await docker.networks.networkList()
console.log( networks)
}
catch (error) {
if (error instanceof ApiError)
console.error('API Error:', error.message)
else
console.error('An unexpected error occurred:', error)
}
// const filters = JSON.stringify({ name: "project_default"} as Filters);
// const res = await docker.networks.networkList()
// const res = await docker.networks.networkCreate({Name: 'project_default', 'CheckDuplicate':true})
// const res = await docker.secrets.secretCreate({
// Name: 'app-key.crt',
// Labels: {
// 'com.example.some-label': 'some-value',
// 'com.example.some-other-label': 'some-other-value',
// 'foo': 'bar',
// },
// Data: 'VEhJUyBJUyBOT1QgQSBSRUFMIENFUlRJRklDQVRFCg==',
// Driver: {
// Name: 'secret-bucket',
// Options: {
// OptionA: 'value for driver option A',
// OptionB: 'value for driver option B',
// },
// },
// Templating: {
// Name: 'some-driver',
// Options: {
// OptionA: 'value for driver-specific option A',
// OptionB: 'value for driver-specific option B',
// },
// },
// })
// const res = await docker.images.imageInspect('sha256:ab6510b890a4b32cfb12d620d4f6b301f48ba3958cbc802ccc226b386e209988')
// console.log(res)