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

Service account support (#1) #963

Closed
wants to merge 2 commits into from
Closed
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
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ clasp deploy
rm .clasp.json appsscript.json hello.js
clear
-->

![clasp](https://user-images.githubusercontent.com/744973/42856573-a5d96d7c-89fa-11e8-9d69-8d2c66f00d8d.gif)

**To get started, try out the [codelab](https://g.co/codelabs/clasp)!**
Expand Down Expand Up @@ -493,6 +494,13 @@ If no `.claspignore` is specified, a default set of patterns is applied. This de
node_modules/**
```

### How to use a service account

1. Create a service account in GCP with `Service Usage` role
2. Create a key for the service account and download
3. Ensure the script is shared with the service account
4. Login using `clasp login --creds <path-to-downloaded-key>`

## Project Settings File (`.clasp.json`)

When running `clone` or `create`, a file named `.clasp.json` is created in the current directory to describe `clasp`'s configuration for the current project. Example `.clasp.json`:
Expand All @@ -511,12 +519,11 @@ The following configuration values can be used:

### `scriptId` (required)

Specifies the id of the Google Script project that clasp will target.
Specifies the id of the Google Script project that clasp will target.

1. Open script url.
1. File > Project properties > Script ID


### `rootDir` (optional)

Specifies the **local** directory in which clasp will store your project files. If not specified, clasp will default to the current directory.
Expand Down
34 changes: 34 additions & 0 deletions build/src/apis.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Google API Types
*/
/**
* Different types of starter script templates.
* Technically, a script can be multiple types (e.g. Slides add-on/API),
* but it's pretty rare that anyone wants that.
*/
export declare enum SCRIPT_TYPES {
STANDALONE = "standalone",
DOCS = "docs",
SHEETS = "sheets",
SLIDES = "slides",
FORMS = "forms",
WEBAPP = "webapp",
API = "api"
}
export interface AdvancedService {
readonly userSymbol: string;
readonly serviceId: string;
readonly version: string;
}
/**
* This is a list of all public Advanced Services.
*
* It was generated by:
* 1. script.google.com/create
* 1. Resources > Advanced Google Services
* 1. Enable all services
* 1. View > Show manifest file
* 1. View appsscript.json
*/
export declare const PUBLIC_ADVANCED_SERVICES: AdvancedService[];
export declare const SCRIPT_ID_LENGTH = 57;
177 changes: 177 additions & 0 deletions build/src/apis.js

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

1 change: 1 addition & 0 deletions build/src/apis.js.map

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

16 changes: 16 additions & 0 deletions build/src/apiutils.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { script_v1 as scriptV1 } from 'googleapis';
import type { ReadonlyDeep } from 'type-fest';
/**
* Prompts for the function name.
*/
export declare const getFunctionNames: (script: ReadonlyDeep<scriptV1.Script>, scriptId: string) => Promise<string>;
/**
* Enables or disables a Google API.
* @param {string} serviceName The name of the service. i.e. sheets
* @param {boolean} enable Enables the API if true, otherwise disables.
*/
export declare const enableOrDisableAPI: (serviceName: string, enable: boolean) => Promise<void>;
/**
* Enable 'script.googleapis.com' of Google API.
*/
export declare const enableAppsScriptAPI: () => Promise<void>;
81 changes: 81 additions & 0 deletions build/src/apiutils.js

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

1 change: 1 addition & 0 deletions build/src/apiutils.js.map

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

38 changes: 38 additions & 0 deletions build/src/auth.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { script_v1 as scriptV1, Auth } from 'googleapis';
import type { ClaspToken } from './dotfile';
import type { ClaspCredentials } from './utils';
export declare const discovery: import("googleapis").discovery_v1.Discovery;
export declare const drive: import("googleapis").drive_v3.Drive;
export declare const logger: import("googleapis").logging_v2.Logging;
export declare const script: scriptV1.Script;
export declare const serviceUsage: import("googleapis").serviceusage_v1.Serviceusage;
/**
* Gets the local OAuth client for the Google Apps Script API.
* Only the Apps Script API needs to use local credential for the Execution API (script.run).
* @see https://developers.google.com/apps-script/api/how-tos/execute
*/
export declare const getLocalScript: () => Promise<scriptV1.Script>;
export declare const scopeWebAppDeploy = "https://www.googleapis.com/auth/script.webapp.deploy";
export declare const defaultScopes: string[];
/**
* @param {boolean} useLocalhost Uses a local HTTP server if true. Manual entry o.w.
* @param {ClaspCredentials?} creds An optional credentials object.
* @param {string[]} [scopes=[]] List of OAuth scopes to authorize.
*/
interface AuthorizationOptions {
readonly creds?: Readonly<ClaspCredentials>;
readonly scopes: readonly string[];
readonly useLocalhost: boolean;
}
/**
* Requests authorization to manage Apps Script projects.
*/
export declare const authorize: (options: AuthorizationOptions) => Promise<void | Auth.JWT>;
export declare const getLoggedInEmail: () => Promise<string | null | undefined>;
/**
* Loads the Apps Script API credentials for the CLI.
*
* Required before every API call.
*/
export declare const loadAPICredentials: (local?: boolean) => Promise<ClaspToken>;
export {};
Loading