Skip to content

Commit

Permalink
fix: naming on repo for status checks and submit samples (#11)
Browse files Browse the repository at this point in the history
* fix: naming on repo

* fix samples

* fix: pass naming

* fix: working samples
  • Loading branch information
sofisl committed Feb 23, 2021
1 parent 39f033e commit cc98680
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 52 deletions.
4 changes: 2 additions & 2 deletions packages/google-cloud-policytroubleshooter/.jsdoc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Google LLC
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,7 +40,7 @@ module.exports = {
includePattern: '\\.js$'
},
templates: {
copyright: 'Copyright 2020 Google LLC',
copyright: 'Copyright 2021 Google LLC',
includeDate: false,
sourceFiles: false,
systemName: '@google-cloud/policy-troubleshooter',
Expand Down
15 changes: 13 additions & 2 deletions packages/google-cloud-policytroubleshooter/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ accept your pull requests.
1. Title your pull request following [Conventional Commits](https://www.conventionalcommits.org/) styling.
1. Submit a pull request.

### Before you begin

1. [Select or create a Cloud Platform project][projects].
1. [Enable billing for your project][billing].
1. [Enable the IAM Policy Troubleshooter API API][enable_api].
1. [Set up authentication with a service account][auth] so you can access the
API from your local workstation.


## Running the tests

1. [Prepare your environment for Node.js setup][setup].
Expand All @@ -51,15 +60,17 @@ accept your pull requests.
npm test

# Run sample integration tests.
gcloud auth application-default login
npm run samples-test

# Run all system tests.
gcloud auth application-default login
npm run system-test

1. Lint (and maybe fix) any changes:

npm run fix

[setup]: https://cloud.google.com/nodejs/docs/setup
[projects]: https://console.cloud.google.com/project
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=policytroubleshooter.googleapis.com
[auth]: https://cloud.google.com/docs/authentication/getting-started
25 changes: 15 additions & 10 deletions packages/google-cloud-policytroubleshooter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,29 @@ npm install @google-cloud/policy-troubleshooter
```javascript
// Imports the Google Cloud client library

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

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

const options = {
keyfilePath,
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
};

// Creates a client
// eslint-disable-next-line no-unused-vars
const client = new {IamCheckerClient}();
const client = new IamCheckerClient(authenticate(options));

//TODO(library generator): write the actual function you will be testing
async function doSomething() {
console.log('Developer! Change this code so that it shows how to use the library! See comments below on structure.')
// const [thing] = await client.methodName({
// });
// console.info(thing);
const policy = await client.troubleshootIamPolicy({
accessTuple: {
principal,
fullResourceName,
permission,
},
});
console.log(policy);
}
doSomething();

Expand All @@ -86,8 +92,7 @@ doSomething();

## Samples

Samples are in the [`samples/`](https://github.com/googleapis/nodejs-policy-troubleshooter/tree/master/samples) directory. The samples' `README.md`
has instructions for running the samples.
Samples are in the [`samples/`](https://github.com/googleapis/nodejs-policy-troubleshooter/tree/master/samples) directory. Each sample's `README.md` has instructions for running its sample.

| Sample | Source Code | Try it |
| --------------------------- | --------------------------------- | ------ |
Expand Down
2 changes: 1 addition & 1 deletion packages/google-cloud-policytroubleshooter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@google-cloud/policy-troubleshooter",
"version": "0.1.0",
"description": "Policytroubleshooter client for Node.js",
"repository": "googleapis/nodejs-policytroubleshooter",
"repository": "googleapis/nodejs-policy-troubleshooter",
"license": "Apache-2.0",
"author": "Google LLC",
"main": "build/src/index.js",
Expand Down

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"test": "c8 mocha --timeout 600000 test/*.js"
},
"dependencies": {
"@google-cloud/local-auth": "^1.0.0",
"@google-cloud/policy-troubleshooter": "^0.1.0"
},
"devDependencies": {
Expand Down
31 changes: 15 additions & 16 deletions packages/google-cloud-policytroubleshooter/samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,30 @@

'use strict';

async function main() {
async function main(principal, fullResourceName, permission) {
// [START nodejs_policy_troubleshooter_quickstart]
// Imports the Google Cloud client library

// remove this line after package is released
// eslint-disable-next-line node/no-missing-require
// Imports the Google Cloud client library
const {IamCheckerClient} = require('@google-cloud/policy-troubleshooter');

// 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 {IamCheckerClient}();

//TODO(library generator): write the actual function you will be testing
async function doSomething() {
console.log(
'Developer! Change this code so that it shows how to use the library! See comments below on structure.'
);
// const [thing] = await client.methodName({
// });
// console.info(thing);
const client = new IamCheckerClient();

async function troubelshootPolicy() {
const policy = await client.troubleshootIamPolicy({
accessTuple: {
principal,
fullResourceName,
permission,
},
});
console.log(policy);
}
doSomething();

troubelshootPolicy();
// [END nodejs_policy_troubleshooter_quickstart]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,27 @@
const path = require('path');
const cp = require('child_process');
const {before, describe, it} = require('mocha');
// eslint-disable-next-line node/no-missing-require
const {IamCheckerClient} = require('@google-cloud/policy-troubleshooter');
// eslint-disable-next-line no-unused-vars, node/no-missing-require
const {assert} = require('chai');

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

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

const client = new {IamCheckerClient}();
const client = new IamCheckerClient();

describe('Quickstart', () => {
//TODO: remove this if not using the projectId
// eslint-disable-next-line no-unused-vars
let projectId;

before(async () => {
// eslint-disable-next-line no-unused-vars
projectId = await client.getProjectId();
});

it('should run quickstart', async () => {
//TODO: remove this disability
// eslint-disable-next-line no-unused-vars
const stdout = execSync('node ./quickstart.js', {cwd});
//assert(stdout, stdout !== null);
const stdout = execSync(
`node ./quickstart.js example@example.com //cloudresourcemanager.googleapis.com/projects/${projectId} accessapproval.requests.approve`,
{cwd}
);
assert.match(stdout, /'UNKNOWN_INFO_DENIED'/);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Google LLC
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion packages/google-cloud-policytroubleshooter/src/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Google LLC
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
10 changes: 5 additions & 5 deletions packages/google-cloud-policytroubleshooter/synth.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
{
"git": {
"name": ".",
"remote": "sso://user/sofialeon/nodejs-policy-troubleshooter",
"sha": "8e8c2e15ffed9278832df68ace50441167f9d723"
"remote": "git@github.com:googleapis/nodejs-policy-troubleshooter.git",
"sha": "4749c7fa902cd909f9b878c8f5554751998747a6"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "49e64a5a8eb24ab49a81049f3bb31df869515715",
"internalRef": "347844600"
"sha": "178d16d9f99ee85ffa65dff304f40324c35d0668",
"internalRef": "357260962"
}
},
{
"git": {
"name": "synthtool",
"remote": "https://github.com/googleapis/synthtool.git",
"sha": "d73e8dea90af1b463a7f9d4a33244cf4612ada7c"
"sha": "b32c87d2c087fb2a841acc623ab540105de821af"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Google LLC
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Google LLC
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down

0 comments on commit cc98680

Please sign in to comment.