fix(core): update
This commit is contained in:
parent
21e6fff3fb
commit
684185e951
11
scripts/testauth.ts
Normal file
11
scripts/testauth.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import * as docker from '../ts';
|
||||||
|
import * as smartstring from '@pushrocks/smartstring';
|
||||||
|
|
||||||
|
const run = async () => {
|
||||||
|
const dockerHost = new docker.DockerHost();
|
||||||
|
await docker.DockerImage.createFromRegistry(dockerHost, {
|
||||||
|
imageUrl: 'registry.gitlab.com/servezone/private/cloudly:latest'
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
run();
|
@ -3,6 +3,12 @@ import { DockerContainer } from './docker.classes.container';
|
|||||||
import { DockerNetwork } from './docker.classes.network';
|
import { DockerNetwork } from './docker.classes.network';
|
||||||
import { DockerService } from './docker.classes.service';
|
import { DockerService } from './docker.classes.service';
|
||||||
|
|
||||||
|
export interface IAuthData {
|
||||||
|
serveraddress: string;
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class DockerHost {
|
export class DockerHost {
|
||||||
/**
|
/**
|
||||||
* the path where the docker sock can be found
|
* the path where the docker sock can be found
|
||||||
@ -31,26 +37,16 @@ export class DockerHost {
|
|||||||
* @param userArg
|
* @param userArg
|
||||||
* @param passArg
|
* @param passArg
|
||||||
*/
|
*/
|
||||||
public async auth(registryUrl: string, userArg: string, passArg: string) {
|
public async auth(authData: IAuthData) {
|
||||||
const response = await this.request('POST', '/auth', {
|
const response = await this.request('POST', '/auth', authData);
|
||||||
serveraddress: registryUrl,
|
|
||||||
username: userArg,
|
|
||||||
password: passArg
|
|
||||||
});
|
|
||||||
if (response.body.Status !== 'Login Succeeded') {
|
if (response.body.Status !== 'Login Succeeded') {
|
||||||
console.log(`Login failed with ${response.body.Status}`);
|
console.log(`Login failed with ${response.body.Status}`);
|
||||||
throw new Error(response.body.Status);
|
throw new Error(response.body.Status);
|
||||||
}
|
}
|
||||||
console.log(response.body.Status);
|
console.log(response.body.Status);
|
||||||
this.registryToken = plugins.smartstring.base64.encode(response.body.IdentityToken);
|
this.registryToken = plugins.smartstring.base64.encode(
|
||||||
}
|
plugins.smartjson.Smartjson.stringify(authData, {})
|
||||||
|
);
|
||||||
/**
|
|
||||||
* sets an auth token
|
|
||||||
* @param authToken
|
|
||||||
*/
|
|
||||||
public setAuthToken(authToken: string) {
|
|
||||||
this.registryToken = authToken;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,7 +55,14 @@ export class DockerHost {
|
|||||||
public async getGitlabComTokenFromDockerConfig() {
|
public async getGitlabComTokenFromDockerConfig() {
|
||||||
const dockerConfigPath = plugins.smartpath.get.home('~/.docker/config.json');
|
const dockerConfigPath = plugins.smartpath.get.home('~/.docker/config.json');
|
||||||
const configObject = plugins.smartfile.fs.toObjectSync(dockerConfigPath);
|
const configObject = plugins.smartfile.fs.toObjectSync(dockerConfigPath);
|
||||||
this.registryToken = configObject.auths['registry.gitlab.com'].auth;
|
const gitlabAuthBase64 = configObject.auths['registry.gitlab.com'].auth;
|
||||||
|
const gitlabAuth: string = plugins.smartstring.base64.decode(gitlabAuthBase64);
|
||||||
|
const gitlabAuthArray = gitlabAuth.split(':');
|
||||||
|
await this.auth({
|
||||||
|
username: gitlabAuthArray[0],
|
||||||
|
password: gitlabAuthArray[1],
|
||||||
|
serveraddress: 'registry.gitlab.com'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -170,6 +173,7 @@ export class DockerHost {
|
|||||||
method: methodArg,
|
method: methodArg,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
'X-Registry-Auth': this.registryToken,
|
||||||
Host: 'docker.sock'
|
Host: 'docker.sock'
|
||||||
},
|
},
|
||||||
requestBody: null,
|
requestBody: null,
|
||||||
|
Loading…
Reference in New Issue
Block a user