-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#609 WIP: add responders menus in case and task details pages
- Loading branch information
Showing
5 changed files
with
191 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,121 @@ | ||
(function() { | ||
'use strict'; | ||
angular.module('theHiveServices').factory('CortexSrv', function($q, $http, $rootScope, $uibModal, StatSrv, StreamSrv, AnalyzerSrv, PSearchSrv) { | ||
|
||
angular.module('theHiveServices').service('CortexSrv', function($q, $http, $rootScope, $uibModal, StatSrv, StreamSrv, AnalyzerSrv, PSearchSrv) { | ||
var self = this; | ||
var baseUrl = './api/connector/cortex'; | ||
|
||
var factory = { | ||
list: function(scope, caseId, observableId, callback) { | ||
return PSearchSrv(undefined, 'connector/cortex/job', { | ||
scope: scope, | ||
sort: '-startDate', | ||
loadAll: false, | ||
pageSize: 200, | ||
onUpdate: callback || angular.noop, | ||
streamObjectType: 'case_artifact_job', | ||
filter: { | ||
_parent: { | ||
_type: 'case_artifact', | ||
_query: { | ||
_id: observableId | ||
} | ||
this.list = function(scope, caseId, observableId, callback) { | ||
return PSearchSrv(undefined, 'connector/cortex/job', { | ||
scope: scope, | ||
sort: '-startDate', | ||
loadAll: false, | ||
pageSize: 200, | ||
onUpdate: callback || angular.noop, | ||
streamObjectType: 'case_artifact_job', | ||
filter: { | ||
_parent: { | ||
_type: 'case_artifact', | ||
_query: { | ||
_id: observableId | ||
} | ||
} | ||
}); | ||
}, | ||
} | ||
}); | ||
} | ||
|
||
getJobs: function(caseId, observableId, analyzerId, limit) { | ||
return $http.post(baseUrl + '/job/_search', { | ||
sort: '-startDate', | ||
range: '0-' + (limit || 10), | ||
query: { | ||
_and: [ | ||
{ | ||
_parent: { | ||
_type: 'case_artifact', | ||
_query: { | ||
_id: observableId | ||
} | ||
this.getJobs = function(caseId, observableId, analyzerId, limit) { | ||
return $http.post(baseUrl + '/job/_search', { | ||
sort: '-startDate', | ||
range: '0-' + ( | ||
limit || 10), | ||
query: { | ||
_and: [ | ||
{ | ||
_parent: { | ||
_type: 'case_artifact', | ||
_query: { | ||
_id: observableId | ||
} | ||
}, { | ||
_or: [ | ||
{analyzerId: analyzerId}, | ||
{ | ||
} | ||
}, { | ||
_or: [ | ||
{ | ||
analyzerId: analyzerId | ||
}, { | ||
_like: { | ||
_field: 'analyzerDefinition', | ||
_value: analyzerId | ||
_field: 'analyzerDefinition', | ||
_value: analyzerId | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}) | ||
}; | ||
|
||
this.getJob = function(jobId, nstats) { | ||
if (nstats) { | ||
return $http.get(baseUrl + '/job/' + jobId, { | ||
params: { | ||
nstats: true | ||
} | ||
}) | ||
}, | ||
}); | ||
} | ||
return $http.get(baseUrl + '/job/' + jobId); | ||
|
||
getJob: function(jobId, nstats) { | ||
if(nstats) { | ||
return $http.get(baseUrl + '/job/' + jobId, {params: {nstats: true}}); | ||
} | ||
return $http.get(baseUrl + '/job/' + jobId); | ||
}; | ||
|
||
}, | ||
this.createJob = function(job) { | ||
return $http.post(baseUrl + '/job', job); | ||
}; | ||
|
||
createJob: function(job) { | ||
return $http.post(baseUrl + '/job', job); | ||
}, | ||
this.getServers = function(analyzerIds) { | ||
return AnalyzerSrv.serversFor(analyzerIds).then(function(servers) { | ||
if (servers.length === 1) { | ||
return $q.resolve(servers[0]); | ||
} else { | ||
return self.promptForInstance(servers); | ||
} | ||
}); | ||
}; | ||
|
||
getServers: function(analyzerIds) { | ||
return AnalyzerSrv.serversFor(analyzerIds).then(function(servers) { | ||
if (servers.length === 1) { | ||
return $q.resolve(servers[0]); | ||
} else { | ||
return factory.promptForInstance(servers); | ||
this.promptForInstance = function(servers) { | ||
var modalInstance = $uibModal.open({ | ||
templateUrl: 'views/partials/cortex/choose-instance-dialog.html', | ||
controller: 'ServerInstanceDialogCtrl', | ||
controllerAs: 'vm', | ||
size: '', | ||
resolve: { | ||
servers: function() { | ||
return servers; | ||
} | ||
}); | ||
}, | ||
} | ||
}); | ||
|
||
promptForInstance: function(servers) { | ||
var modalInstance = $uibModal.open({ | ||
templateUrl: 'views/partials/cortex/choose-instance-dialog.html', | ||
controller: 'ServerInstanceDialogCtrl', | ||
controllerAs: 'vm', | ||
size: '', | ||
resolve: { | ||
servers: function() { | ||
return servers; | ||
} | ||
} | ||
}); | ||
return modalInstance.result; | ||
}; | ||
|
||
return modalInstance.result; | ||
} | ||
this.getResponders = function(type, id) { | ||
//return $http.get(baseUrl + '/responder') | ||
return $http.get(baseUrl + '/responder/' + type + '/' + id) | ||
.then(function(response) { | ||
return $q.resolve(response.data); | ||
}) | ||
.catch(function(err) { | ||
return $q.reject(err); | ||
}) | ||
}; | ||
|
||
return factory; | ||
this.runResponder = function(responderId, type, object) { | ||
var post = { | ||
responderId: responderId, | ||
objectType: type, | ||
objectId: object.id | ||
}; | ||
|
||
return $http.post(baseUrl + '/action', post); | ||
} | ||
}); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters