fix(core): update

This commit is contained in:
Philipp Kunz 2019-08-14 23:21:54 +02:00
parent 04bb3b9ed0
commit 6e97a7d83c
4 changed files with 78 additions and 40 deletions

View File

@ -4,9 +4,7 @@ import * as interfaces from './interfaces';
import { DockerHost } from './docker.classes.host'; import { DockerHost } from './docker.classes.host';
export class DockerContainer { export class DockerContainer {
// ======
// STATIC // STATIC
// ======
/** /**
* get all containers * get all containers
@ -26,35 +24,36 @@ export class DockerContainer {
* gets an container by Id * gets an container by Id
* @param containerId * @param containerId
*/ */
public static async getContainerById(containerId: string) {} public static async getContainerById(containerId: string) {
// TODO: implement get container by id
}
/** /**
* create a container * 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 // INSTANCE
// ========
constructor(dockerContainerObjectArg: any) { constructor(dockerContainerObjectArg: any) {
Object.keys(dockerContainerObjectArg).forEach(keyArg => { Object.keys(dockerContainerObjectArg).forEach(keyArg => {
this[keyArg] = dockerContainerObjectArg[keyArg]; this[keyArg] = dockerContainerObjectArg[keyArg];
}); });
} }
Id: string; public Id: string;
Names: string[]; public Names: string[];
Image: string; public Image: string;
ImageID: string; public ImageID: string;
Command: string; public Command: string;
Created: number; public Created: number;
Ports: interfaces.TPorts; public Ports: interfaces.TPorts;
Labels: interfaces.TLabels; public Labels: interfaces.TLabels;
State: string; public State: string;
Status: string; public Status: string;
HostConfig: any; public HostConfig: any;
NetworkSettings: { public NetworkSettings: {
Networks: { Networks: {
[key: string]: { [key: string]: {
IPAMConfig: any; IPAMConfig: any;
@ -73,5 +72,5 @@ export class DockerContainer {
}; };
}; };
}; };
Mounts: any; public Mounts: any;
} }

View File

@ -1,23 +1,19 @@
import * as plugins from './dockersock.plugins'; import * as plugins from './dockersock.plugins';
import { DockerContainer } from './docker.classes.container'; import { DockerContainer } from './docker.classes.container';
import { DockerNetwork } from './docker.classes.network';
export class DockerHost { export class DockerHost {
/** /**
* the path where the docker sock can be found * the path where the docker sock can be found
*/ */
sockPath: string; public socketPath: string;
/**
* keeping track of currently active requests to safely end this module at any time
*/
requestObjectmap = new plugins.lik.Objectmap<any>();
/** /**
* the constructor to instantiate a new docker sock instance * the constructor to instantiate a new docker sock instance
* @param pathArg * @param pathArg
*/ */
constructor(pathArg: string = 'http://unix:/var/run/docker.sock:') { 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 userArg
* @param passArg * @param passArg
*/ */
auth(registryArg: string, userArg: string, passArg: string) { public async auth(registryArg: string, userArg: string, passArg: string) {
let done = plugins.smartpromise.defer(); // TODO: implement Docker Registry authentication
this.request('POST', ''); await this.request('POST', '');
return done.promise;
} }
/** /**
* * gets all networks
*/ */
async getContainers() { public async getNetworks() {
DockerNetwork.getNetworks(this);
}
/**
* gets all containers
*/
public async getContainers() {
const containerArray = await DockerContainer.getContainers(this); const containerArray = await DockerContainer.getContainers(this);
return containerArray; return containerArray;
} }
async getEventObservable(): Promise<plugins.rxjs.Observable<any>> { public async getEventObservable(): Promise<plugins.rxjs.Observable<any>> {
const response = await this.requestStreaming('GET', '/events'); const response = await this.requestStreaming('GET', '/events');
return plugins.rxjs.Observable.create(observer => { return plugins.rxjs.Observable.create(observer => {
response.on('data', data => { response.on('data', data => {
@ -60,8 +62,8 @@ export class DockerHost {
/** /**
* fire a request * fire a request
*/ */
async request(methodArg: string, routeArg: string, dataArg = {}) { public async request(methodArg: string, routeArg: string, dataArg = {}) {
const requestUrl = `${this.sockPath}${routeArg}`; const requestUrl = `${this.socketPath}${routeArg}`;
const response = await plugins.smartrequest.request(requestUrl, { const response = await plugins.smartrequest.request(requestUrl, {
method: methodArg, method: methodArg,
headers: { headers: {
@ -73,8 +75,8 @@ export class DockerHost {
return response; return response;
} }
async requestStreaming(methodArg: string, routeArg: string, dataArg = {}) { public async requestStreaming(methodArg: string, routeArg: string, dataArg = {}) {
const requestUrl = `${this.sockPath}${routeArg}`; const requestUrl = `${this.socketPath}${routeArg}`;
const response = await plugins.smartrequest.request( const response = await plugins.smartrequest.request(
requestUrl, requestUrl,
{ {

View File

@ -3,4 +3,41 @@ import * as interfaces from './interfaces';
import { DockerHost } from './docker.classes.host'; import { DockerHost } from './docker.classes.host';
export class DockerNetwork {} export class DockerNetwork {
public static async getNetworks(dockerHost: DockerHost): Promise<DockerNetwork[]> {
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
}
]
};
}

View File

@ -1,6 +1,6 @@
import { DockerNetwork } from '../docker.classes.network'; import { DockerNetwork } from '../docker.classes.network';
export interface IContainerCreationSpecifier { export interface IContainerCreationDescriptor {
hostname: string; hostname: string;
domainName: string; domainName: string;
networks?: DockerNetwork[]; networks?: DockerNetwork[];