Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for permissions props #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/cdkactions/src/job.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Construct } from 'constructs';
import { StringMap, RunProps, DefaultsProps } from './types';
import { StringMap, RunProps, DefaultsProps, PermissionsProps } from './types';
import { renameKeys } from './utils';
import { Workflow } from './workflow';

Expand Down Expand Up @@ -193,6 +193,12 @@ export interface JobProps {
* Additional Docker services provided to the job.
*/
readonly services?: { [key: string]: DockerProps };

/**
* Modifies the default permissions granted to the GITHUB_TOKEN
* https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idpermissions
*/
readonly permissions?: PermissionsProps;
}

/**
Expand Down
21 changes: 21 additions & 0 deletions packages/cdkactions/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,24 @@ export interface DefaultsProps {
*/
readonly [key: string]: any;
}

/**
* Permissions to apply to all scopes
*/
export type PermissionAccessAll = 'read-all' | 'write-all';

/**
* Permissions to apply to individual scopes
*/
export type PermissionAccess = 'read' | 'write' | 'none';

/**
* All available permission scopes
*/
export type PermissionScope = 'actions' | 'checks' | 'contents' | 'deployments' | 'id-token' | 'issues' | 'discussions' | 'packages' | 'pages' | 'pull-requests' | 'repository-projects' | 'security-events' | 'statuses';

/**
* Configuration for permissions
*/
export type PermissionsProps = PermissionAccessAll | Partial<Record<PermissionScope, PermissionAccess>>;

8 changes: 7 additions & 1 deletion packages/cdkactions/src/workflow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Construct, Node } from 'constructs';
import { Job } from './job';
import { StringMap, DefaultsProps } from './types';
import { StringMap, DefaultsProps, PermissionsProps } from './types';
import { renameKeys, camelToSnake } from './utils';

/**
Expand Down Expand Up @@ -347,6 +347,12 @@ export interface WorkflowProps {
*/
readonly on: Events | Array<Events> | EventMap | ScheduleEvent | WorkflowRunEvent;

/**
* Modifies the default permissions granted to the GITHUB_TOKEN
* https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#permissions
*/
readonly permissions?: PermissionsProps;

/**
* A map of environment variables to provide to the job.
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/cdkactions/test/__snapshots__/job.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
exports[`toGHAction 1`] = `
Object {
"continue-on-error": true,
"permissions": Object {
"contents": "write",
"id-token": "write",
},
"runs-on": "ubuntu-latest",
"steps": Array [
Object {
Expand Down
4 changes: 4 additions & 0 deletions packages/cdkactions/test/__snapshots__/workflow.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ Object {
],
},
},
"permissions": Object {
"contents": "write",
"id-token": "write",
},
}
`;
4 changes: 4 additions & 0 deletions packages/cdkactions/test/job.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ test('toGHAction', () => {
fastFail: true,
maxParallel: 11,
},
permissions: {
'id-token': 'write',
'contents': 'write',
},
steps: [{
name: 'step',
continueOnError: false,
Expand Down
4 changes: 4 additions & 0 deletions packages/cdkactions/test/workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ test('toGHAction', () => {
workingDirectory: '~/',
},
},
permissions: {
'id-token': 'write',
'contents': 'write',
},
});
expect(workflow.toGHAction()).toMatchSnapshot();
});
Expand Down