Skip to content

Commit

Permalink
fix(action): add scope fully qualified name to additional cidr entry (#1
Browse files Browse the repository at this point in the history
)

Co-authored-by: kty1965 <[email protected]>
  • Loading branch information
kty1965 and kty1965 authored Feb 16, 2024
1 parent 6e9c9a2 commit c5aae03
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 46 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ A GitHub Action that will load Enterprise IP Allow List Entries from the [GitHub
| `scope` | false | default: `@scope`, select prefix of name |
| `mode` | false | default: `sync`, mode `sync`, `delete` available |

## Environments

| name | description |
| ----------------- | ------------------------------------------- |
| `API_CONCURRENCY` | using request to github graphql concurrency |

## Examples

> if you change input `scope` already created allowlist does not changed.
Expand Down
30 changes: 26 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33879,6 +33879,19 @@ function CreateGithubClient(token, maxRetries) {
}


/***/ }),

/***/ 4438:
/***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {

"use strict";
__nccwpck_require__.r(__webpack_exports__);
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
/* harmony export */ "FULLY_QUALIFIED_SCOPE_FUNC": () => (/* binding */ FULLY_QUALIFIED_SCOPE_FUNC)
/* harmony export */ });
const FULLY_QUALIFIED_SCOPE_FUNC = (scope) => `${scope} made by github action`;


/***/ }),

/***/ 4521:
Expand Down Expand Up @@ -34050,6 +34063,7 @@ const Bottleneck = __nccwpck_require__(7356);
const { Octokit } = __nccwpck_require__(5375);
const _ = __nccwpck_require__(5067);
const { env } = __nccwpck_require__(4521);
const { FULLY_QUALIFIED_SCOPE_FUNC } = __nccwpck_require__(4438);

const {
CreateIpAllowListEntryCommand,
Expand All @@ -34068,12 +34082,12 @@ async function getMetaCIDRs({ metadataKey }) {
return metadata[metadataKey];
}

async function getMetaCidrEntries({ metadataKey }) {
async function getMetaCidrEntries({ metadataKey, scope }) {
const cidrs = await getMetaCIDRs({ metadataKey });
const cidrEntries = cidrs.map(
(cidr) =>
new CidrEntry({
name: '@scope made by github action',
name: FULLY_QUALIFIED_SCOPE_FUNC(scope),
cidr,
isActive: true,
}),
Expand All @@ -34087,7 +34101,14 @@ function getAdditionalCidrEntries(value) {
try {
const parsedCidrEntries = YAML.parse(value);
core.debug(`yaml parse: ${JSON.stringify(parsedCidrEntries)}`);
cidrEntries = parsedCidrEntries.map((cidrEntry) => new CidrEntry(cidrEntry));
cidrEntries = parsedCidrEntries.map(
(cidrEntry) =>
new CidrEntry({
name: `${FULLY_QUALIFIED_SCOPE_FUNC(scope)} ${cidrEntry.name}`,
cidr: cidrEntry.cidr,
isActive: cidrEntry.isActive,
}),
);
core.debug(`getAdditionalCidrEntries: ${JSON.stringify(cidrEntries)}`);
} catch (err) {
throw new Error(`additionalCidrEntries yaml string cannot parse ${err}`);
Expand Down Expand Up @@ -46801,6 +46822,7 @@ async function run() {
const metadataKey = core.getInput('metadata_key');
const additionalCidrEntries = core.getInput('additional_cidr_entries');
const scope = core.getInput('scope');
const mode = core.getInput('mode');

const octokit = CreateGithubClient(githubToken);

Expand All @@ -46816,7 +46838,7 @@ async function run() {
});

if (metadataKey) {
const cidrEntries = await getMetaCidrEntries({ metadataKey });
const cidrEntries = await getMetaCidrEntries({ metadataKey, scope });
if (cidrEntries) {
expectCidrEntries.push(...cidrEntries);
} else {
Expand Down
39 changes: 0 additions & 39 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"@octokit/plugin-throttling": "^8.1.3",
"@octokit/rest": "^20.0.2",
"bottleneck": "^2.19.5",
"p-limit": "^5.0.0",
"underscore": "^1.13.6",
"yaml": "^2.3.4"
},
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const FULLY_QUALIFIED_SCOPE_FUNC = (scope) => `${scope} made by github action`;
12 changes: 10 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Bottleneck = require('bottleneck');
const { Octokit } = require('@octokit/rest');
const _ = require('underscore');
const { env } = require('./env');
const { FULLY_QUALIFIED_SCOPE_FUNC } = require('./constants');

const {
CreateIpAllowListEntryCommand,
Expand All @@ -28,7 +29,7 @@ export async function getMetaCidrEntries({ metadataKey, scope }) {
const cidrEntries = cidrs.map(
(cidr) =>
new CidrEntry({
name: `${scope} made by github action`,
name: FULLY_QUALIFIED_SCOPE_FUNC(scope),
cidr,
isActive: true,
}),
Expand All @@ -42,7 +43,14 @@ export function getAdditionalCidrEntries(value) {
try {
const parsedCidrEntries = YAML.parse(value);
core.debug(`yaml parse: ${JSON.stringify(parsedCidrEntries)}`);
cidrEntries = parsedCidrEntries.map((cidrEntry) => new CidrEntry(cidrEntry));
cidrEntries = parsedCidrEntries.map(
(cidrEntry) =>
new CidrEntry({
name: `${FULLY_QUALIFIED_SCOPE_FUNC(scope)} ${cidrEntry.name}`,
cidr: cidrEntry.cidr,
isActive: cidrEntry.isActive,
}),
);
core.debug(`getAdditionalCidrEntries: ${JSON.stringify(cidrEntries)}`);
} catch (err) {
throw new Error(`additionalCidrEntries yaml string cannot parse ${err}`);
Expand Down

0 comments on commit c5aae03

Please sign in to comment.