From 6e97a7d83c2b7c406f6c5a3735cf8a46ae76601b Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Wed, 14 Aug 2019 23:21:54 +0200 Subject: [PATCH] fix(core): update --- ts/docker.classes.container.ts | 39 +++++++++++++++++----------------- ts/docker.classes.host.ts | 38 +++++++++++++++++---------------- ts/docker.classes.network.ts | 39 +++++++++++++++++++++++++++++++++- ts/interfaces/container.ts | 2 +- 4 files changed, 78 insertions(+), 40 deletions(-) diff --git a/ts/docker.classes.container.ts b/ts/docker.classes.container.ts index 2ab3852..7f7de53 100644 --- a/ts/docker.classes.container.ts +++ b/ts/docker.classes.container.ts @@ -4,9 +4,7 @@ import * as interfaces from './interfaces'; import { DockerHost } from './docker.classes.host'; export class DockerContainer { - // ====== // STATIC - // ====== /** * get all containers @@ -26,35 +24,36 @@ export class DockerContainer { * gets an container by Id * @param containerId */ - public static async getContainerById(containerId: string) {} + public static async getContainerById(containerId: string) { + // TODO: implement get container by id + } /** * create a container */ - public static async create(creationSpecifier: interfaces.IContainerCreationSpecifier) {} + public static async create(dockerHost: DockerHost, containerCreationDescriptor: interfaces.IContainerCreationDescriptor) { + // TODO implement creating a container + } - // ======== // INSTANCE - // ======== - constructor(dockerContainerObjectArg: any) { Object.keys(dockerContainerObjectArg).forEach(keyArg => { this[keyArg] = dockerContainerObjectArg[keyArg]; }); } - Id: string; - Names: string[]; - Image: string; - ImageID: string; - Command: string; - Created: number; - Ports: interfaces.TPorts; - Labels: interfaces.TLabels; - State: string; - Status: string; - HostConfig: any; - NetworkSettings: { + public Id: string; + public Names: string[]; + public Image: string; + public ImageID: string; + public Command: string; + public Created: number; + public Ports: interfaces.TPorts; + public Labels: interfaces.TLabels; + public State: string; + public Status: string; + public HostConfig: any; + public NetworkSettings: { Networks: { [key: string]: { IPAMConfig: any; @@ -73,5 +72,5 @@ export class DockerContainer { }; }; }; - Mounts: any; + public Mounts: any; } diff --git a/ts/docker.classes.host.ts b/ts/docker.classes.host.ts index 133cede..6f82d05 100644 --- a/ts/docker.classes.host.ts +++ b/ts/docker.classes.host.ts @@ -1,23 +1,19 @@ import * as plugins from './dockersock.plugins'; import { DockerContainer } from './docker.classes.container'; +import { DockerNetwork } from './docker.classes.network'; export class DockerHost { /** * the path where the docker sock can be found */ - sockPath: string; - - /** - * keeping track of currently active requests to safely end this module at any time - */ - requestObjectmap = new plugins.lik.Objectmap(); + public socketPath: string; /** * the constructor to instantiate a new docker sock instance * @param pathArg */ constructor(pathArg: string = 'http://unix:/var/run/docker.sock:') { - this.sockPath = pathArg; + this.socketPath = pathArg; } /** @@ -25,21 +21,27 @@ export class DockerHost { * @param userArg * @param passArg */ - auth(registryArg: string, userArg: string, passArg: string) { - let done = plugins.smartpromise.defer(); - this.request('POST', ''); - return done.promise; + public async auth(registryArg: string, userArg: string, passArg: string) { + // TODO: implement Docker Registry authentication + await this.request('POST', ''); } /** - * + * gets all networks */ - async getContainers() { + public async getNetworks() { + DockerNetwork.getNetworks(this); + } + + /** + * gets all containers + */ + public async getContainers() { const containerArray = await DockerContainer.getContainers(this); return containerArray; } - async getEventObservable(): Promise> { + public async getEventObservable(): Promise> { const response = await this.requestStreaming('GET', '/events'); return plugins.rxjs.Observable.create(observer => { response.on('data', data => { @@ -60,8 +62,8 @@ export class DockerHost { /** * fire a request */ - async request(methodArg: string, routeArg: string, dataArg = {}) { - const requestUrl = `${this.sockPath}${routeArg}`; + public async request(methodArg: string, routeArg: string, dataArg = {}) { + const requestUrl = `${this.socketPath}${routeArg}`; const response = await plugins.smartrequest.request(requestUrl, { method: methodArg, headers: { @@ -73,8 +75,8 @@ export class DockerHost { return response; } - async requestStreaming(methodArg: string, routeArg: string, dataArg = {}) { - const requestUrl = `${this.sockPath}${routeArg}`; + public async requestStreaming(methodArg: string, routeArg: string, dataArg = {}) { + const requestUrl = `${this.socketPath}${routeArg}`; const response = await plugins.smartrequest.request( requestUrl, { diff --git a/ts/docker.classes.network.ts b/ts/docker.classes.network.ts index 33457fd..3abfce9 100644 --- a/ts/docker.classes.network.ts +++ b/ts/docker.classes.network.ts @@ -3,4 +3,41 @@ import * as interfaces from './interfaces'; import { DockerHost } from './docker.classes.host'; -export class DockerNetwork {} +export class DockerNetwork { + public static async getNetworks(dockerHost: DockerHost): Promise { + const dockerNetworks: DockerNetwork[] = []; + return dockerNetworks; + } + + public static async createNetwork(dockerHost: DockerHost, networkCreationDescriptor) { + // TODO: implement create network + } + + constructor(dockerNetworkObjectArg: any) { + Object.keys(dockerNetworkObjectArg).forEach(keyArg => { + this[keyArg] = dockerNetworkObjectArg[keyArg]; + }); + } + + public Name: string; + public Id: string; + public Created: string; + public Scope: string; + public Driver: string; + public EnableIPv6: boolean; + public Internal: boolean; + public Attachable: boolean; + public Ingress: false; + public IPAM: { + Driver: "default" | "bridge" | "overlay", + Config: [ + { + Subnet: string, + IPRange: string, + Gateway: string + } + ] + }; + + +} diff --git a/ts/interfaces/container.ts b/ts/interfaces/container.ts index 2368b0a..013978b 100644 --- a/ts/interfaces/container.ts +++ b/ts/interfaces/container.ts @@ -1,6 +1,6 @@ import { DockerNetwork } from '../docker.classes.network'; -export interface IContainerCreationSpecifier { +export interface IContainerCreationDescriptor { hostname: string; domainName: string; networks?: DockerNetwork[];