Skip to content

Commit

Permalink
feat(core): mutating request debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeach authored and anotherchrisberry committed May 10, 2017
1 parent 91bd4c1 commit 6303629
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/scripts/modules/core/core.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {REPLACE_FILTER} from './filter/replace.filter';
import {PIPELINE_TEMPLATE_MODULE} from './pipeline/config/templates/pipelineTemplate.module';
import {HEALTH_COUNTS_COMPONENT} from './healthCounts/healthCounts.component';
import {CORE_PAGETITLE_SERVICE} from './pageTitle/pageTitle.service';
import {INTERCEPTOR_MODULE} from './interceptor/interceptor.module';

require('../../../fonts/spinnaker/icons.css');

Expand Down Expand Up @@ -95,6 +96,7 @@ module.exports = angular

INSIGHT_NGMODULE.name,
require('./instance/instance.module.js'),
INTERCEPTOR_MODULE,

require('./loadBalancer/loadBalancer.module.js'),

Expand Down
32 changes: 32 additions & 0 deletions app/scripts/modules/core/interceptor/debug.interceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {module, IRequestConfig, IHttpInterceptor, IHttpProvider} from 'angular';
import {$log, $location} from 'ngimport';
import {JSON_UTILITY_SERVICE, JsonUtilityService} from 'core/utils/json/json.utility.service';
import autoBindMethods from 'class-autobind-decorator';

@autoBindMethods
export class DebugInterceptor implements IHttpInterceptor {

constructor(private jsonUtilityService: JsonUtilityService) { 'ngInject'; }

public request(config: IRequestConfig): IRequestConfig {
try { // This is a great opportunity to break Deck, so be careful.
this.logMutatingRequest(config);
} catch (e) {
$log.warn('Debug interceptor bug: ', e.message);
}
return config;
}

private logMutatingRequest(config: IRequestConfig): void {
if ($location.url() &&
$location.url().includes('debug=true') &&
['POST', 'PUT', 'DELETE'].includes(config.method)) {
$log.log(`${config.method}: ${config.url} \n`, this.jsonUtilityService.makeSortedStringFromObject(config.data));
}
}
}

export const DEBUG_INTERCEPTOR = 'spinnaker.core.debug.interceptor';
module(DEBUG_INTERCEPTOR, [JSON_UTILITY_SERVICE])
.service('debugInterceptor', DebugInterceptor)
.config(($httpProvider: IHttpProvider) => $httpProvider.interceptors.push('debugInterceptor'));
8 changes: 8 additions & 0 deletions app/scripts/modules/core/interceptor/interceptor.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {module} from 'angular';

import {DEBUG_INTERCEPTOR} from './debug.interceptor';

export const INTERCEPTOR_MODULE = 'spinnaker.core.interceptor.module';
module(INTERCEPTOR_MODULE, [
DEBUG_INTERCEPTOR,
]);
4 changes: 4 additions & 0 deletions app/scripts/modules/core/navigation/state.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export class StateConfigProvider implements IServiceProvider {
private root: INestedState = {
name: 'home',
abstract: true,
url: '?{debug:boolean}',
params: {
debug: { dynamic: true }
},
children: [],
};

Expand Down

0 comments on commit 6303629

Please sign in to comment.