Skip to content

Commit

Permalink
chore: switch to writeSecureFile from actions-utils (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo committed Mar 18, 2022
1 parent a54bf4e commit 622063f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 28 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dependencies": {
"@actions/core": "^1.6.0",
"@actions/tool-cache": "^1.7.1",
"@google-github-actions/actions-utils": "^0.1.2",
"@google-github-actions/actions-utils": "^0.1.6",
"@google-github-actions/setup-cloud-sdk": "^0.5.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/setup-gcloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import {
errorMessage,
isPinnedToHead,
pinnedToHeadWarning,
writeSecureFile,
} from '@google-github-actions/actions-utils';
import { writeSecureFile } from './utils';
import path from 'path';
import crypto from 'crypto';

Expand Down
18 changes: 0 additions & 18 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@

import { promises as fs } from 'fs';

/**
* writeSecureFile writes a file to disk in a given directory with a
* random name.
*
* @param outputPath Path in which to create random file in.
* @param data Data to write to file.
* @returns Path to written file.
*/
export async function writeSecureFile(
outputPath: string,
data: string,
): Promise<string> {
// Write the file as 0640 so the owner has RW, group as R, and the file is
// otherwise unreadable. Also write with EXCL to prevent a symlink attack.
await fs.writeFile(outputPath, data, { mode: 0o640, flag: 'wx' });
return outputPath;
}

/**
* removeExportedCredentials removes any exported credentials file. If the file
* does not exist, it does nothing.
Expand Down
3 changes: 2 additions & 1 deletion tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import { tmpdir } from 'os';
import crypto from 'crypto';
import path from 'path';

import { writeSecureFile } from '@google-github-actions/actions-utils';

import { removeExportedCredentials } from '../src/utils';
import { writeSecureFile } from '../src/utils';

describe('post', () => {
describe('#removeExportedCredentials', () => {
Expand Down

0 comments on commit 622063f

Please sign in to comment.