Skip to content

Commit ddc2f52

Browse files
author
Oleg Sucharevich
authored
add ability to integrate standard docker registry into codefresh
1 parent c2d9922 commit ddc2f52

File tree

8 files changed

+217
-1
lines changed

8 files changed

+217
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const Command = require('../../Command');
2+
const createRoot = require('../root/create.cmd');
3+
const yargs = require('yargs');
4+
5+
const command = new Command({
6+
command: 'registry',
7+
category: 'Registries',
8+
parent: createRoot,
9+
description: 'Integrate Container registry into Codefresh',
10+
webDocs: {
11+
category: 'Registries',
12+
title: 'Create Registry',
13+
},
14+
handler: async () => {
15+
yargs.showHelp();
16+
},
17+
});
18+
19+
module.exports = command;
20+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const _ = require('lodash');
2+
const debug = require('debug')('codefresh:cli:create:context:git:github');
3+
const Command = require('../../../Command');
4+
const CFError = require('cf-errors');
5+
const createbase = require('./../create.cmd');
6+
const {
7+
registry,
8+
} = require('../../../../../logic/index').api;
9+
10+
const command = new Command({
11+
command: 'standard <name>',
12+
parent: createbase,
13+
description: 'Integrate a standard container registry into Codefresh',
14+
webDocs: {
15+
category: 'Registries',
16+
title: 'Standard',
17+
subCategory: 'standard',
18+
weight: 10,
19+
},
20+
builder: (yargs) => {
21+
yargs
22+
.positional('name', {
23+
describe: 'Registry name',
24+
})
25+
.option('username', {
26+
describe: 'Username to access the docker registry',
27+
required: true,
28+
})
29+
.option('password', {
30+
describe: 'Password to access the docker registry',
31+
required: true,
32+
})
33+
.option('domain', {
34+
describe: 'Domain to access the docker registry',
35+
required: true,
36+
})
37+
.option('behind-firewall', {
38+
describe: 'Set if the registry is behind a firewall',
39+
default: false,
40+
type: 'boolean',
41+
});
42+
return yargs;
43+
},
44+
handler: async (argv) => {
45+
const data = _.chain(argv)
46+
.pick(['username', 'password', 'domain', 'name', 'behindFirewall'])
47+
.merge({ provider: 'other' })
48+
.value();
49+
await registry.create(data);
50+
},
51+
});
52+
53+
module.exports = command;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const debug = require('debug')('codefresh:cli:get:cluster');
2+
const Command = require('../../Command');
3+
const { registry } = require('../../../../logic').api;
4+
const Output = require('../../../../output/Output');
5+
const deleteCmd = require('../root/delete.cmd');
6+
const yargs = require('yargs');
7+
8+
const command = new Command({
9+
command: 'registry <ID>',
10+
category: 'Registries',
11+
parent: deleteCmd,
12+
description: 'Delete registry from Codefresh',
13+
webDocs: {
14+
category: 'Registries',
15+
title: 'Delete Registry',
16+
},
17+
builder: (y) => {
18+
y.positional('ID', {
19+
describe: 'ID of a registry to delete',
20+
});
21+
return y;
22+
},
23+
handler: async (argv) => {
24+
await registry.remove(argv.ID);
25+
},
26+
});
27+
28+
module.exports = command;
29+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const debug = require('debug')('codefresh:cli:get:cluster');
2+
const Command = require('../../Command');
3+
const { registry } = require('../../../../logic').api;
4+
const Output = require('../../../../output/Output');
5+
const getRoot = require('../root/get.cmd');
6+
7+
8+
const command = new Command({
9+
command: 'registry',
10+
category: 'Registries',
11+
parent: getRoot,
12+
description: 'Get an array of accounts registries',
13+
webDocs: {
14+
category: 'Registries',
15+
title: 'Get Registries',
16+
},
17+
builder: (yargs) => {
18+
return yargs
19+
.example('codefresh get registry', 'Get all registries connected to the account');
20+
},
21+
handler: async (argv) => {
22+
const registries = await registry.list();
23+
Output.print(registries);
24+
},
25+
});
26+
27+
module.exports = command;
28+

lib/logic/api/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const section = require('./section');
1616
const cluster = require('./cluster');
1717
const repository = require('./repository');
1818
const token = require('./token');
19+
const registry = require('./registry');
1920

2021
module.exports = {
2122
user,
@@ -36,4 +37,5 @@ module.exports = {
3637
cluster,
3738
repository,
3839
token,
40+
registry,
3941
};

lib/logic/api/registry.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const _ = require('lodash');
2+
const { sendHttpRequest } = require('./helper');
3+
const Registry = require('../entities/Registry');
4+
5+
const BASE_API_URL = '/api/registries';
6+
7+
const _extractFieldsForContextEntity = ref => ({
8+
provider: ref.provider,
9+
name: ref.name,
10+
kind: ref.kind,
11+
_id: ref._id,
12+
behindFirewall: ref.behindFirewall,
13+
default: ref.default,
14+
});
15+
16+
async function _test(opt) {
17+
if (opt.behindFirewall) {
18+
return Promise.resolve();
19+
}
20+
return sendHttpRequest({
21+
url: `${BASE_API_URL}/test/`,
22+
method: 'POST',
23+
body: opt,
24+
});
25+
}
26+
27+
async function list() {
28+
const res = await sendHttpRequest({
29+
url: BASE_API_URL,
30+
});
31+
return _.chain(res)
32+
.map(_extractFieldsForContextEntity)
33+
.map(data => new Registry(data))
34+
.value();
35+
}
36+
37+
38+
async function create(opt = {}) {
39+
await _test(opt);
40+
const res = await sendHttpRequest({
41+
url: BASE_API_URL,
42+
method: 'POST',
43+
body: opt,
44+
});
45+
return res;
46+
}
47+
48+
async function remove(id) {
49+
const res = await sendHttpRequest({
50+
url: `${BASE_API_URL}/${id}`,
51+
method: 'DELETE',
52+
});
53+
return res;
54+
}
55+
56+
module.exports = {
57+
list,
58+
create,
59+
remove,
60+
};

lib/logic/entities/Registry.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const Entity = require('./Entity');
2+
const _ = require('lodash'); // eslint-disable-line
3+
4+
class Registry extends Entity {
5+
constructor(data) {
6+
super();
7+
this.entityType = 'registry';
8+
this.info = data;
9+
this.name = this.info.name;
10+
this.kind = this.info.kind;
11+
this.id = this.info._id;
12+
this.behindFirewall = this.info.behindFirewall;
13+
this.default = this.info.default;
14+
this.provider = this.info.provider;
15+
this.defaultColumns = ['id', 'provider', 'name', 'kind', 'behindFirewall', 'default'];
16+
this.wideColumns = this.defaultColumns || [];
17+
}
18+
19+
getType() {
20+
return this.type;
21+
}
22+
}
23+
24+
module.exports = Registry;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.13.5",
3+
"version": "0.14.0",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)