Skip to content

Commit

Permalink
feat: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
luhanamz committed Sep 9, 2021
1 parent b7dda25 commit c0c01d5
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DEPLOYMENT_MECHANISM } from './base-api-stack';
import { GitHubSourceActionInfo } from './pipeline-with-awaiter';
import { API_TYPE, IMAGE_SOURCE_TYPE, ResourceDependency, ServiceConfiguration } from './service-walkthroughs/containers-walkthrough';
import { ApiResource, generateContainersArtifacts } from './utils/containers-artifacts';
import { createDefaultCustomPoliciesFile, pathManager } from "amplify-cli-core";
import { createDefaultCustomPoliciesFile, pathManager } from 'amplify-cli-core';

export const addResource = async (
serviceWalkthroughPromise: Promise<ServiceConfiguration>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ export async function addFunctionResource(

const { print } = context;


const customPoliciesPath = pathManager.getCustomPoliciesPath(category, completeParams.resourceName);

print.success(`Successfully added resource ${completeParams.resourceName} locally.`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {createDefaultCustomPoliciesFile} from "../customPoliciesUtils"
import { JSONUtilities } from "..";
import { pathManager, PathConstants } from "../state-manager";
import {createDefaultCustomPoliciesFile} from '../customPoliciesUtils'
import { JSONUtilities } from '..';
import { pathManager, PathConstants } from '../state-manager';
import path from 'path';

describe('Custom policies util test', () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/amplify-cli-core/src/customPoliciesUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Fn, IAM } from 'cloudform-types';
import * as iam from '@aws-cdk/aws-iam';
import { JSONUtilities, pathManager } from '.';

export type CustomIAMPolicies = CustomIAMPolicy[];
Expand All @@ -17,7 +16,7 @@ export const CustomIAMPoliciesSchema = {
type: 'object',
properties: {
Action: { type: 'array', items: { type: 'string' }, minItems: 1, nullable: false },
Effect: {type: 'string', nullable: true, default: iam.Effect.ALLOW},
Effect: {enum:['Allow', 'Deny'], nullable: true, default: 'Allow'},
Resource: { type: 'array', items: { type: 'string' }, minItems: 1, nullable: false},
},
required: ['Resource', 'Action'],
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-cli-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export * from './cliGetCategories';
export * from './cliRemoveResourcePrompt';
export * from './cliViewAPI';
export * from './hooks';
export * from "./cliViewAPI";
export * from './cliViewAPI';
export * from './customPoliciesUtils'

// Temporary types until we can finish full type definition across the whole CLI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ describe('preProcessCFNTemplate', () => {
it('writes valid custom policies to cfn template', async () => {
const cfnTemplate = ({
Resources: {
"LambdaExecutionRole": {
"Type": "AWS::IAM::Role"
LambdaExecutionRole: {
Type: 'AWS::IAM::Role'
}
},
} as unknown) as Template;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { prePushCfnTemplateModifier } from './pre-push-cfn-modifier';
import { Fn, Template } from 'cloudform-types';
import { printer } from 'amplify-prompts';
import Ajv from 'ajv';
import * as iam from '@aws-cdk/aws-iam';


const buildDir = 'build';
Expand Down Expand Up @@ -84,11 +83,11 @@ async function addCustomPoliciesToCFNTemplate(
resourceName: string
) {
let customExecutionPolicy;
if(service === 'Lambda') {
if (service === 'Lambda') {
customExecutionPolicy = customExecutionPolicyForFunction;
}
if (service === 'ElasticContainer') {
const roleName = cfnTemplate.Resources.TaskDefinition.Properties.ExecutionRoleArn["Fn::GetAtt"][0];
const roleName = cfnTemplate.Resources.TaskDefinition.Properties.ExecutionRoleArn['Fn::GetAtt'][0];
customExecutionPolicy = customExecutionPolicyForContainer;
const role = Fn.Ref(roleName);
customExecutionPolicy.Properties.Roles.push(role);
Expand All @@ -99,7 +98,7 @@ async function addCustomPoliciesToCFNTemplate(
for (const customPolicy of customPolicies) {
validateCustomPolicy(customPolicy, category, resourceName);
const policyWithEnv = replaceEnvForCustomPolicies(customPolicy);
if (!policyWithEnv.Effect) policyWithEnv.Effect = iam.Effect.ALLOW;
if (!policyWithEnv.Effect) policyWithEnv.Effect = 'Allow';
customExecutionPolicy.Properties.PolicyDocument.Statement.push(policyWithEnv);
}

Expand Down

0 comments on commit c0c01d5

Please sign in to comment.