Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
Support semantic versioning for releases, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
croomes committed Mar 28, 2014
1 parent e202779 commit eee32ce
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 873 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/changes/change_detail_controller.js
Expand Up @@ -37,7 +37,7 @@ function($scope, $stateParams, changeWrapper, nodeWrapper, listener, Restangular
};

$scope.getTierRiskData = function() {
Restangular.oneUrl('nodes', 'http://localhost:5984/' + $scope.version + '/_design/hostrisk/_view/all?reduce=true&group=true').get().then(function(res) {
Restangular.oneUrl('nodes', 'http://localhost:5984/r' + $scope.version + '/_design/hostrisk/_view/all?reduce=true&group=true').get().then(function(res) {
$scope.tierhosts = $scope.tierhosts || {};
$scope.tierriskdata = $scope.tierriskdata || {};

Expand Down
22 changes: 12 additions & 10 deletions app/assets/javascripts/changes/change_factory.js
Expand Up @@ -4,16 +4,16 @@ gonzo.factory('changedb', ['$stateParams', function($stateParams) {
// TODO: There are a few other rules we should check for.

if ($stateParams.version) {
version = angular.lowercase($stateParams.version);
release_db = "r" + angular.lowercase($stateParams.version);
}
else {
version = '1.0.0';
return null;
}

console.log("change factory, version: " + version);
var changedb = new PouchDB(version);
PouchDB.replicate('http://127.0.0.1:5984/' + version, version, {continuous: true});
PouchDB.replicate(version, 'http://127.0.0.1:5984/' + version, {continuous: true});
console.log("change factory, version: " + release_db);
var changedb = new PouchDB(release_db);
PouchDB.replicate('http://127.0.0.1:5984/' + release_db, release_db, {continuous: true});
PouchDB.replicate(release_db, 'http://127.0.0.1:5984/' + release_db, {continuous: true});
return changedb;

}]);
Expand Down Expand Up @@ -50,10 +50,11 @@ gonzo.factory('changeWrapper', ['$q', '$rootScope', 'changedb', function($q, $ro

return {
reset: function(version) {
changedb = new PouchDB(version);
console.log("reset change factory to version: " + version);
PouchDB.replicate('http://127.0.0.1:5984/' + version, version, {continuous: true});
PouchDB.replicate(version, 'http://127.0.0.1:5984/' + version, {continuous: true});
release_db = "r" + version;
changedb = new PouchDB(release_db);
console.log("reset change factory to version: " + release_db);
PouchDB.replicate('http://127.0.0.1:5984/' + release_db, release_db, {continuous: true});
PouchDB.replicate(release_db, 'http://127.0.0.1:5984/' + release_db, {continuous: true});
},
query: function(text) {
var deferred = $q.defer();
Expand Down Expand Up @@ -153,6 +154,7 @@ gonzo.factory('changeWrapper', ['$q', '$rootScope', 'changedb', function($q, $ro
changedb.put(doc, function(err, res) {
$rootScope.$apply(function() {
if (err) {
console.log("put err:");
deferred.reject(err);
} else {
console.log("put ok:");
Expand Down
50 changes: 5 additions & 45 deletions app/assets/javascripts/changes/change_list_controller.js
Expand Up @@ -41,7 +41,6 @@ function($scope, $stateParams, $interval, $modal, Restangular, listener, changeW
// Wrapper to call methods that need re-running when the version
// changes
$scope.update_stats = function() {
console.log("update_stats")
$scope.getRiskData();
$scope.getHostRiskData();
$scope.getTierRiskData();
Expand Down Expand Up @@ -96,43 +95,8 @@ function($scope, $stateParams, $interval, $modal, Restangular, listener, changeW
});
};

// $scope.submit = function() {
// changeWrapper.add($scope.text).then(function(res) {
// $scope.text = '';
// }, function(reason) {
// console.log(reason);
// });
// };

// $scope.remove = function(id) {
// changeWrapper.remove(id).then(function(res) {
// }, function(reason) {
// console.log(reason);
// });
// };

// $scope.query = function() {
// console.log("XXXXX Query")
// changeWrapper.query($scope.changes).then(function(res) {
// $scope.changes = '';
// }, function(reason) {
// console.log(reason);
// });
// };

// $scope.get = function(id) {
// changeWrapper.get(id).then(function(res) {
// console.log("Loaded change");
// $scope.change = res;
// }, function(reason) {
// console.log(reason);
// });
// };

$scope.get_tier = function(host) {
// TODO: enforce FQDNs everywhere!!
nodeWrapper.get_tier(host + '.croome.org').then(function(res) {
// console.log(res);
nodeWrapper.get_tier(host).then(function(res) {
return res;
}, function(reason) {
console.log(reason);
Expand Down Expand Up @@ -174,7 +138,7 @@ function($scope, $stateParams, $interval, $modal, Restangular, listener, changeW
};

$scope.getHostRiskData = function() {
Restangular.oneUrl('nodes', 'http://localhost:5984/' + $scope.version + '/_design/hostrisk/_view/all?reduce=true&group=true').get().then(function(res) {
Restangular.oneUrl('nodes', 'http://localhost:5984/r' + $scope.version + '/_design/hostrisk/_view/all?reduce=true&group=true').get().then(function(res) {
$scope.hosts = {};

['dev', 'uat', 'prod', 'unknown'].forEach(function(cur_tier) {
Expand All @@ -185,8 +149,7 @@ function($scope, $stateParams, $interval, $modal, Restangular, listener, changeW
if (row['key'] == cur_risk && row['value']) {
Object.keys(row['value']).forEach(function(host, value) {
if (! $scope.hosts[host]) {
// TODO: remove hardcoding - need to enforce FQDNs everywhere
nodeWrapper.get_tier(host + '.croome.org').then(function(host_tier) {
nodeWrapper.get_tier(host).then(function(host_tier) {
if (host_tier == cur_tier) {
found = false;
for(var i = 0, len = $scope.hostriskdata[cur_tier].length; i < len; i++) {
Expand Down Expand Up @@ -221,14 +184,13 @@ function($scope, $stateParams, $interval, $modal, Restangular, listener, changeW
};

$scope.getRiskData = function() {
Restangular.oneUrl('nodes', 'http://localhost:5984/' + $scope.version + '/_design/risk/_view/all?reduce=true&group=true').get().then(function(res) {
Restangular.oneUrl('nodes', 'http://localhost:5984/r' + $scope.version + '/_design/risk/_view/all?reduce=true&group=true').get().then(function(res) {
results = [];
res.rows.forEach(function(row) {
row.type = $scope.getRiskType(row.key);
results.push(row);
});
$scope.riskdata = $scope.sortByRisk(results);
// console.log($scope.riskdata);

total = 0;
$scope.riskdata.forEach(function(entry) {
Expand Down Expand Up @@ -262,7 +224,6 @@ function($scope, $stateParams, $interval, $modal, Restangular, listener, changeW
});

['unassessed', 'low', 'medium', 'high'].forEach(function(risk) {
// ['high', 'medium', 'low', 'unassessed'].forEach(function(risk) {
if (tmprisk[risk]) {
results.push(tmprisk[risk]);
}
Expand All @@ -271,7 +232,7 @@ function($scope, $stateParams, $interval, $modal, Restangular, listener, changeW
}

$scope.getTierRiskData = function() {
Restangular.oneUrl('nodes', 'http://localhost:5984/' + $scope.version + '/_design/hostrisk/_view/all?reduce=true&group=true').get().then(function(res) {
Restangular.oneUrl('nodes', 'http://localhost:5984/r' + $scope.version + '/_design/hostrisk/_view/all?reduce=true&group=true').get().then(function(res) {
$scope.tierhosts = $scope.tierhosts || {};
$scope.tierriskdata = $scope.tierriskdata || {};

Expand All @@ -283,7 +244,6 @@ function($scope, $stateParams, $interval, $modal, Restangular, listener, changeW
if (row['key'] == cur_risk && row['value']) {
Object.keys(row['value']).forEach(function(host, value) {

// TODO: issues with some hostnames - need to enforce FQDNs everywhere
nodeWrapper.get_tier(host).then(function(host_tier) {
if (host_tier == cur_tier) {
if (! $scope.tierriskdata[cur_tier][cur_risk]) {
Expand Down
10 changes: 10 additions & 0 deletions app/assets/javascripts/filters/release_filter.js
@@ -0,0 +1,10 @@
angular.module('releaseFilter', []).filter('release', function() {
return function(input) {
if (input) {
return input.replace(/_/g,".");
}
else {
return '-';
}
};
});
128 changes: 11 additions & 117 deletions app/assets/javascripts/gonzo.js
Expand Up @@ -7,6 +7,7 @@ var gonzo = angular.module('gonzo', [
'skipFilter',
'timeagoFilter',
'capitalizeFilter',
'releaseFilter',
'md5shortFilter',
'revisionFilter'
]);
Expand All @@ -17,9 +18,6 @@ function($locationProvider, $stateProvider, $urlRouterProvider, RestangularProvi
api_token = {'X-CSRF-Token':$('meta[name=csrf-token]').attr('content')};
$locationProvider.html5Mode(true);

// For any unmatched url, redirect to /gonzo
// $urlRouterProvider.otherwise("");

// Now set up the states
$stateProvider
.state("index", {
Expand Down Expand Up @@ -48,6 +46,15 @@ function($locationProvider, $stateProvider, $urlRouterProvider, RestangularProvi
},
}
})
.state("releases.refresh", {
url: "/refresh",
controller: 'ReleaseListCtrl',
resolve: {
release: function(Restangular, $route) {
return Restangular.one('releases').customPUT(null, 'refresh', null, api_token);
}
}
})
.state("releases.detail", {
url: "/:version",
views: {
Expand Down Expand Up @@ -118,117 +125,4 @@ function($locationProvider, $stateProvider, $urlRouterProvider, RestangularProvi
}]);

gonzo.run(['$state', '$rootScope', '$urlRouter', function ($state, $rootScope, $urlRouter) {
console.log("gonzo run");
console.log($state);
// $state.transitionTo('index');

// $rootScope.$on('$locationChangeSuccess', function(evt) {
// // console.log(evt);
// // Halt state change from even starting
// evt.preventDefault();
// // Perform custom logic
// var meetsRequirement = true;
// // Continue with the update and state transition if logic allows
// if (meetsRequirement) $urlRouter.sync();
// });

// $rootScope.$on('$viewContentLoading', function(event, viewConfig) {
// console.log(viewConfig);
// // Access to all the view config properties.
// // and one special property 'targetView'
// // viewConfig.targetView
// });

// $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
// console.log('$stateChangeStart');
// });
// $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
// console.log('$stateChangeSuccess');
// });
// $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) {
// console.log('$stateChangeError:');
// console.log(error);
// });

}])

// gonzo.config([
// '$locationProvider', '$routeProvider', 'RestangularProvider',
// function($locationProvider, $routeProvider, RestangularProvider) {
// api_token = {'X-CSRF-Token':$('meta[name=csrf-token]').attr('content')};
// $locationProvider.html5Mode(true);
// $routeProvider.when('/releases/', {
// templateUrl: '/assets/releases/index.html',
// controller: 'ReleaseListCtrl'
// });
// $routeProvider.when('/releases/refresh', {
// templateUrl: '/assets/releases/index.html',
// controller: 'ReleaseListCtrl',
// resolve: {
// release: function(Restangular, $route) {
// return Restangular.one('releases').customPUT(null, 'refresh', null, api_token);
// }
// }
// });
// $routeProvider.when('/releases/:version', {
// templateUrl: '/assets/releases/view.html',
// controller: 'ReleaseEditCtrl',
// resolve: {
// release: function(Restangular, $route) {
// return Restangular.one('releases', $route.current.params.version).get();
// }
// }
// });
// $routeProvider.when('/releases/:version/check', {
// templateUrl: '/assets/releases/summary.html',
// controller: 'ChangeCtrl',
// resolve: {
// release: function(Restangular, $route) {
// return Restangular.one('releases', $route.current.params.version).customPUT(null, 'check', null, api_token);
// }
// }
// });
// $routeProvider.when('/releases/:version/summary', {
// templateUrl: '/assets/releases/summary.html',
// controller: 'ChangeCtrl'
// });
// $routeProvider.when('/releases/:version/changes', {
// templateUrl: '/assets/releases/changes.html',
// controller: 'ChangeCtrl'
// });
// $routeProvider.when('/releases/:version/reports', {
// templateUrl: '/assets/releases/reports.html',
// controller: 'ChangeCtrl'
// });
// $routeProvider.when('/nodes/:nodeId', {
// templateUrl: '/assets/nodes/view.html',
// controller: 'NodeCtrl'
// });
// $routeProvider.when('/nodes/', {
// templateUrl: '/assets/nodes/index.html',
// controller: 'NodeCtrl'
// });
// $routeProvider.when('/agents/:name', {
// templateUrl: '/assets/agents/view.html',
// controller: 'AgentCtrl'
// });
// $routeProvider.when('/agents/', {
// templateUrl: '/assets/agents/index.html',
// controller: 'AgentCtrl'
// });

// // NEW!
// $routeProvider.when('/', {
// templateUrl: '/assets/gonzo.html',
// controller: 'GonzoCtrl'
// });
// RestangularProvider.setBaseUrl('/api/v1');
// }
// ]);

// TODO: This breaks CouchDB, but without it we need to specify api_token in individual Restangular callss
// gonzo.config([
// "$httpProvider", function(provider) {
// return provider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content');
// },
// ]);
}])

0 comments on commit eee32ce

Please sign in to comment.