-
Notifications
You must be signed in to change notification settings - Fork 901
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding service account api calls * fixing edge case for function regions/buckets/triggers, added code to set the iam role on storage service agent * spacing * adding reducer to clean up code * fix additional edge cases * addressing comments * cleaning up names * exposing more location apis and clean up * linter * refactor into services file * fixing comments * clean up sinon stubs * changing dispatch function to undefined for noop & pubsub services * linter
- Loading branch information
1 parent
832242d
commit 0d6d632
Showing
17 changed files
with
955 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const STORAGE_V2_EVENTS = [ | ||
"google.cloud.storage.object.v1.finalized", | ||
"google.cloud.storage.object.v1.archived", | ||
"google.cloud.storage.object.v1.deleted", | ||
"google.cloud.storage.object.v1.metadataUpdated", | ||
]; | ||
|
||
export const PUBSUB_V2_EVENT = "google.cloud.pubsub.topic.v1.messagePublished"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as backend from "../backend"; | ||
import * as iam from "../../../gcp/iam"; | ||
import { obtainStorageBindings, ensureStorageTriggerRegion } from "./storage"; | ||
|
||
const noop = (): Promise<void> => Promise.resolve(); | ||
|
||
/** A service interface for the underlying GCP event services */ | ||
export interface Service { | ||
readonly name: string; | ||
readonly api: string; | ||
|
||
// dispatch functions | ||
requiredProjectBindings: ((pId: any, p: any) => Promise<Array<iam.Binding>>) | undefined; | ||
ensureTriggerRegion: (ep: backend.Endpoint, et: backend.EventTrigger) => Promise<void>; | ||
} | ||
|
||
/** A noop service object, useful for v1 events */ | ||
export const NoOpService: Service = { | ||
name: "noop", | ||
api: "", | ||
requiredProjectBindings: undefined, | ||
ensureTriggerRegion: noop, | ||
}; | ||
/** A pubsub service object */ | ||
export const PubSubService: Service = { | ||
name: "pubsub", | ||
api: "pubsub.googleapis.com", | ||
requiredProjectBindings: undefined, | ||
ensureTriggerRegion: noop, | ||
}; | ||
/** A storage service object */ | ||
export const StorageService = { | ||
name: "storage", | ||
api: "storage.googleapis.com", | ||
requiredProjectBindings: obtainStorageBindings, | ||
ensureTriggerRegion: ensureStorageTriggerRegion, | ||
}; | ||
|
||
/** Mapping from event type string to service object */ | ||
export const EVENT_SERVICE_MAPPING: Record<string, any> = { | ||
"google.cloud.pubsub.topic.v1.messagePublished": PubSubService, | ||
"google.cloud.storage.object.v1.finalized": StorageService, | ||
"google.cloud.storage.object.v1.archived": StorageService, | ||
"google.cloud.storage.object.v1.deleted": StorageService, | ||
"google.cloud.storage.object.v1.metadataUpdated": StorageService, | ||
}; | ||
|
||
/** | ||
* Find the Service object for the given endpoint | ||
* @param endpoint the endpoint that we want the service for | ||
* @returns a Service object that corresponds to the event type of the endpoint or noop | ||
*/ | ||
export function serviceForEndpoint(endpoint: backend.Endpoint): Service { | ||
if (!backend.isEventTriggered(endpoint)) { | ||
return NoOpService; | ||
} | ||
|
||
return EVENT_SERVICE_MAPPING[endpoint.eventTrigger.eventType] || NoOpService; | ||
} |
Oops, something went wrong.