mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
feat(settings): add settings management (#906)
This commit is contained in:
parent
5e74a3993b
commit
c7e306841a
93 changed files with 1086 additions and 457 deletions
38
app/rest/docker/container.js
Normal file
38
app/rest/docker/container.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('Container', ['$resource', 'DOCKER_ENDPOINT', 'EndpointProvider', function ContainerFactory($resource, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return $resource(DOCKER_ENDPOINT + '/:endpointId/containers/:id/:action', {
|
||||
name: '@name',
|
||||
endpointId: EndpointProvider.endpointID
|
||||
},
|
||||
{
|
||||
query: {method: 'GET', params: {all: 0, action: 'json', filters: '@filters' }, isArray: true},
|
||||
get: {method: 'GET', params: {action: 'json'}},
|
||||
stop: {method: 'POST', params: {id: '@id', t: 5, action: 'stop'}},
|
||||
restart: {method: 'POST', params: {id: '@id', t: 5, action: 'restart'}},
|
||||
kill: {method: 'POST', params: {id: '@id', action: 'kill'}},
|
||||
pause: {method: 'POST', params: {id: '@id', action: 'pause'}},
|
||||
unpause: {method: 'POST', params: {id: '@id', action: 'unpause'}},
|
||||
stats: {method: 'GET', params: {id: '@id', stream: false, action: 'stats'}, timeout: 5000},
|
||||
start: {
|
||||
method: 'POST', params: {id: '@id', action: 'start'},
|
||||
transformResponse: genericHandler
|
||||
},
|
||||
create: {
|
||||
method: 'POST', params: {action: 'create'},
|
||||
transformResponse: genericHandler
|
||||
},
|
||||
remove: {
|
||||
method: 'DELETE', params: {id: '@id', v: '@v', force: '@force'},
|
||||
transformResponse: genericHandler
|
||||
},
|
||||
rename: {
|
||||
method: 'POST', params: {id: '@id', action: 'rename', name: '@name'},
|
||||
transformResponse: genericHandler
|
||||
},
|
||||
exec: {
|
||||
method: 'POST', params: {id: '@id', action: 'exec'},
|
||||
transformResponse: genericHandler
|
||||
}
|
||||
});
|
||||
}]);
|
10
app/rest/docker/containerCommit.js
Normal file
10
app/rest/docker/containerCommit.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('ContainerCommit', ['$resource', 'DOCKER_ENDPOINT', 'EndpointProvider', function ContainerCommitFactory($resource, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return $resource(DOCKER_ENDPOINT + '/:endpointId/commit', {
|
||||
endpointId: EndpointProvider.endpointID
|
||||
},
|
||||
{
|
||||
commit: {method: 'POST', params: {container: '@id', repo: '@repo', tag: '@tag'}}
|
||||
});
|
||||
}]);
|
20
app/rest/docker/containerLogs.js
Normal file
20
app/rest/docker/containerLogs.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('ContainerLogs', ['$http', 'DOCKER_ENDPOINT', 'EndpointProvider', function ContainerLogsFactory($http, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return {
|
||||
get: function (id, params, callback) {
|
||||
$http({
|
||||
method: 'GET',
|
||||
url: DOCKER_ENDPOINT + '/' + EndpointProvider.endpointID() + '/containers/' + id + '/logs',
|
||||
params: {
|
||||
'stdout': params.stdout || 0,
|
||||
'stderr': params.stderr || 0,
|
||||
'timestamps': params.timestamps || 0,
|
||||
'tail': params.tail || 'all'
|
||||
}
|
||||
}).success(callback).error(function (data, status, headers, config) {
|
||||
console.log(error, data);
|
||||
});
|
||||
}
|
||||
};
|
||||
}]);
|
15
app/rest/docker/containerTop.js
Normal file
15
app/rest/docker/containerTop.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('ContainerTop', ['$http', 'DOCKER_ENDPOINT', 'EndpointProvider', function ($http, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return {
|
||||
get: function (id, params, callback, errorCallback) {
|
||||
$http({
|
||||
method: 'GET',
|
||||
url: DOCKER_ENDPOINT + '/' + EndpointProvider.endpointID() + '/containers/' + id + '/top',
|
||||
params: {
|
||||
ps_args: params.ps_args
|
||||
}
|
||||
}).success(callback);
|
||||
}
|
||||
};
|
||||
}]);
|
13
app/rest/docker/event.js
Normal file
13
app/rest/docker/event.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('Events', ['$resource', 'DOCKER_ENDPOINT', 'EndpointProvider', function EventFactory($resource, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return $resource(DOCKER_ENDPOINT + '/:endpointId/events', {
|
||||
endpointId: EndpointProvider.endpointID
|
||||
},
|
||||
{
|
||||
query: {
|
||||
method: 'GET', params: {since: '@since', until: '@until'},
|
||||
isArray: true, transformResponse: jsonObjectsToArrayHandler
|
||||
}
|
||||
});
|
||||
}]);
|
13
app/rest/docker/exec.js
Normal file
13
app/rest/docker/exec.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('Exec', ['$resource', 'DOCKER_ENDPOINT', 'EndpointProvider', function ExecFactory($resource, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return $resource(DOCKER_ENDPOINT + '/:endpointId/exec/:id/:action', {
|
||||
endpointId: EndpointProvider.endpointID
|
||||
},
|
||||
{
|
||||
resize: {
|
||||
method: 'POST', params: {id: '@id', action: 'resize', h: '@height', w: '@width'},
|
||||
transformResponse: genericHandler
|
||||
}
|
||||
});
|
||||
}]);
|
28
app/rest/docker/image.js
Normal file
28
app/rest/docker/image.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('Image', ['$resource', 'DOCKER_ENDPOINT', 'EndpointProvider', function ImageFactory($resource, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return $resource(DOCKER_ENDPOINT + '/:endpointId/images/:id/:action', {
|
||||
endpointId: EndpointProvider.endpointID
|
||||
},
|
||||
{
|
||||
query: {method: 'GET', params: {all: 0, action: 'json'}, isArray: true},
|
||||
get: {method: 'GET', params: {action: 'json'}},
|
||||
search: {method: 'GET', params: {action: 'search'}},
|
||||
history: {method: 'GET', params: {action: 'history'}, isArray: true},
|
||||
insert: {method: 'POST', params: {id: '@id', action: 'insert'}},
|
||||
tag: {method: 'POST', params: {id: '@id', action: 'tag', force: 0, repo: '@repo', tag: '@tag'}},
|
||||
inspect: {method: 'GET', params: {id: '@id', action: 'json'}},
|
||||
push: {
|
||||
method: 'POST', params: {action: 'push', id: '@tag'},
|
||||
isArray: true, transformResponse: jsonObjectsToArrayHandler
|
||||
},
|
||||
create: {
|
||||
method: 'POST', params: {action: 'create', fromImage: '@fromImage', tag: '@tag'},
|
||||
isArray: true, transformResponse: jsonObjectsToArrayHandler
|
||||
},
|
||||
remove: {
|
||||
method: 'DELETE', params: {id: '@id', force: '@force'},
|
||||
isArray: true, transformResponse: deleteImageHandler
|
||||
}
|
||||
});
|
||||
}]);
|
7
app/rest/docker/info.js
Normal file
7
app/rest/docker/info.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('Info', ['$resource', 'DOCKER_ENDPOINT', 'EndpointProvider', function InfoFactory($resource, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return $resource(DOCKER_ENDPOINT + '/:endpointId/info', {
|
||||
endpointId: EndpointProvider.endpointID
|
||||
});
|
||||
}]);
|
16
app/rest/docker/network.js
Normal file
16
app/rest/docker/network.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('Network', ['$resource', 'DOCKER_ENDPOINT', 'EndpointProvider', function NetworkFactory($resource, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return $resource(DOCKER_ENDPOINT + '/:endpointId/networks/:id/:action', {
|
||||
id: '@id',
|
||||
endpointId: EndpointProvider.endpointID
|
||||
},
|
||||
{
|
||||
query: {method: 'GET', isArray: true},
|
||||
get: {method: 'GET'},
|
||||
create: {method: 'POST', params: {action: 'create'}, transformResponse: genericHandler},
|
||||
remove: { method: 'DELETE', transformResponse: genericHandler },
|
||||
connect: {method: 'POST', params: {action: 'connect'}},
|
||||
disconnect: {method: 'POST', params: {action: 'disconnect'}}
|
||||
});
|
||||
}]);
|
13
app/rest/docker/node.js
Normal file
13
app/rest/docker/node.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('Node', ['$resource', 'DOCKER_ENDPOINT', 'EndpointProvider', function NodeFactory($resource, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return $resource(DOCKER_ENDPOINT + '/:endpointId/nodes/:id/:action', {
|
||||
endpointId: EndpointProvider.endpointID
|
||||
},
|
||||
{
|
||||
query: {method: 'GET', isArray: true},
|
||||
get: {method: 'GET', params: {id: '@id'}},
|
||||
update: { method: 'POST', params: {id: '@id', action: 'update', version: '@version'} },
|
||||
remove: { method: 'DELETE', params: {id: '@id'} }
|
||||
});
|
||||
}]);
|
68
app/rest/docker/response/handlers.js
Normal file
68
app/rest/docker/response/handlers.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
function isJSONArray(jsonString) {
|
||||
return Object.prototype.toString.call(jsonString) === '[object Array]';
|
||||
}
|
||||
|
||||
function isJSON(jsonString) {
|
||||
try {
|
||||
var o = JSON.parse(jsonString);
|
||||
if (o && typeof o === 'object') {
|
||||
return o;
|
||||
}
|
||||
}
|
||||
catch (e) { }
|
||||
return false;
|
||||
}
|
||||
|
||||
// The Docker API often returns a list of JSON object.
|
||||
// This handler wrap the JSON objects in an array.
|
||||
// Used by the API in: Image push, Image create, Events query.
|
||||
function jsonObjectsToArrayHandler(data) {
|
||||
var str = '[' + data.replace(/\n/g, ' ').replace(/\}\s*\{/g, '}, {') + ']';
|
||||
return angular.fromJson(str);
|
||||
}
|
||||
|
||||
// The Docker API often returns an empty string or a valid JSON object on success (Docker 1.9 -> Docker 1.12).
|
||||
// On error, it returns either an error message as a string (Docker < 1.12) or a JSON object with the field message
|
||||
// container the error (Docker = 1.12)
|
||||
// This handler ensure a valid JSON object is returned in any case.
|
||||
// Used by the API in: container deletion, network deletion, network creation, volume creation,
|
||||
// container exec, exec resize.
|
||||
function genericHandler(data) {
|
||||
var response = {};
|
||||
// No data is returned when deletion is successful (Docker 1.9 -> 1.12)
|
||||
if (!data) {
|
||||
return response;
|
||||
}
|
||||
// A string is returned on failure (Docker < 1.12)
|
||||
else if (!isJSON(data)) {
|
||||
response.message = data;
|
||||
}
|
||||
// Docker 1.12 returns a valid JSON object when an error occurs
|
||||
else {
|
||||
response = angular.fromJson(data);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
// Image delete API returns an array on success (Docker 1.9 -> Docker 1.12).
|
||||
// On error, it returns either an error message as a string (Docker < 1.12) or a JSON object with the field message
|
||||
// container the error (Docker = 1.12).
|
||||
// This handler returns the original array on success or a newly created array containing
|
||||
// only one JSON object with the field message filled with the error message on failure.
|
||||
function deleteImageHandler(data) {
|
||||
// A string is returned on failure (Docker < 1.12)
|
||||
var response = [];
|
||||
if (!isJSON(data)) {
|
||||
response.push({message: data});
|
||||
}
|
||||
// A JSON object is returned on failure (Docker = 1.12)
|
||||
else if (!isJSONArray(data)) {
|
||||
var json = angular.fromJson(data);
|
||||
response.push(json);
|
||||
}
|
||||
// An array is returned on success (Docker 1.9 -> 1.12)
|
||||
else {
|
||||
response = angular.fromJson(data);
|
||||
}
|
||||
return response;
|
||||
}
|
12
app/rest/docker/secret.js
Normal file
12
app/rest/docker/secret.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('Secret', ['$resource', 'DOCKER_ENDPOINT', 'EndpointProvider', function SecretFactory($resource, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return $resource(DOCKER_ENDPOINT + '/:endpointId/secrets/:id/:action', {
|
||||
endpointId: EndpointProvider.endpointID
|
||||
}, {
|
||||
get: { method: 'GET', params: {id: '@id'} },
|
||||
query: { method: 'GET', isArray: true },
|
||||
create: { method: 'POST', params: {action: 'create'} },
|
||||
remove: { method: 'DELETE', params: {id: '@id'} }
|
||||
});
|
||||
}]);
|
14
app/rest/docker/service.js
Normal file
14
app/rest/docker/service.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('Service', ['$resource', 'DOCKER_ENDPOINT', 'EndpointProvider', function ServiceFactory($resource, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return $resource(DOCKER_ENDPOINT + '/:endpointId/services/:id/:action', {
|
||||
endpointId: EndpointProvider.endpointID
|
||||
},
|
||||
{
|
||||
get: { method: 'GET', params: {id: '@id'} },
|
||||
query: { method: 'GET', isArray: true },
|
||||
create: { method: 'POST', params: {action: 'create'} },
|
||||
update: { method: 'POST', params: {id: '@id', action: 'update', version: '@version'} },
|
||||
remove: { method: 'DELETE', params: {id: '@id'} }
|
||||
});
|
||||
}]);
|
10
app/rest/docker/swarm.js
Normal file
10
app/rest/docker/swarm.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('Swarm', ['$resource', 'DOCKER_ENDPOINT', 'EndpointProvider', function SwarmFactory($resource, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return $resource(DOCKER_ENDPOINT + '/:endpointId/swarm', {
|
||||
endpointId: EndpointProvider.endpointID
|
||||
},
|
||||
{
|
||||
get: {method: 'GET'}
|
||||
});
|
||||
}]);
|
11
app/rest/docker/task.js
Normal file
11
app/rest/docker/task.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('Task', ['$resource', 'DOCKER_ENDPOINT', 'EndpointProvider', function TaskFactory($resource, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return $resource(DOCKER_ENDPOINT + '/:endpointId/tasks/:id', {
|
||||
endpointId: EndpointProvider.endpointID
|
||||
},
|
||||
{
|
||||
get: { method: 'GET', params: {id: '@id'} },
|
||||
query: { method: 'GET', isArray: true, params: {filters: '@filters'} }
|
||||
});
|
||||
}]);
|
7
app/rest/docker/version.js
Normal file
7
app/rest/docker/version.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('Version', ['$resource', 'DOCKER_ENDPOINT', 'EndpointProvider', function VersionFactory($resource, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return $resource(DOCKER_ENDPOINT + '/:endpointId/version', {
|
||||
endpointId: EndpointProvider.endpointID
|
||||
});
|
||||
}]);
|
16
app/rest/docker/volume.js
Normal file
16
app/rest/docker/volume.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
angular.module('portainer.rest')
|
||||
.factory('Volume', ['$resource', 'DOCKER_ENDPOINT', 'EndpointProvider', function VolumeFactory($resource, DOCKER_ENDPOINT, EndpointProvider) {
|
||||
'use strict';
|
||||
return $resource(DOCKER_ENDPOINT + '/:endpointId/volumes/:id/:action',
|
||||
{
|
||||
endpointId: EndpointProvider.endpointID
|
||||
},
|
||||
{
|
||||
query: { method: 'GET' },
|
||||
get: { method: 'GET', params: {id: '@id'} },
|
||||
create: {method: 'POST', params: {action: 'create'}, transformResponse: genericHandler},
|
||||
remove: {
|
||||
method: 'DELETE', transformResponse: genericHandler, params: {id: '@id'}
|
||||
}
|
||||
});
|
||||
}]);
|
Loading…
Add table
Add a link
Reference in a new issue