Skip to content
Merged
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
40 changes: 40 additions & 0 deletions spec/v1/function-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,44 @@ describe('FunctionBuilder', () => {
})
).to.throw();
});

it('should throw an error if invoker is an empty string', () => {
expect(() =>
functions.runWith({
invoker: '',
})
).to.throw();
});

it('should throw an error if invoker is an empty array', () => {
expect(() =>
functions.runWith({
invoker: [''],
})
).to.throw();
});

it('should throw an error if invoker has an empty string', () => {
expect(() =>
functions.runWith({
invoker: ['service-account1', '', 'service-account2'],
})
).to.throw();
});

it('should throw an error if public identifier is in the invoker array', () => {
expect(() =>
functions.runWith({
invoker: ['service-account1', 'public', 'service-account2'],
})
).to.throw();
});

it('', () => {
expect(() =>
functions.runWith({
invoker: ['service-account1', 'private', 'service-account2'],
})
).to.throw();
});
});
5 changes: 4 additions & 1 deletion src/v1/cloud-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
DEFAULT_FAILURE_POLICY,
DeploymentOptions,
FailurePolicy,
Invoker,
Schedule,
} from './function-configuration';
export { Request, Response };
Expand Down Expand Up @@ -278,6 +279,7 @@ export interface TriggerAnnotated {
vpcConnectorEgressSettings?: string;
serviceAccountEmail?: string;
ingressSettings?: string;
invoker?: Invoker | Invoker[];
};
}

Expand Down Expand Up @@ -497,7 +499,8 @@ export function optionsToTrigger(options: DeploymentOptions) {
'ingressSettings',
'vpcConnectorEgressSettings',
'vpcConnector',
'labels'
'labels',
'invoker'
);
convertIfPresent(
trigger,
Expand Down
37 changes: 37 additions & 0 deletions src/v1/function-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,43 @@ function assertRuntimeOptionsValid(runtimeOptions: RuntimeOptions): boolean {
);
}
}

if (
typeof runtimeOptions.invoker === 'string' &&
runtimeOptions.invoker.length === 0
) {
throw new Error(
'Invalid service account for function invoker, must be a non-empty string'
);
}
if (
runtimeOptions.invoker !== undefined &&
Array.isArray(runtimeOptions.invoker)
) {
if (runtimeOptions.invoker.length === 0) {
throw new Error(
'Invalid invoker array, must contain at least 1 service account entry'
);
}
for (const serviceAccount of runtimeOptions.invoker) {
if (serviceAccount.length === 0) {
throw new Error(
'Invalid invoker array, a service account must be a non-empty string'
);
}
if (serviceAccount === 'public') {
throw new Error(
"Invalid invoker array, a service account cannot be set to the 'public' identifier"
);
}
if (serviceAccount === 'private') {
throw new Error(
"Invalid invoker array, a service account cannot be set to the 'private' identifier"
);
}
}
}

return true;
}

Expand Down
10 changes: 10 additions & 0 deletions src/v1/function-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ export const DEFAULT_FAILURE_POLICY: FailurePolicy = {

export const MAX_NUMBER_USER_LABELS = 58;

/**
* Invoker access control type for https functions.
*/
export type Invoker = 'public' | 'private' | string;

export interface RuntimeOptions {
/**
* Which platform should host the backend. Valid options are "gcfv1"
Expand Down Expand Up @@ -156,6 +161,11 @@ export interface RuntimeOptions {
* User labels to set on the function.
*/
labels?: Record<string, string>;

/**
* Invoker to set access control on https functions.
*/
invoker?: Invoker | Invoker[];
}

export interface DeploymentOptions extends RuntimeOptions {
Expand Down