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

migrate code from googleapis/nodejs-org-policy #2806

Merged
merged 25 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f906ff8
feat!: initial stub of library
sofisl Feb 17, 2021
f333d53
feat: add tests and samples to library
sofisl Feb 17, 2021
7540483
chore: release 1.0.0
release-please[bot] Feb 24, 2021
1c04140
chore: release 1.0.1 (#23)
release-please[bot] May 13, 2021
88029da
chore: release 1.0.2 (#31)
release-please[bot] May 25, 2021
c3eec17
chore: release 1.0.3 (#38)
release-please[bot] Jun 29, 2021
e80f285
chore: release 1.0.4 (#43)
release-please[bot] Jun 30, 2021
3f405f8
chore: release 1.0.5 (#45)
release-please[bot] Jul 13, 2021
61bf1e8
chore: release 1.0.6 (#47)
release-please[bot] Jul 16, 2021
cc1c488
chore: release 1.0.7 (#55)
release-please[bot] Aug 17, 2021
adaa370
chore: release 1.1.0 (#57)
release-please[bot] Aug 23, 2021
90301a4
fix(build): switch primary branch to main (#60)
bcoe Sep 9, 2021
eb68f35
chore: release 1.1.1 (#61)
release-please[bot] Sep 9, 2021
193ef3d
chore(main): release 1.1.2 (#91)
release-please[bot] Feb 16, 2022
2229978
build!: update library to use Node 12 (#108)
sofisl May 20, 2022
5c9aaa8
chore(main): release 2.0.0 (#110)
release-please[bot] Jun 6, 2022
ab62c9c
chore(main): release 2.0.1 (#116)
release-please[bot] Jun 30, 2022
ecf5cd2
chore(main): release 2.0.2 (#123)
release-please[bot] Aug 26, 2022
7ad8630
Merge remote-tracking branch 'migration/main' into nodejs-org-policy-…
kweinmeister Nov 7, 2022
8d4ba48
add workflow, update README and CODEOWNERS
kweinmeister Nov 7, 2022
c644abb
update workflow
kweinmeister Nov 7, 2022
10918b5
update README typo
kweinmeister Nov 7, 2022
ecc1e38
update path to orgpolicy
kweinmeister Nov 8, 2022
d47dc20
changed filename to orgpolicy
kweinmeister Nov 8, 2022
45d9293
Merge branch 'main' into nodejs-org-policy-migration
kweinmeister Nov 8, 2022
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
67 changes: 67 additions & 0 deletions .github/workflows/org-policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: orgpolicy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking: should we standardize the use of hyphen or no hyphen in org-policy?

on:
push:
branches:
- main
paths:
- "orgpolicy/**"
pull_request:
paths:
- "orgpolicy/**"
pull_request_target:
types: [labeled]
schedule:
- cron: "0 0 * * 0"
jobs:
test:
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }}
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: "write"
pull-requests: "write"
id-token: "write"
steps:
- uses: actions/[email protected]
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- uses: "google-github-actions/[email protected]"
with:
workload_identity_provider: "projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider"
service_account: "[email protected]"
create_credentials_file: "true"
access_token_lifetime: 600s
- uses: actions/[email protected]
with:
node-version: 16
- run: npm install
working-directory: orgpolicy
- run: npm test
working-directory: orgpolicy
env:
MOCHA_REPORTER_SUITENAME: org_policy
MOCHA_REPORTER_OUTPUT: org_policy_sponge_log.xml
MOCHA_REPORTER: xunit
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
await github.rest.issues.removeLabel({
name: 'actions:force-run',
owner: 'GoogleCloudPlatform',
repo: 'nodejs-docs-samples',
issue_number: context.payload.pull_request.number
});
} catch (e) {
if (!e.message.includes('Label does not exist')) {
throw e;
}
}
- if: ${{ github.event_name == 'schedule'}}
run: |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L
chmod +x ./flakybot
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
1 change: 1 addition & 0 deletions .github/workflows/workflows.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"healthcare/hl7v2",
"monitoring/opencensus",
"monitoring/prometheus",
"orgpolicy",
"datacatalog/cloud-client",
"datacatalog/quickstart",
"datastore/functions"
Expand Down
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ cloud-tasks @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/nodejs-samples-r
workflows @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/nodejs-samples-reviewers
eventarc @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/nodejs-samples-reviewers

# Infrastructure
orgpolicy @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers

# Other functions samples
functions/scheduleinstance @askmeegs @GoogleCloudPlatform/nodejs-samples-reviewers
functions/speech-to-speech @ricalo @GoogleCloudPlatform/nodejs-samples-reviewers
Expand Down
48 changes: 48 additions & 0 deletions orgpolicy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# [Organization Policy: Node.js Samples](https://github.com/GoogleCloudPlatform/nodejs-docs-samples)

[![Open in Cloud Shell][shell_img]][shell_link]



## Table of Contents

- [Organization Policy: Node.js Samples](#organization-policy-nodejs-samples)
- [Table of Contents](#table-of-contents)
- [Before you begin](#before-you-begin)
- [Samples](#samples)
- [Quickstart](#quickstart)

## Before you begin

Before running the samples, make sure you've followed the steps outlined in
[Using the client library](https://github.com/googleapis/nodejs-org-policy#using-the-client-library).

`npm install`

`cd ..`

## Samples



### Quickstart

View the [source code](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/orgpolicy/quickstart.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/nodejs-docs-samples&page=editor&open_in_editor=orgpolicy/quickstart.js,orgpolicy/README.md)

__Usage:__


`node quickstart.js`






[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/nodejs-docs-samples&page=editor&open_in_editor=orgpolicy/README.md
[product-docs]: https://cloud.google.com/resource-manager/docs/organization-policy/overview
23 changes: 23 additions & 0 deletions orgpolicy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "nodejs-org-policy",
"private": true,
"license": "Apache-2.0",
"author": "Google LLC",
"engines": {
"node": ">=12.0.0"
},
"files": [
"*.js"
],
"scripts": {
"test": "c8 mocha --timeout 600000 test/*.js"
},
"dependencies": {
"@google-cloud/org-policy": "^2.0.2"
},
"devDependencies": {
"c8": "^7.1.0",
"chai": "^4.2.0",
"mocha": "^8.0.0"
}
}
49 changes: 49 additions & 0 deletions orgpolicy/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

'use strict';

async function main(projectId) {
// [START nodejs_org_policy_quickstart]
// Imports the Google Cloud client library

// remove this line after package is released
// eslint-disable-next-line node/no-missing-require
const {OrgPolicyClient} = require('@google-cloud/org-policy');

// TODO(developer): replace with your prefered project ID.
// const projectId = 'my-project'

// Creates a client
// eslint-disable-next-line no-unused-vars
const client = new OrgPolicyClient();

//TODO(library generator): write the actual function you will be testing
async function listConstraints() {
const constraints = await client.listConstraints({
parent: `projects/${projectId}`,
});
console.info(constraints);
}
listConstraints();
// [END nodejs_org_policy_quickstart]
}

main(...process.argv.slice(2)).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
43 changes: 43 additions & 0 deletions orgpolicy/test/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

'use strict';

const path = require('path');
const cp = require('child_process');
const {before, describe, it} = require('mocha');
const {OrgPolicyClient} = require('@google-cloud/org-policy');
const {assert} = require('chai');

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const cwd = path.join(__dirname, '..');

const client = new OrgPolicyClient();

describe('Quickstart', () => {
let projectId;

before(async () => {
projectId = await client.getProjectId();
});

it('should run quickstart', async () => {
const stdout = execSync(`node ./quickstart.js ${projectId}`, {cwd});
assert.match(stdout, /\[[\s\S]*\]/);
});
});