Skip to content

Commit

Permalink
fix(titus): Make iamProfile a required field in the UI and offer to f…
Browse files Browse the repository at this point in the history
…ill in the default value if it's missing. (#8434)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
christopherthielen and mergify[bot] committed Jul 27, 2020
1 parent e9363b4 commit 0b392c5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ export const name = TITUS_SERVERGROUP_CONFIGURE_SERVERGROUPCOMMANDBUILDER; // fo
angular.module(TITUS_SERVERGROUP_CONFIGURE_SERVERGROUPCOMMANDBUILDER, []).factory('titusServerGroupCommandBuilder', [
'$q',
function($q) {
function getDefaultIamProfile(application) {
const defaultIamProfile = TitusProviderSettings.defaults.iamProfile || '{{application}}InstanceProfile';
return defaultIamProfile.replace('{{application}}', application.name);
}

function buildNewServerGroupCommand(application, defaults) {
defaults = defaults || {};

const defaultCredentials = defaults.account || TitusProviderSettings.defaults.account;
const defaultRegion = defaults.region || TitusProviderSettings.defaults.region;
const defaultZone = defaults.zone || TitusProviderSettings.defaults.zone;
let defaultIamProfile = TitusProviderSettings.defaults.iamProfile || '{{application}}InstanceProfile';
defaultIamProfile = defaultIamProfile.replace('{{application}}', application.name);
const defaultIamProfile = getDefaultIamProfile(application);

const command = {
application: application.name,
Expand Down Expand Up @@ -56,6 +60,7 @@ angular.module(TITUS_SERVERGROUP_CONFIGURE_SERVERGROUPCOMMANDBUILDER, []).factor
},
serviceJobProcesses: {},
viewState: {
defaultIamProfile,
useSimpleCapacity: true,
usePreferredZones: true,
mode: defaults.mode || 'create',
Expand Down Expand Up @@ -100,7 +105,7 @@ angular.module(TITUS_SERVERGROUP_CONFIGURE_SERVERGROUPCOMMANDBUILDER, []).factor
labels: serverGroup.labels,
containerAttributes: serverGroup.containerAttributes,
entryPoint: serverGroup.entryPoint,
iamProfile: serverGroup.iamProfile || application.name + 'InstanceProfile',
iamProfile: serverGroup.iamProfile,
capacityGroup: serverGroup.capacityGroup,
migrationPolicy: serverGroup.migrationPolicy ? serverGroup.migrationPolicy : { type: 'systemDefault' },
securityGroups: serverGroup.securityGroups || [],
Expand Down Expand Up @@ -131,6 +136,7 @@ angular.module(TITUS_SERVERGROUP_CONFIGURE_SERVERGROUPCOMMANDBUILDER, []).factor
cloudProvider: 'titus',
selectedProvider: 'titus',
viewState: {
defaultIamProfile: getDefaultIamProfile(application),
useSimpleCapacity: serverGroup.capacity.min === serverGroup.capacity.max,
mode: mode,
},
Expand Down Expand Up @@ -197,11 +203,13 @@ angular.module(TITUS_SERVERGROUP_CONFIGURE_SERVERGROUPCOMMANDBUILDER, []).factor
useSimpleCapacity: originalCluster.capacity.min === originalCluster.capacity.max,
mode: 'editPipeline',
submitButtonLabel: 'Done',
defaultIamProfile: getDefaultIamProfile(application),
};

const viewOverrides = {
region: pipelineCluster.region,
credentials: pipelineCluster.account,
iamProfile: pipelineCluster.iamProfile,
viewState: viewState,
};

Expand All @@ -212,10 +220,10 @@ angular.module(TITUS_SERVERGROUP_CONFIGURE_SERVERGROUPCOMMANDBUILDER, []).factor
}

return {
buildNewServerGroupCommand: buildNewServerGroupCommand,
buildNewServerGroupCommandForPipeline: buildNewServerGroupCommandForPipeline,
buildServerGroupCommandFromExisting: buildServerGroupCommandFromExisting,
buildServerGroupCommandFromPipeline: buildServerGroupCommandFromPipeline,
buildNewServerGroupCommand,
buildNewServerGroupCommandForPipeline,
buildServerGroupCommandFromExisting,
buildServerGroupCommandFromPipeline,
};
},
]);
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface ITitusServerGroupCommandViewState extends IServerGroupCommandVi
regionChangedStream: Subject<{}>;
groupsRemovedStream: Subject<{}>;
dirty: IAmazonServerGroupCommandDirty;
defaultIamProfile: string;
}

export const defaultJobDisruptionBudget: IJobDisruptionBudget = {
Expand Down Expand Up @@ -97,6 +98,7 @@ export interface ITitusServerGroupCommand extends IServerGroupCommand {
labels: { [key: string]: string };
containerAttributes: { [key: string]: string };
env: { [key: string]: string };
iamProfile: string;
migrationPolicy: {
type: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export class ServerGroupParameters extends React.Component<IServerGroupParameter
if (this.duplicateKeys.env) {
errors.env = 'Environment Variables have duplicate keys.';
}
if (!_values.iamProfile) {
errors.iamProfile = 'IAM Profile is required.';
}

const duplicateConstraints = intersection(Object.keys(softConstraints), Object.keys(hardConstraints));
if (duplicateConstraints.length > 0) {
Expand All @@ -72,8 +75,9 @@ export class ServerGroupParameters extends React.Component<IServerGroupParameter

public render() {
const { app } = this.props;
const { setFieldValue, values } = this.props.formik;
const { setFieldValue, values, errors } = this.props.formik;

const setDefaultIamProfile = () => setFieldValue('iamProfile', values.viewState.defaultIamProfile);
return (
<>
<div className="form-group">
Expand All @@ -85,14 +89,18 @@ export class ServerGroupParameters extends React.Component<IServerGroupParameter
<Field type="text" className="form-control input-sm no-spel" name="iamProfile" />
</div>
<div className="col-md-1 small" style={{ whiteSpace: 'nowrap', paddingLeft: '0px', paddingTop: '7px' }}>
in{' '}
<AccountTag
account={
values.backingData.credentialsKeyedByAccount[values.credentials] &&
values.backingData.credentialsKeyedByAccount[values.credentials].awsAccount
}
/>
in <AccountTag account={values.backingData.credentialsKeyedByAccount[values.credentials]?.awsAccount} />
</div>
{errors.iamProfile && (
<div className="col-md-8 col-md-offset-4">
<div className="flex-container-h baseline">
<span className="error-message">{errors.iamProfile}</span>
<button className="link" onClick={setDefaultIamProfile}>
Apply default value
</button>
</div>
</div>
)}
</div>
<div className="form-group">
<div className="col-md-4 sm-label-right">
Expand Down

0 comments on commit 0b392c5

Please sign in to comment.