2016-09-04 02:50:37 +00:00
|
|
|
angular.module('portainer.services', ['ngResource', 'ngSanitize'])
|
2015-09-14 06:06:34 +00:00
|
|
|
.factory('Container', ['$resource', 'Settings', function ContainerFactory($resource, Settings) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2013-06-09 01:20:29 +00:00
|
|
|
// Resource for interacting with the docker containers
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#2-1-containers
|
2014-07-28 16:09:05 +00:00
|
|
|
return $resource(Settings.url + '/containers/:id/:action', {
|
2014-10-19 02:41:26 +00:00
|
|
|
name: '@name'
|
2014-07-28 16:09:05 +00:00
|
|
|
}, {
|
2016-12-25 20:28:54 +00:00
|
|
|
query: {method: 'GET', params: {all: 0, action: 'json', filters: '@filters' }, isArray: true},
|
2015-03-31 21:37:03 +00:00
|
|
|
get: {method: 'GET', params: {action: 'json'}},
|
2013-06-09 23:56:54 +00:00
|
|
|
stop: {method: 'POST', params: {id: '@id', t: 5, action: 'stop'}},
|
2015-03-31 21:37:03 +00:00
|
|
|
restart: {method: 'POST', params: {id: '@id', t: 5, action: 'restart'}},
|
2014-10-19 02:41:26 +00:00
|
|
|
kill: {method: 'POST', params: {id: '@id', action: 'kill'}},
|
|
|
|
pause: {method: 'POST', params: {id: '@id', action: 'pause'}},
|
|
|
|
unpause: {method: 'POST', params: {id: '@id', action: 'unpause'}},
|
2015-03-31 21:37:03 +00:00
|
|
|
changes: {method: 'GET', params: {action: 'changes'}, isArray: true},
|
2016-09-02 03:25:20 +00:00
|
|
|
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
|
|
|
|
},
|
2016-09-01 03:07:31 +00:00
|
|
|
remove: {
|
|
|
|
method: 'DELETE', params: {id: '@id', v: 0},
|
2016-09-02 03:25:20 +00:00
|
|
|
transformResponse: genericHandler
|
2016-09-01 03:07:31 +00:00
|
|
|
},
|
2016-09-02 03:25:20 +00:00
|
|
|
rename: {
|
|
|
|
method: 'POST', params: {id: '@id', action: 'rename', name: '@name'},
|
|
|
|
transformResponse: genericHandler
|
|
|
|
},
|
|
|
|
exec: {
|
|
|
|
method: 'POST', params: {id: '@id', action: 'exec'},
|
|
|
|
transformResponse: genericHandler
|
|
|
|
}
|
2013-06-09 01:20:29 +00:00
|
|
|
});
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
2016-09-23 04:54:58 +00:00
|
|
|
.factory('Service', ['$resource', 'Settings', function ServiceFactory($resource, Settings) {
|
|
|
|
'use strict';
|
|
|
|
// https://docs.docker.com/engine/reference/api/docker_remote_api_<%= remoteApiVersion %>/#/3-9-services
|
|
|
|
return $resource(Settings.url + '/services/:id/:action', {}, {
|
|
|
|
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'} }
|
|
|
|
});
|
|
|
|
}])
|
|
|
|
.factory('Task', ['$resource', 'Settings', function TaskFactory($resource, Settings) {
|
|
|
|
'use strict';
|
|
|
|
// https://docs.docker.com/engine/reference/api/docker_remote_api_<%= remoteApiVersion %>/#/3-9-services
|
|
|
|
return $resource(Settings.url + '/tasks/:id', {}, {
|
|
|
|
get: { method: 'GET', params: {id: '@id'} },
|
|
|
|
query: { method: 'GET', isArray: true, params: {filters: '@filters'} }
|
|
|
|
});
|
|
|
|
}])
|
2016-08-03 03:12:53 +00:00
|
|
|
.factory('Exec', ['$resource', 'Settings', function ExecFactory($resource, Settings) {
|
|
|
|
'use strict';
|
|
|
|
// https://docs.docker.com/engine/reference/api/docker_remote_api_<%= remoteApiVersion %>/#/exec-resize
|
|
|
|
return $resource(Settings.url + '/exec/:id/:action', {}, {
|
2016-09-02 03:25:20 +00:00
|
|
|
resize: {
|
|
|
|
method: 'POST', params: {id: '@id', action: 'resize', h: '@height', w: '@width'},
|
|
|
|
transformResponse: genericHandler
|
|
|
|
}
|
2016-08-03 03:12:53 +00:00
|
|
|
});
|
|
|
|
}])
|
2015-09-14 06:06:34 +00:00
|
|
|
.factory('ContainerCommit', ['$resource', '$http', 'Settings', function ContainerCommitFactory($resource, $http, Settings) {
|
2015-05-12 16:53:19 +00:00
|
|
|
'use strict';
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#create-a-new-image-from-a-container-s-changes
|
2016-08-19 06:41:45 +00:00
|
|
|
return $resource(Settings.url + '/commit', {}, {
|
|
|
|
commit: {method: 'POST', params: {container: '@id', repo: '@repo', tag: '@tag'}}
|
|
|
|
});
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
|
|
|
.factory('ContainerLogs', ['$resource', '$http', 'Settings', function ContainerLogsFactory($resource, $http, Settings) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#get-container-logs
|
2014-12-15 22:26:10 +00:00
|
|
|
return {
|
2015-03-31 21:37:03 +00:00
|
|
|
get: function (id, params, callback) {
|
2014-12-15 22:26:10 +00:00
|
|
|
$http({
|
|
|
|
method: 'GET',
|
2015-03-31 21:37:03 +00:00
|
|
|
url: Settings.url + '/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) {
|
2014-12-15 22:26:10 +00:00
|
|
|
console.log(error, data);
|
|
|
|
});
|
|
|
|
}
|
2015-01-04 00:39:40 +00:00
|
|
|
};
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
|
|
|
.factory('ContainerTop', ['$http', 'Settings', function ($http, Settings) {
|
2015-03-31 21:37:03 +00:00
|
|
|
'use strict';
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#list-processes-running-inside-a-container
|
2015-03-31 21:37:03 +00:00
|
|
|
return {
|
|
|
|
get: function (id, params, callback, errorCallback) {
|
|
|
|
$http({
|
|
|
|
method: 'GET',
|
|
|
|
url: Settings.url + '/containers/' + id + '/top',
|
|
|
|
params: {
|
|
|
|
ps_args: params.ps_args
|
|
|
|
}
|
|
|
|
}).success(callback);
|
|
|
|
}
|
|
|
|
};
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
|
|
|
.factory('Image', ['$resource', 'Settings', function ImageFactory($resource, Settings) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#2-2-images
|
2013-06-11 00:10:43 +00:00
|
|
|
return $resource(Settings.url + '/images/:id/:action', {}, {
|
2015-03-31 21:37:03 +00:00
|
|
|
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'}},
|
2015-11-27 06:19:38 +00:00
|
|
|
tag: {method: 'POST', params: {id: '@id', action: 'tag', force: 0, repo: '@repo', tag: '@tag'}},
|
2016-08-10 03:14:10 +00:00
|
|
|
inspect: {method: 'GET', params: {id: '@id', action: 'json'}},
|
2016-08-17 00:27:54 +00:00
|
|
|
push: {
|
|
|
|
method: 'POST', params: {action: 'push', id: '@tag'},
|
2016-08-17 01:50:55 +00:00
|
|
|
isArray: true, transformResponse: jsonObjectsToArrayHandler
|
2016-08-17 00:27:54 +00:00
|
|
|
},
|
2016-08-10 03:14:10 +00:00
|
|
|
create: {
|
|
|
|
method: 'POST', params: {action: 'create', fromImage: '@fromImage', tag: '@tag'},
|
2016-08-17 01:50:55 +00:00
|
|
|
isArray: true, transformResponse: jsonObjectsToArrayHandler
|
2016-08-10 03:14:10 +00:00
|
|
|
},
|
|
|
|
remove: {
|
|
|
|
method: 'DELETE', params: {id: '@id'},
|
|
|
|
isArray: true, transformResponse: deleteImageHandler
|
|
|
|
}
|
2013-06-09 01:20:29 +00:00
|
|
|
});
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
2016-07-27 05:05:16 +00:00
|
|
|
.factory('Events', ['$resource', 'Settings', function EventFactory($resource, Settings) {
|
|
|
|
'use strict';
|
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#/monitor-docker-s-events
|
|
|
|
return $resource(Settings.url + '/events', {}, {
|
2016-08-10 03:14:10 +00:00
|
|
|
query: {
|
|
|
|
method: 'GET', params: {since: '@since', until: '@until'},
|
2016-08-17 01:50:55 +00:00
|
|
|
isArray: true, transformResponse: jsonObjectsToArrayHandler
|
2016-08-10 03:14:10 +00:00
|
|
|
}
|
2016-07-27 05:05:16 +00:00
|
|
|
});
|
|
|
|
}])
|
2015-12-21 02:23:17 +00:00
|
|
|
.factory('Version', ['$resource', 'Settings', function VersionFactory($resource, Settings) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#show-the-docker-version-information
|
2013-06-11 00:10:43 +00:00
|
|
|
return $resource(Settings.url + '/version', {}, {
|
2013-06-10 01:31:05 +00:00
|
|
|
get: {method: 'GET'}
|
|
|
|
});
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
2016-09-23 04:54:58 +00:00
|
|
|
.factory('Node', ['$resource', 'Settings', function NodeFactory($resource, Settings) {
|
|
|
|
'use strict';
|
|
|
|
// https://docs.docker.com/engine/reference/api/docker_remote_api_<%= remoteApiVersion %>/#/3-7-nodes
|
2017-01-25 21:12:04 +00:00
|
|
|
return $resource(Settings.url + '/nodes/:id/:action', {}, {
|
|
|
|
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'} }
|
2016-09-23 04:54:58 +00:00
|
|
|
});
|
|
|
|
}])
|
|
|
|
.factory('Swarm', ['$resource', 'Settings', function SwarmFactory($resource, Settings) {
|
|
|
|
'use strict';
|
|
|
|
// https://docs.docker.com/engine/reference/api/docker_remote_api_<%= remoteApiVersion %>/#/3-8-swarm
|
|
|
|
return $resource(Settings.url + '/swarm', {}, {
|
|
|
|
get: {method: 'GET'}
|
|
|
|
});
|
|
|
|
}])
|
2015-12-21 02:23:17 +00:00
|
|
|
.factory('Info', ['$resource', 'Settings', function InfoFactory($resource, Settings) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2015-08-29 07:38:03 +00:00
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#display-system-wide-information
|
2013-06-11 00:10:43 +00:00
|
|
|
return $resource(Settings.url + '/info', {}, {
|
2013-06-10 01:31:05 +00:00
|
|
|
get: {method: 'GET'}
|
|
|
|
});
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
2015-12-21 03:17:01 +00:00
|
|
|
.factory('Network', ['$resource', 'Settings', function NetworkFactory($resource, Settings) {
|
2015-12-18 05:35:04 +00:00
|
|
|
'use strict';
|
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#2-5-networks
|
2015-12-21 01:13:53 +00:00
|
|
|
return $resource(Settings.url + '/networks/:id/:action', {id: '@id'}, {
|
2015-12-18 05:35:04 +00:00
|
|
|
query: {method: 'GET', isArray: true},
|
|
|
|
get: {method: 'GET'},
|
2016-09-02 03:25:20 +00:00
|
|
|
create: {method: 'POST', params: {action: 'create'}, transformResponse: genericHandler},
|
|
|
|
remove: { method: 'DELETE', transformResponse: genericHandler },
|
2015-12-21 01:13:53 +00:00
|
|
|
connect: {method: 'POST', params: {action: 'connect'}},
|
|
|
|
disconnect: {method: 'POST', params: {action: 'disconnect'}}
|
2015-12-18 05:35:04 +00:00
|
|
|
});
|
|
|
|
}])
|
2015-12-21 03:17:01 +00:00
|
|
|
.factory('Volume', ['$resource', 'Settings', function VolumeFactory($resource, Settings) {
|
|
|
|
'use strict';
|
|
|
|
// http://docs.docker.com/reference/api/docker_remote_api_<%= remoteApiVersion %>/#2-5-networks
|
|
|
|
return $resource(Settings.url + '/volumes/:name/:action', {name: '@name'}, {
|
2016-12-25 20:34:02 +00:00
|
|
|
query: {method: 'GET'},
|
|
|
|
get: {method: 'GET'},
|
|
|
|
create: {method: 'POST', params: {action: 'create'}, transformResponse: genericHandler},
|
|
|
|
remove: {
|
|
|
|
method: 'DELETE', transformResponse: genericHandler
|
|
|
|
}
|
2015-12-21 03:17:01 +00:00
|
|
|
});
|
|
|
|
}])
|
2016-08-03 09:13:17 +00:00
|
|
|
.factory('Config', ['$resource', 'CONFIG_ENDPOINT', function ConfigFactory($resource, CONFIG_ENDPOINT) {
|
2016-06-21 06:35:21 +00:00
|
|
|
return $resource(CONFIG_ENDPOINT).get();
|
2016-06-16 05:27:07 +00:00
|
|
|
}])
|
2016-08-23 06:09:14 +00:00
|
|
|
.factory('Templates', ['$resource', 'TEMPLATES_ENDPOINT', function TemplatesFactory($resource, TEMPLATES_ENDPOINT) {
|
|
|
|
return $resource(TEMPLATES_ENDPOINT, {}, {
|
|
|
|
get: {method: 'GET', isArray: true}
|
|
|
|
});
|
|
|
|
}])
|
2016-11-17 12:50:46 +00:00
|
|
|
.factory('Settings', ['DOCKER_ENDPOINT', 'DOCKER_PORT', 'UI_VERSION', 'PAGINATION_MAX_ITEMS', function SettingsFactory(DOCKER_ENDPOINT, DOCKER_PORT, UI_VERSION, PAGINATION_MAX_ITEMS) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2013-06-19 01:50:35 +00:00
|
|
|
var url = DOCKER_ENDPOINT;
|
|
|
|
if (DOCKER_PORT) {
|
|
|
|
url = url + DOCKER_PORT + '\\' + DOCKER_PORT;
|
|
|
|
}
|
2016-01-11 02:02:04 +00:00
|
|
|
var firstLoad = (localStorage.getItem('firstLoad') || 'true') === 'true';
|
2013-06-09 23:56:54 +00:00
|
|
|
return {
|
2016-07-07 02:31:16 +00:00
|
|
|
displayAll: true,
|
2016-06-16 05:27:07 +00:00
|
|
|
endpoint: DOCKER_ENDPOINT,
|
|
|
|
uiVersion: UI_VERSION,
|
|
|
|
url: url,
|
2016-11-17 12:50:46 +00:00
|
|
|
firstLoad: firstLoad,
|
|
|
|
pagination_count: PAGINATION_MAX_ITEMS
|
2013-06-19 01:50:35 +00:00
|
|
|
};
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
2016-12-15 03:33:47 +00:00
|
|
|
.factory('Auth', ['$resource', 'AUTH_ENDPOINT', function AuthFactory($resource, AUTH_ENDPOINT) {
|
|
|
|
'use strict';
|
|
|
|
return $resource(AUTH_ENDPOINT, {}, {
|
|
|
|
login: {
|
|
|
|
method: 'POST'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}])
|
2016-12-18 05:21:29 +00:00
|
|
|
.factory('Users', ['$resource', 'USERS_ENDPOINT', function UsersFactory($resource, USERS_ENDPOINT) {
|
2016-12-15 03:33:47 +00:00
|
|
|
'use strict';
|
2016-12-18 05:21:29 +00:00
|
|
|
return $resource(USERS_ENDPOINT + '/:username/:action', {}, {
|
2016-12-15 03:33:47 +00:00
|
|
|
create: { method: 'POST' },
|
2016-12-25 20:34:02 +00:00
|
|
|
get: { method: 'GET', params: { username: '@username' } },
|
2016-12-15 03:33:47 +00:00
|
|
|
update: { method: 'PUT', params: { username: '@username' } },
|
|
|
|
checkPassword: { method: 'POST', params: { username: '@username', action: 'passwd' } },
|
2016-12-25 20:34:02 +00:00
|
|
|
checkAdminUser: { method: 'GET', params: { username: 'admin', action: 'check' } },
|
|
|
|
initAdminUser: { method: 'POST', params: { username: 'admin', action: 'init' } }
|
2016-12-15 03:33:47 +00:00
|
|
|
});
|
|
|
|
}])
|
2017-01-23 04:04:34 +00:00
|
|
|
.factory('Authentication', ['$q', '$rootScope', 'Auth', 'jwtHelper', 'LocalStorage', 'StateManager', function AuthenticationFactory($q, $rootScope, Auth, jwtHelper, LocalStorage, StateManager) {
|
2016-12-15 03:33:47 +00:00
|
|
|
'use strict';
|
|
|
|
return {
|
|
|
|
init: function() {
|
2017-01-22 23:14:34 +00:00
|
|
|
var jwt = LocalStorage.getJWT();
|
2016-12-15 03:33:47 +00:00
|
|
|
if (jwt) {
|
|
|
|
var tokenPayload = jwtHelper.decodeToken(jwt);
|
|
|
|
$rootScope.username = tokenPayload.username;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
login: function(username, password) {
|
|
|
|
return $q(function (resolve, reject) {
|
|
|
|
Auth.login({username: username, password: password}).$promise
|
|
|
|
.then(function(data) {
|
2017-01-22 23:14:34 +00:00
|
|
|
LocalStorage.storeJWT(data.jwt);
|
2016-12-15 03:33:47 +00:00
|
|
|
$rootScope.username = username;
|
|
|
|
resolve();
|
|
|
|
}, function() {
|
|
|
|
reject();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
logout: function() {
|
2017-01-23 04:04:34 +00:00
|
|
|
StateManager.clean();
|
|
|
|
LocalStorage.clean();
|
2016-12-15 03:33:47 +00:00
|
|
|
},
|
|
|
|
isAuthenticated: function() {
|
2017-01-22 23:14:34 +00:00
|
|
|
var jwt = LocalStorage.getJWT();
|
2016-12-15 03:33:47 +00:00
|
|
|
return jwt && !jwtHelper.isTokenExpired(jwt);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}])
|
2016-12-25 20:34:02 +00:00
|
|
|
.factory('FileUploadService', ['$q', 'Upload', function FileUploadFactory($q, Upload) {
|
|
|
|
'use strict';
|
|
|
|
function uploadFile(url, file) {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
Upload.upload({
|
|
|
|
url: url,
|
|
|
|
data: { file: file }
|
|
|
|
}).then(function success(data) {
|
|
|
|
deferred.resolve(data);
|
|
|
|
}, function error(e) {
|
|
|
|
deferred.reject(e);
|
|
|
|
}, function progress(evt) {
|
|
|
|
});
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
uploadTLSFilesForEndpoint: function(endpointID, TLSCAFile, TLSCertFile, TLSKeyFile) {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
var queue = [];
|
|
|
|
|
|
|
|
if (TLSCAFile !== null) {
|
|
|
|
var uploadTLSCA = uploadFile('api/upload/tls/' + endpointID + '/ca', TLSCAFile);
|
|
|
|
queue.push(uploadTLSCA);
|
|
|
|
}
|
|
|
|
if (TLSCertFile !== null) {
|
|
|
|
var uploadTLSCert = uploadFile('api/upload/tls/' + endpointID + '/cert', TLSCertFile);
|
|
|
|
queue.push(uploadTLSCert);
|
|
|
|
}
|
|
|
|
if (TLSKeyFile !== null) {
|
|
|
|
var uploadTLSKey = uploadFile('api/upload/tls/' + endpointID + '/key', TLSKeyFile);
|
|
|
|
queue.push(uploadTLSKey);
|
|
|
|
}
|
|
|
|
$q.all(queue).then(function (data) {
|
|
|
|
deferred.resolve(data);
|
|
|
|
}, function (err) {
|
|
|
|
deferred.reject(err);
|
|
|
|
}, function update(evt) {
|
|
|
|
deferred.notify(evt);
|
|
|
|
});
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}])
|
|
|
|
.factory('Endpoints', ['$resource', 'ENDPOINTS_ENDPOINT', function EndpointsFactory($resource, ENDPOINTS_ENDPOINT) {
|
|
|
|
'use strict';
|
|
|
|
return $resource(ENDPOINTS_ENDPOINT + '/:id/:action', {}, {
|
|
|
|
create: { method: 'POST' },
|
|
|
|
query: { method: 'GET', isArray: true },
|
|
|
|
get: { method: 'GET', params: { id: '@id' } },
|
|
|
|
update: { method: 'PUT', params: { id: '@id' } },
|
|
|
|
remove: { method: 'DELETE', params: { id: '@id'} },
|
|
|
|
getActiveEndpoint: { method: 'GET', params: { id: '0' } },
|
|
|
|
setActiveEndpoint: { method: 'POST', params: { id: '@id', action: 'active' } }
|
|
|
|
});
|
|
|
|
}])
|
2017-01-24 01:28:40 +00:00
|
|
|
.factory('Pagination', ['LocalStorage', 'Settings', function PaginationFactory(LocalStorage, Settings) {
|
|
|
|
'use strict';
|
|
|
|
return {
|
|
|
|
getPaginationCount: function(key) {
|
|
|
|
var storedCount = LocalStorage.getPaginationCount(key);
|
|
|
|
var paginationCount = Settings.pagination_count;
|
|
|
|
if (storedCount !== null) {
|
|
|
|
paginationCount = storedCount;
|
|
|
|
}
|
|
|
|
return '' + paginationCount;
|
|
|
|
},
|
|
|
|
setPaginationCount: function(key, count) {
|
|
|
|
LocalStorage.storePaginationCount(key, count);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}])
|
2017-01-22 23:14:34 +00:00
|
|
|
.factory('LocalStorage', ['localStorageService', function LocalStorageFactory(localStorageService) {
|
|
|
|
'use strict';
|
|
|
|
return {
|
|
|
|
storeEndpointState: function(state) {
|
|
|
|
localStorageService.set('ENDPOINT_STATE', state);
|
|
|
|
},
|
|
|
|
getEndpointState: function() {
|
|
|
|
return localStorageService.get('ENDPOINT_STATE');
|
|
|
|
},
|
|
|
|
storeJWT: function(jwt) {
|
|
|
|
localStorageService.set('JWT', jwt);
|
|
|
|
},
|
|
|
|
getJWT: function() {
|
|
|
|
return localStorageService.get('JWT');
|
|
|
|
},
|
|
|
|
deleteJWT: function() {
|
|
|
|
localStorageService.remove('JWT');
|
2017-01-23 04:04:34 +00:00
|
|
|
},
|
2017-01-24 01:28:40 +00:00
|
|
|
storePaginationCount: function(key, count) {
|
|
|
|
localStorageService.cookie.set('pagination_' + key, count);
|
|
|
|
},
|
|
|
|
getPaginationCount: function(key) {
|
|
|
|
return localStorageService.cookie.get('pagination_' + key);
|
|
|
|
},
|
2017-01-23 04:04:34 +00:00
|
|
|
clean: function() {
|
|
|
|
localStorageService.clearAll();
|
2017-01-22 23:14:34 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}])
|
|
|
|
.factory('StateManager', ['$q', 'Info', 'InfoHelper', 'Version', 'LocalStorage', function StateManagerFactory($q, Info, InfoHelper, Version, LocalStorage) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var state = {
|
|
|
|
loading: true,
|
|
|
|
application: {},
|
|
|
|
endpoint: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
init: function() {
|
|
|
|
var endpointState = LocalStorage.getEndpointState();
|
|
|
|
if (endpointState) {
|
|
|
|
state.endpoint = endpointState;
|
|
|
|
}
|
|
|
|
state.loading = false;
|
|
|
|
},
|
2017-01-23 04:04:34 +00:00
|
|
|
clean: function() {
|
|
|
|
state.endpoint = {};
|
|
|
|
},
|
2017-01-22 23:14:34 +00:00
|
|
|
updateEndpointState: function(loading) {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
if (loading) {
|
|
|
|
state.loading = true;
|
|
|
|
}
|
|
|
|
$q.all([Info.get({}).$promise, Version.get({}).$promise])
|
|
|
|
.then(function success(data) {
|
|
|
|
var endpointMode = InfoHelper.determineEndpointMode(data[0]);
|
|
|
|
var endpointAPIVersion = parseFloat(data[1].ApiVersion);
|
|
|
|
state.endpoint.mode = endpointMode;
|
|
|
|
state.endpoint.apiVersion = endpointAPIVersion;
|
|
|
|
LocalStorage.storeEndpointState(state.endpoint);
|
|
|
|
state.loading = false;
|
|
|
|
deferred.resolve();
|
|
|
|
}, function error(err) {
|
|
|
|
state.loading = false;
|
|
|
|
deferred.reject({msg: 'Unable to connect to the Docker endpoint', err: err});
|
|
|
|
});
|
|
|
|
return deferred.promise;
|
|
|
|
},
|
|
|
|
getState: function() {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}])
|
|
|
|
.factory('EndpointService', ['$q', 'Endpoints', 'FileUploadService', function EndpointServiceFactory($q, Endpoints, FileUploadService) {
|
2016-12-25 20:34:02 +00:00
|
|
|
'use strict';
|
|
|
|
return {
|
|
|
|
getActive: function() {
|
|
|
|
return Endpoints.getActiveEndpoint().$promise;
|
|
|
|
},
|
|
|
|
setActive: function(endpointID) {
|
|
|
|
return Endpoints.setActiveEndpoint({id: endpointID}).$promise;
|
|
|
|
},
|
|
|
|
endpoint: function(endpointID) {
|
|
|
|
return Endpoints.get({id: endpointID}).$promise;
|
|
|
|
},
|
|
|
|
endpoints: function() {
|
|
|
|
return Endpoints.query({}).$promise;
|
|
|
|
},
|
2017-01-12 05:44:53 +00:00
|
|
|
updateEndpoint: function(ID, name, URL, TLS, TLSCAFile, TLSCertFile, TLSKeyFile, type) {
|
2016-12-25 20:34:02 +00:00
|
|
|
var endpoint = {
|
|
|
|
id: ID,
|
|
|
|
Name: name,
|
2017-01-12 05:44:53 +00:00
|
|
|
URL: type === 'local' ? ("unix://" + URL) : ("tcp://" + URL),
|
2016-12-25 20:34:02 +00:00
|
|
|
TLS: TLS
|
|
|
|
};
|
|
|
|
var deferred = $q.defer();
|
|
|
|
Endpoints.update({}, endpoint, function success(data) {
|
|
|
|
FileUploadService.uploadTLSFilesForEndpoint(ID, TLSCAFile, TLSCertFile, TLSKeyFile).then(function success(data) {
|
|
|
|
deferred.notify({upload: false});
|
|
|
|
deferred.resolve(data);
|
|
|
|
}, function error(err) {
|
|
|
|
deferred.notify({upload: false});
|
|
|
|
deferred.reject({msg: 'Unable to upload TLS certs', err: err});
|
|
|
|
});
|
|
|
|
}, function error(err) {
|
|
|
|
deferred.reject({msg: 'Unable to update endpoint', err: err});
|
|
|
|
});
|
|
|
|
return deferred.promise;
|
|
|
|
},
|
|
|
|
deleteEndpoint: function(endpointID) {
|
|
|
|
return Endpoints.remove({id: endpointID}).$promise;
|
|
|
|
},
|
|
|
|
createLocalEndpoint: function(name, URL, TLS, active) {
|
|
|
|
var endpoint = {
|
|
|
|
Name: "local",
|
|
|
|
URL: "unix:///var/run/docker.sock",
|
|
|
|
TLS: false
|
|
|
|
};
|
|
|
|
return Endpoints.create({active: active}, endpoint).$promise;
|
|
|
|
},
|
|
|
|
createRemoteEndpoint: function(name, URL, TLS, TLSCAFile, TLSCertFile, TLSKeyFile, active) {
|
|
|
|
var endpoint = {
|
|
|
|
Name: name,
|
|
|
|
URL: 'tcp://' + URL,
|
|
|
|
TLS: TLS
|
|
|
|
};
|
|
|
|
var deferred = $q.defer();
|
|
|
|
Endpoints.create({active: active}, endpoint, function success(data) {
|
|
|
|
var endpointID = data.Id;
|
|
|
|
if (TLS) {
|
|
|
|
deferred.notify({upload: true});
|
|
|
|
FileUploadService.uploadTLSFilesForEndpoint(endpointID, TLSCAFile, TLSCertFile, TLSKeyFile).then(function success(data) {
|
|
|
|
deferred.notify({upload: false});
|
|
|
|
if (active) {
|
|
|
|
Endpoints.setActiveEndpoint({}, {id: endpointID}, function success(data) {
|
|
|
|
deferred.resolve(data);
|
|
|
|
}, function error(err) {
|
|
|
|
deferred.reject({msg: 'Unable to create endpoint', err: err});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
deferred.resolve(data);
|
|
|
|
}
|
|
|
|
}, function error(err) {
|
|
|
|
deferred.notify({upload: false});
|
|
|
|
deferred.reject({msg: 'Unable to upload TLS certs', err: err});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
deferred.resolve(data);
|
|
|
|
}
|
|
|
|
}, function error(err) {
|
|
|
|
deferred.reject({msg: 'Unable to create endpoint', err: err});
|
|
|
|
});
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}])
|
2016-04-01 01:06:46 +00:00
|
|
|
.factory('Messages', ['$rootScope', '$sanitize', function MessagesFactory($rootScope, $sanitize) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2013-06-20 02:40:58 +00:00
|
|
|
return {
|
2015-03-31 21:37:03 +00:00
|
|
|
send: function (title, text) {
|
2014-10-19 02:41:26 +00:00
|
|
|
$.gritter.add({
|
2016-04-01 01:06:46 +00:00
|
|
|
title: $sanitize(title),
|
|
|
|
text: $sanitize(text),
|
2014-10-19 02:41:26 +00:00
|
|
|
time: 2000,
|
2015-03-31 21:37:03 +00:00
|
|
|
before_open: function () {
|
|
|
|
if ($('.gritter-item-wrapper').length === 3) {
|
2013-08-08 19:18:51 +00:00
|
|
|
return false;
|
2015-03-31 21:37:03 +00:00
|
|
|
}
|
2013-08-08 19:18:51 +00:00
|
|
|
}
|
2015-03-31 21:37:03 +00:00
|
|
|
});
|
2014-10-19 02:41:26 +00:00
|
|
|
},
|
2016-09-02 05:40:03 +00:00
|
|
|
error: function (title, e, fallbackText) {
|
|
|
|
var msg = fallbackText;
|
|
|
|
if (e.data && e.data.message) {
|
|
|
|
msg = e.data.message;
|
|
|
|
} else if (e.message) {
|
|
|
|
msg = e.message;
|
2016-09-07 06:21:46 +00:00
|
|
|
} else if (e.data && e.data.length > 0 && e.data[0].message) {
|
2016-09-07 06:03:55 +00:00
|
|
|
msg = e.data[0].message;
|
2016-09-02 05:40:03 +00:00
|
|
|
}
|
2013-08-08 19:18:51 +00:00
|
|
|
$.gritter.add({
|
2016-04-01 01:06:46 +00:00
|
|
|
title: $sanitize(title),
|
2016-09-02 05:40:03 +00:00
|
|
|
text: $sanitize(msg),
|
2015-01-25 23:59:08 +00:00
|
|
|
time: 10000,
|
2015-03-31 21:37:03 +00:00
|
|
|
before_open: function () {
|
|
|
|
if ($('.gritter-item-wrapper').length === 4) {
|
2013-08-08 19:18:51 +00:00
|
|
|
return false;
|
2015-03-31 21:37:03 +00:00
|
|
|
}
|
2013-08-08 19:18:51 +00:00
|
|
|
}
|
|
|
|
});
|
2014-10-19 02:41:26 +00:00
|
|
|
}
|
2013-06-20 02:40:58 +00:00
|
|
|
};
|
2015-09-14 06:06:34 +00:00
|
|
|
}])
|
|
|
|
.factory('LineChart', ['Settings', function LineChartFactory(Settings) {
|
2015-01-04 00:39:40 +00:00
|
|
|
'use strict';
|
2014-11-29 06:06:06 +00:00
|
|
|
return {
|
2015-03-31 21:37:03 +00:00
|
|
|
build: function (id, data, getkey) {
|
2014-11-29 06:06:06 +00:00
|
|
|
var chart = new Chart($(id).get(0).getContext("2d"));
|
|
|
|
var map = {};
|
|
|
|
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
var c = data[i];
|
|
|
|
var key = getkey(c);
|
2015-03-31 21:37:03 +00:00
|
|
|
|
2014-11-29 06:06:06 +00:00
|
|
|
var count = map[key];
|
|
|
|
if (count === undefined) {
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
count += 1;
|
|
|
|
map[key] = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
var labels = [];
|
2015-01-04 00:39:40 +00:00
|
|
|
data = [];
|
2014-11-29 06:06:06 +00:00
|
|
|
var keys = Object.keys(map);
|
2015-10-10 09:04:19 +00:00
|
|
|
var max = 1;
|
2014-11-29 06:06:06 +00:00
|
|
|
|
2015-01-04 00:39:40 +00:00
|
|
|
for (i = keys.length - 1; i > -1; i--) {
|
2014-11-29 06:06:06 +00:00
|
|
|
var k = keys[i];
|
|
|
|
labels.push(k);
|
|
|
|
data.push(map[k]);
|
2015-10-10 09:04:19 +00:00
|
|
|
if (map[k] > max) {
|
2015-12-21 01:13:53 +00:00
|
|
|
max = map[k];
|
2015-10-10 09:04:19 +00:00
|
|
|
}
|
2014-11-29 06:06:06 +00:00
|
|
|
}
|
2016-01-03 04:59:43 +00:00
|
|
|
var steps = Math.min(max, 10);
|
2014-11-29 06:06:06 +00:00
|
|
|
var dataset = {
|
2015-03-31 21:37:03 +00:00
|
|
|
fillColor: "rgba(151,187,205,0.5)",
|
|
|
|
strokeColor: "rgba(151,187,205,1)",
|
|
|
|
pointColor: "rgba(151,187,205,1)",
|
|
|
|
pointStrokeColor: "#fff",
|
|
|
|
data: data
|
2014-11-29 06:06:06 +00:00
|
|
|
};
|
|
|
|
chart.Line({
|
2015-03-31 21:37:03 +00:00
|
|
|
labels: labels,
|
|
|
|
datasets: [dataset]
|
|
|
|
},
|
|
|
|
{
|
2016-01-03 04:59:43 +00:00
|
|
|
scaleStepWidth: Math.ceil(max / steps),
|
2015-03-31 21:37:03 +00:00
|
|
|
pointDotRadius: 1,
|
2016-01-03 04:59:43 +00:00
|
|
|
scaleIntegersOnly: true,
|
2015-03-31 21:37:03 +00:00
|
|
|
scaleOverride: true,
|
2016-01-03 04:59:43 +00:00
|
|
|
scaleSteps: steps
|
2015-03-31 21:37:03 +00:00
|
|
|
});
|
2014-11-29 06:06:06 +00:00
|
|
|
}
|
|
|
|
};
|
2015-09-14 06:06:34 +00:00
|
|
|
}]);
|