Skip to content

Commit

Permalink
fix(*): Use allowlist and denylist (#8351)
Browse files Browse the repository at this point in the history
  • Loading branch information
caseyhebebrand committed Jun 17, 2020
1 parent ad13e35 commit 579560d
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions app/scripts/modules/amazon/src/aws.settings.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { IProviderSettings, SETTINGS } from '@spinnaker/core';

export interface IClassicLaunchWhitelist {
export interface IClassicLaunchAllowlist {
region: string;
credentials: string;
}

export interface IAWSProviderSettings extends IProviderSettings {
classicLaunchLockout?: number;
classicLaunchWhitelist?: IClassicLaunchWhitelist[];
classicLaunchAllowlist?: IClassicLaunchAllowlist[];
createLoadBalancerWarnings?: {
application?: string;
classic?: string;
Expand Down
6 changes: 3 additions & 3 deletions app/scripts/modules/amazon/src/subnet/SubnetSelectInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export class SubnetSelectInput extends React.Component<ISubnetSelectInputProps,
public state: ISubnetSelectInputState = { options: [] };

private isClassicLockout(region: string, credentials: string, application: Application): boolean {
const { classicLaunchLockout, classicLaunchWhitelist: whitelist } = AWSProviderSettings;
const { classicLaunchLockout, classicLaunchAllowlist: allowlist } = AWSProviderSettings;

const appCreationDate = Number(get(application, 'attributes.createTs', 0));
const appCreatedAfterLockout = appCreationDate > (classicLaunchLockout || 0);
const isWhitelisted = !!whitelist && whitelist.some(e => e.region === region && e.credentials === credentials);
return appCreatedAfterLockout || !isWhitelisted;
const isAllowlisted = !!allowlist && allowlist.some(e => e.region === region && e.credentials === credentials);
return appCreatedAfterLockout || !isAllowlisted;
}

private getOptions(subnets: ISubnet[], isClassicHidden: boolean): Array<Option<string>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface IExecutionWindowActionsState {
dayText: string;
}

export interface IExecutionWindowWhitelistEntry {
export interface IExecutionWindowAllowlistEntry {
startHour: number;
startMin: number;
endHour: number;
Expand Down Expand Up @@ -82,7 +82,7 @@ export class ExecutionWindowActions extends React.Component<
<strong>Stage execution can only run:</strong>
<dl className="dl-narrow dl-horizontal">
{get(stage, 'context.restrictedExecutionWindow.whitelist', []).map(
(entry: IExecutionWindowWhitelistEntry, index: number) => {
(entry: IExecutionWindowAllowlistEntry, index: number) => {
return (
<div key={index}>
<dt>From</dt>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export const ExecutionWindows = (props: IExecutionWindowsConfigProps) => {
skipManual: false,
};
const jitter = get(props.restrictedExecutionWindow, 'jitter', defaultJitter);
const whitelist = get(props.restrictedExecutionWindow, 'whitelist', []);
const allowlist = get(props.restrictedExecutionWindow, 'whitelist', []);
const days = get(props.restrictedExecutionWindow, 'days', []);
const [timelineWindows, setTimelineWindows] = useState(getTimelineWindows(whitelist));
const [timelineWindows, setTimelineWindows] = useState(getTimelineWindows(allowlist));
const [enableCustomSkipWindowText, setEnableCustomSkipWindowText] = useState(!!props.skipWindowText);
const defaultSkipWindowText = DEFAULT_SKIP_WINDOW_TEXT;
const isWindowExpression =
Expand All @@ -49,8 +49,8 @@ export const ExecutionWindows = (props: IExecutionWindowsConfigProps) => {
}));

// if the user edits the stage as JSON, we'll get a re-render, but the state will be possibly stale, so reset
if (!isEqual(getTimelineWindows(whitelist), timelineWindows)) {
setTimelineWindows(getTimelineWindows(whitelist));
if (!isEqual(getTimelineWindows(allowlist), timelineWindows)) {
setTimelineWindows(getTimelineWindows(allowlist));
}

const jitterUpdated = (changes: Partial<IJitter>) => {
Expand Down Expand Up @@ -79,17 +79,17 @@ export const ExecutionWindows = (props: IExecutionWindowsConfigProps) => {
};
const restrictedExecutionWindow = {
...(props.restrictedExecutionWindow || {}),
whitelist: [...whitelist, newExecutionWindow],
whitelist: [...allowlist, newExecutionWindow],
};
props.updateStageField({ restrictedExecutionWindow });
};

const removeWindow = (index: number): void => {
const newWhitelist = [...whitelist];
newWhitelist.splice(index, 1);
const newAllowlist = [...allowlist];
newAllowlist.splice(index, 1);
const restrictedExecutionWindow = {
...props.restrictedExecutionWindow,
whitelist: newWhitelist,
whitelist: newAllowlist,
};
props.updateStageField({ restrictedExecutionWindow });
};
Expand All @@ -102,15 +102,15 @@ export const ExecutionWindows = (props: IExecutionWindowsConfigProps) => {
props.updateStageField({ restrictedExecutionWindow });
};

const updateWhitelist = (changes: Partial<IWindow>, index: number) => {
const newWhitelist = [...whitelist];
extend(newWhitelist[index], changes);
const updateAllowlist = (changes: Partial<IWindow>, index: number) => {
const newAllowlist = [...allowlist];
extend(newAllowlist[index], changes);
const restrictedExecutionWindow = {
...props.restrictedExecutionWindow,
whitelist: newWhitelist,
whitelist: newAllowlist,
};
props.updateStageField({ restrictedExecutionWindow });
setTimelineWindows(getTimelineWindows(newWhitelist));
setTimelineWindows(getTimelineWindows(newAllowlist));
};

function getTimelineWindows(w: IWindow[]): ITimelineWindow[] {
Expand Down Expand Up @@ -254,7 +254,7 @@ export const ExecutionWindows = (props: IExecutionWindowsConfigProps) => {
):
</p>
</div>
{whitelist.map((w: IWindow, i: number) => {
{allowlist.map((w: IWindow, i: number) => {
return (
<div className="window-entry" key={i}>
<div className="form-group">
Expand All @@ -266,7 +266,7 @@ export const ExecutionWindows = (props: IExecutionWindowsConfigProps) => {
value={w.startHour}
options={hours.map(h => ({ label: h.label, value: h.value }))}
onChange={(option: Option<number>) => {
updateWhitelist({ startHour: option.target.value }, i);
updateAllowlist({ startHour: option.target.value }, i);
}}
/>
<span> : </span>
Expand All @@ -276,7 +276,7 @@ export const ExecutionWindows = (props: IExecutionWindowsConfigProps) => {
value={w.startMin}
options={minutes.map(m => ({ label: m.label, value: m.value }))}
onChange={(option: Option<number>) => {
updateWhitelist({ startMin: option.target.value }, i);
updateAllowlist({ startMin: option.target.value }, i);
}}
/>
<span className="start-end-divider"> to </span>
Expand All @@ -286,7 +286,7 @@ export const ExecutionWindows = (props: IExecutionWindowsConfigProps) => {
value={w.endHour}
options={hours.map(h => ({ label: h.label, value: h.value }))}
onChange={(option: Option<number>) => {
updateWhitelist({ endHour: option.target.value }, i);
updateAllowlist({ endHour: option.target.value }, i);
}}
/>
<span> : </span>
Expand All @@ -296,7 +296,7 @@ export const ExecutionWindows = (props: IExecutionWindowsConfigProps) => {
value={w.endMin}
options={minutes.map(m => ({ label: m.label, value: m.value }))}
onChange={(option: Option<number>) => {
updateWhitelist({ endMin: option.target.value }, i);
updateAllowlist({ endMin: option.target.value }, i);
}}
/>
<Tooltip value={'Remove window'}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,23 @@ export class ExecutionFilterService {
}
}

private static getValuesAsString(object: any, blacklist: string[] = []): string {
private static getValuesAsString(object: any, denylist: string[] = []): string {
if (typeof object === 'string') {
return object;
}
if (typeof object === 'number') {
return '' + object;
}
if (object instanceof Array) {
return object.map(val => this.getValuesAsString(val, blacklist)).join(' ');
return object.map(val => this.getValuesAsString(val, denylist)).join(' ');
}
if (object instanceof Object) {
return Object.keys(object)
.map(key => {
if (blacklist.includes(key)) {
if (denylist.includes(key)) {
return '';
}
return this.getValuesAsString(object[key], blacklist);
return this.getValuesAsString(object[key], denylist);
})
.join(' ');
}
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/modules/core/src/task/displayableTasks.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { module } from 'angular';
import { ITaskStep } from 'core/domain';

export function displayableTasks(input: ITaskStep[]): ITaskStep[] {
const blacklist = ['stageStart', 'stageEnd', 'determineTargetServerGroup'];
const denylist = ['stageStart', 'stageEnd', 'determineTargetServerGroup'];

let result: ITaskStep[] = [];
if (input) {
result = input.filter((test: ITaskStep) => !blacklist.includes(test.name) || test.status === 'TERMINAL');
result = input.filter((test: ITaskStep) => !denylist.includes(test.name) || test.status === 'TERMINAL');
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class ManifestSelector extends React.Component<IManifestSelectorProps, IM
const { application, includeSpinnakerKinds } = this.props;
const { selector } = this.state;
const applications = application ? [application] : [];
// If the only whitelisted Spinnaker kind is `serverGroups`, exclude server groups with `serverGroupManagers`.
// If the only allowlisted Spinnaker kind is `serverGroups`, exclude server groups with `serverGroupManagers`.
// This is because traffic management stages only allow ReplicaSets.
const includeServerGroupsWithManagers: boolean =
isEmpty(includeSpinnakerKinds) || includeSpinnakerKinds.length > 1 || includeSpinnakerKinds[0] !== 'serverGroups';
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/modules/tencentcloud/src/tencentcloud.settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IProviderSettings, SETTINGS } from '@spinnaker/core';

export interface IClassicLaunchWhitelist {
export interface IClassicLaunchAllowlist {
region: string;
credentials: string;
}
Expand All @@ -18,7 +18,7 @@ export interface ITencentcloudProviderSettings extends IProviderSettings {
certificateTypes?: string[];
};
classicLaunchLockout?: number;
classicLaunchWhitelist?: IClassicLaunchWhitelist[];
classicLaunchAllowlist?: IClassicLaunchAllowlist[];
metrics?: {
customNamespaces?: string[];
};
Expand Down
6 changes: 3 additions & 3 deletions app/scripts/strictDi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ const angularJSModuleStrictDiHandler: ProxyHandler<any> = {
},
};

const whitelistedModules = ['ngMock'];
const allowlistedModules = ['ngMock'];
const realModule = angular.module;
(angular as any).module = function module() {
const angularModule = realModule.apply(this, arguments);
const isWhitelisted = whitelistedModules.includes(arguments[0]);
return isWhitelisted ? angularModule : new Proxy(angularModule, angularJSModuleStrictDiHandler);
const isAllowlisted = allowlistedModules.includes(arguments[0]);
return isAllowlisted ? angularModule : new Proxy(angularModule, angularJSModuleStrictDiHandler);
};
6 changes: 3 additions & 3 deletions packages/eslint-plugin/rules/ng-strictdi.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ const rule = function(context) {
function fromFunction(thisGuy) {
const { node: fn } = thisGuy;
const name = fn.type === 'FunctionDeclaration' ? fn.id.name : fn.name;
let params = fn.params.map(param => param.name);
let diStrings = getDiStrings(name);
const params = fn.params.map(param => param.name);
const diStrings = getDiStrings(name);
return { type: 'function', fn, name, params, diStrings };
}

Expand All @@ -181,7 +181,7 @@ const rule = function(context) {
return fromClassDeclaration(thisGuy);
case 'MemberExpression': {
const memberExpression = context.getSourceCode().getText(thisGuy.node);
// whitelist some known symbols
// allowlist some known symbols
if (!['angular.noop', 'noop'].includes(memberExpression)) {
console.warn(`Unable to handle MemberExpression: ${memberExpression}`);
}
Expand Down

0 comments on commit 579560d

Please sign in to comment.