-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblih.js
More file actions
150 lines (126 loc) · 3.32 KB
/
Copy pathblih.js
File metadata and controls
150 lines (126 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
var crypto = require('crypto');
var request = require('request');
module.exports = class Blih {
constructor(login, password) {
this.login = login,
this.token = this.GenerateToken(password);
this.baseurl = "https://blih.epitech.eu/";
this.Repository = new Repository(this);
this.SSHKeys = new SSH(this);
}
GenerateToken(password) {
var hash = crypto.createHash('sha512');
hash = hash.update(password, 'utf8').digest('hex');
return hash;
}
Request(options, callback) {
var result = {
error: null,
}
var signature = {
user: this.login,
signature: ""
}
var hash = crypto.createHmac('sha512', this.token);
hash.update(this.login);
if (options.data !== undefined) {
hash.update(JSON.stringify(options.data, null, 4));
signature.data = options.data;
}
signature.signature = hash.digest('hex').toString();
request({
uri: this.baseurl + options.path,
method: options.method,
json: signature
}, function (error, response, body) {
if (error)
result.error = error;
if (body.error) {
result.error = body.error;
return callback(result);
}
result.body = body;
callback(result);
});
}
Whoami(callback) {
this.Request({
method: 'GET',
path: "whoami"
}, callback);
}
}
class Repository {
constructor(blih) {
this.blih = blih;
}
GetAlls(callback) {
this.blih.Request({
method: 'GET',
path: "repositories"
}, callback);
}
Get(name, callback) {
this.blih.Request({
method: 'GET',
path: "repository/" + name
}, callback);
}
Create(name, callback) {
this.blih.Request({
method: "POST",
path: "repositories",
data: {
name: repository,
type: "git"
}
}, callback)
}
Delete(name, callback) {
this.blih.Request({
method: "DELETE",
path: "repository/" + name
}, callback)
}
GetACLs(repository, callback) {
this.blih.Request({
method: "GET",
path: "repository/" + repository + "/acls"
}, callback)
}
SetACL(repository, username, rights, callback) {
this.blih.Request({
method: "DELETE",
path: "repository/" + repository + "/acls",
data: {
acl: rights, user: username
}
}, callback)
}
}
class SSH {
constructor(blih) {
this.blih = blih;
}
GetAlls(callback) {
this.blih.Request({
method: 'GET',
path: "sshkeys"
}, callback);
}
Create(key, callback) {
this.blih.Request({
method: 'POST',
path: "sshkey",
json: {
sshkey: key
}
}, callback);
}
Delete(key, callback) {
this.blih.Request({
method: 'DELETE',
path: "sshkey/" + key,
}, callback);
}
}