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';
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;
}

View File

@ -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<any>();
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<plugins.rxjs.Observable<any>> {
public async getEventObservable(): Promise<plugins.rxjs.Observable<any>> {
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,
{

View File

@ -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<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';
export interface IContainerCreationSpecifier {
export interface IContainerCreationDescriptor {
hostname: string;
domainName: string;
networks?: DockerNetwork[];