{"id":13754900,"url":"https://github.com/brigadecore/brigade-eventgrid-gateway","last_synced_at":"2025-05-10T00:31:15.418Z","repository":{"id":29467554,"uuid":"121527776","full_name":"brigadecore/brigade-eventgrid-gateway","owner":"brigadecore","description":"Brigade v1 gateway that responds to Azure EventGrid events using CloudEvents schema","archived":true,"fork":false,"pushed_at":"2022-06-01T13:23:31.000Z","size":103,"stargazers_count":7,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-15T02:17:52.685Z","etag":null,"topics":["brigade","brigade-gateway","cloudevents","cloudevents-schema","kubernetes","v1"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brigadecore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-14T15:39:18.000Z","updated_at":"2023-09-08T17:36:41.000Z","dependencies_parsed_at":"2022-07-27T19:18:03.753Z","dependency_job_id":null,"html_url":"https://github.com/brigadecore/brigade-eventgrid-gateway","commit_stats":null,"previous_names":["radu-matei/brigade-eventgrid-gateway"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brigadecore%2Fbrigade-eventgrid-gateway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brigadecore%2Fbrigade-eventgrid-gateway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brigadecore%2Fbrigade-eventgrid-gateway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brigadecore%2Fbrigade-eventgrid-gateway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brigadecore","download_url":"https://codeload.github.com/brigadecore/brigade-eventgrid-gateway/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253346392,"owners_count":21894263,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["brigade","brigade-gateway","cloudevents","cloudevents-schema","kubernetes","v1"],"created_at":"2024-08-03T10:00:36.190Z","updated_at":"2025-05-10T00:31:15.081Z","avatar_url":"https://github.com/brigadecore.png","language":"Go","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"\u003e ⚠️\u0026nbsp;\u0026nbsp;This repo contains the source for a component of the Brigade\n\u003e v1.x ecosystem. Brigade v1.x reached end-of-life on June 1, 2022 and as a\n\u003e result, this component is no longer maintained.\n\u003e\n\u003e Brigade v2 users can utilize the\n\u003e [Brigade CloudEvents Gateway](https://github.com/brigadecore/brigade-cloudevents-gateway)\n\u003e to support the use cases previously supported by this gateway.\n\n# Brigade EventGrid Gateway\n\n[Brigade][1] gateway that responds to [Azure EventGrid][2] events.\n\n\u003e [Here you can read more about Brigade Gateways][6]\n\nDeploying the gateway\n---------------------\n\nFirst you need to clone this repo: \n\n`git clone https://github.com/radu-matei/brigade-eventgrid-gateway` and navigate to the root directory.\n\n[EventGrid needs an HTTPS endpoint to deliver the event][3], so you need to have TLS ingress for your cluster (use something like [kube-lego][4] or [cert-manager][5]), and this chart assumes you have an `nginx` ingress controller deployed on your cluster. Once you have an HTTPS domain or subdomain, pass it to the `ingress.host` property below.\n\nNow install the Helm chart:\n\n`helm install -n brigade-eventgrid-gateway ./charts/brigade-eventgrid-gateway --set ingress.host=\u003cyour-HTTPS-endpoint\u003e`\n\n\u003e You can also  specify the host in [`charts/brigade-eventgrid-gateway/values.yaml`][7]\n\n\u003e By default, the chart assumes you have a cluster with RBAC enabled. If you don't, either modify the `rbac.enabled` value in `values.yaml` or pass `--set rbac.enabled=false` to the `helm install` command. \n\n\u003e If you don't have a domain or an ingress controller configured, you can [change the ingress annotations in the ingress template file](charts/brigade-eventgrid-gateway/templates/ingress.yaml) - but keep in mind that EventGrid will not pass events to a non-HTTPS endpoint.\n\nAt this point, you should be able to navigate to `https://\u003cyour-endpoint\u003e/healthz` and receive `\"message\": \"ok\"` and you can start sending events to this gateway.\n\n\n## Creating a Brigade project\n\nYou can [follow the instructions from the official Brigade documentation][14] to create a new project - the gateway will use a token in order to make sure that if unauthorized people send events to your gateway, those will not become Brigade builds - the token is passed in the URL and it is checked whenever a new event is received, before creating a new Brigade build, and can be any string. In your project's `values.yaml` file, add an `eventGridToken` token:\n\n```\nproject: \"\u003cyour-project\u003e\"\nrepository: \"\u003cyour-repo\u003e\"\ncloneURL: \"\u003cyour-clone-url\u003e\"\n\nsecrets:\n  eventGridToken: \"\u003cyour-token\u003e\"\n\nallowPrivilegedJobs: \"false\"\n```\n\n\nThen create the project:\n\n`helm install -n eventgrid-project brigade/brigade-project -f values.yaml`\n\nWhen creating an EventGrid subscription you will need both the project ID and the token, as they will be part of the event endpoint URL.\n\n## Creating the Azure EventGrid subscription\n\nAzure EventGrid supports two JSON event schemas:\n\n- [the CloudEvents JSON schema](https://github.com/cloudevents/spec/blob/master/json-format.md), which is an open standard for describing event data in a consistent way (which is in preview at the moment of writing this document)\n- [the default Azure EventGrid schema](https://docs.microsoft.com/en-us/azure/event-grid/event-schema)\n\nFor the purpose of this tutorial we will use a storage account as the source of events, but the same concepts can be applied to [any event source Azure EventGrid supports](https://docs.microsoft.com/en-us/azure/event-grid/overview):\n\n```\naz storage account create \\\n  --name  \u003cstorage-account-name\u003e \\\n  --location northeurope \\\n  --resource-group \u003cresource-group-name\u003e \\\n  --sku Standard_LRS \\\n  --kind BlobStorage \\\n  --access-tier Hot\n```\n\n\u003e Please note that currently, Azure Event Grid has preview support for CloudEvents JSON format input and output in West Central US, Central US, and North Europe.\n\n\u003e For more up-to-date information about regions and CloudEvents in Azure EventGrid, [check out the documentation][13]\n\nIn order to create an event subscription, we need to pass the id to the resource that generates the events - in this case, we need to pass the id to the storage account we just created:\n\n`storageid=$(az storage account show --name \u003cstorage-account-name\u003e --resource-group \u003cresource-group-name\u003e --query id --output tsv)`\n\n\u003e Please that in this way you can get the ID of any Azure resource that supports generating events and sending them to EventGrid.\n\u003e For an up-to-date list of Azure resources that support EventGrid, [check out the documentation][12]\n\n### Using the CloudEvents schema\n\nWe want to generate events from Azure resources using the CloudEvents schema and handle them using the gateway we just deployed. Since the feature is currently in preview, we need to add an extension for the `az` command line:\n\n`az extension add --name eventgrid`\n\nThen, we create the event subscription:\n\n```\n  az eventgrid event-subscription create \\\n  --source-resource-id $storageid \\\n  --name brigade-cloudevents \\\n  --endpoint https://\u003cyour-endpoint\u003e/cloudevents/v0.1/\u003cbrigade-project-id\u003e/\u003cyour-token\u003e \\\n  --event-delivery-schema cloudeventv01schema\n```\n\n\u003e You can get the Brigade Project ID using the [`brig`][11] tool: `brig project list`\n\nNote that the path for CloudEvents is `/cloudevents/v0.1/\u003cbrigade-project-id\u003e/\u003cyour-token\u003e`, and an example of the full URL would be:\n\n`https://$YOURDOMAIN/cloudevents/v0.1/brigade-9e0af40182d1ab201542ebfb7d795d189ad0ec0b73512190e93935/you-should-change-this-to-be-your-own`\n\nThis is a sample event that follows the CloudEvents schema looks like:\n\n```\n{\n    \"cloudEventsVersion\" : \"0.1\",\n    \"eventType\" : \"Microsoft.Storage.BlobCreated\",\n    \"eventTypeVersion\" : \"\",\n    \"source\" : \"/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Storage/storageAccounts/{storage-account}#blobServices/default/containers/{storage-container}/blobs/{new-file}\",\n    \"eventID\" : \"173d9985-401e-0075-2497-de268c06ff25\",\n    \"eventTime\" : \"2018-04-28T02:18:47.1281675Z\",\n    \"data\" : {\n      \"api\": \"PutBlockList\",\n      \"clientRequestId\": \"6d79dbfb-0e37-4fc4-981f-442c9ca65760\",\n      \"requestId\": \"831e1650-001e-001b-66ab-eeb76e000000\",\n      \"eTag\": \"0x8D4BCC2E4835CD0\",\n      \"contentType\": \"application/octet-stream\",\n      \"contentLength\": 524288,\n      \"blobType\": \"BlockBlob\",\n      \"url\": \"https://oc2d2817345i60006.blob.core.windows.net/oc2d2817345i200097container/oc2d2817345i20002296blob\",\n      \"sequencer\": \"00000000000004420000000000028963\",\n      \"storageDiagnostics\": {\n        \"batchId\": \"b68529f3-68cd-4744-baa4-3c0498ec19f0\"\n      }\n    }\n}\n```\n\n### Using the default EventGrid schema\n\n```\n  az eventgrid event-subscription create \\\n  --source-resource-id $storageid \\\n  --name brigade-eventgrid \\\n  --endpoint https://\u003cyour-endpoint\u003e/eventgrid/\u003cbrigade-project-id\u003e/\u003cyour-token\u003e \n```\n\nNote that the path for the default EventGrid schema is `/eventgrid/\u003cbrigade-project-id\u003e/\u003cyour-token\u003e`\n\nThis is a sample event that follows the Azure EventGrid default schema:\n\n```\n[{\n  \"topic\": \"/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myrg/providers/Microsoft.Storage/storageAccounts/myblobstorageaccount\",\n  \"subject\": \"/blobServices/default/containers/testcontainer/blobs/testfile.txt\",\n  \"eventType\": \"Microsoft.Storage.BlobCreated\",\n  \"eventTime\": \"2017-08-16T20:33:51.0595757Z\",\n  \"id\": \"4d96b1d4-0001-00b3-58ce-16568c064fab\",\n  \"data\": {\n    \"api\": \"PutBlockList\",\n    \"clientRequestId\": \"d65ca2e2-a168-4155-b7a4-2c925c18902f\",\n    \"requestId\": \"4d96b1d4-0001-00b3-58ce-16568c000000\",\n    \"eTag\": \"0x8D4E4E61AE038AD\",\n    \"contentType\": \"text/plain\",\n    \"contentLength\": 0,\n    \"blobType\": \"BlockBlob\",\n    \"url\": \"https://myblobstorageaccount.blob.core.windows.net/testcontainer/testblob1.txt\",\n    \"sequencer\": \"00000000000000EB0000000000046199\",\n    \"storageDiagnostics\": {\n      \"batchId\": \"dffea416-b46e-4613-ac19-0371c0c5e352\"\n    }\n  },\n  \"dataVersion\": \"\",\n  \"metadataVersion\": \"1\"\n}]\n```\n\n\u003e You can get the Brigade Project ID using the [`brig`][11] tool: `brig project list`\n\nAn example of the full URL would be:\n\n`https://$YOURDOMAIN/eventgrid/brigade-9e0af40182d1ab201542ebfb7d795d189ad0ec0b73512190e93935/you-should-change-this-to-be-your-own`\n\nIn both cases, a validation request will be sent to the endpoint, which this gateway handles - after this, the endpoint will receive events according to the subscription.\n\n\n## Handling events in Brigade builds\n\nFollowing the example so far, blob storage generates two events: `Microsoft.Storage.BlobCreated` and `Microsoft.Storage.BlobDeleted` that we can handle in our `brigade.js` file:\n\n```javascript\nconst { events } = require('brigadier')\n\nevents.on(\"Microsoft.Storage.BlobDeleted\", (e, p) =\u003e {\n  console.log(e);\n})\n\nevents.on(\"Microsoft.Storage.BlobCreated\", (e, p) =\u003e {\n  console.log(e);\n})\n```\n\nAt this point, whenever events are fired, our simple handlers will log them to the console:\n\n```shell\n$ brig build logs 01cegwv9t48kva8wh093pw0hbn\n\n==========[  brigade-worker-01cegwv9t48kva8wh093pw0hbn  ]==========\nprestart: empty script found. Falling back to VCS script\nprestart: src/brigade.js written[brigade] brigade-worker version: 0.14.0\n[brigade:k8s] Creating PVC named brigade-worker-01cegwv9t48kva8wh093pw0hbn\n{ buildID: '01cegwv9t48kva8wh093pw0hbn',\n  workerID: 'brigade-worker-01cegwv9t48kva8wh093pw0hbn',\n  type: 'Microsoft.Storage.BlobDeleted',\n  provider: 'cloudevents',\n  revision: { commit: '', ref: 'master' },\n  logLevel: 1,\n  payload: '{\"eventType\":\"Microsoft.Storage.BlobDeleted\",\"eventTypeVersion\":\"\",\"cloudEventsVersion\":\"0.1\",\"source\":\"/subscriptions/\u003csubscription-id\u003e/resourceGroups/\u003cresource-group\u003e/providers/Microsoft.Storage/storageAccounts/\u003cstorage-account\u003e#blobServices/default/containers/\u003cpath-to-file-in-blob\u003e\",\"eventID\":\"\u003cevent-id\u003e\",\"eventTime\":\"2018-05-27T13:33:18.1443969Z\",\"contentType\":\"\",\"extensions\":null,\"data\":{\"api\":\"DeleteBlob\",\"blobType\":\"BlockBlob\",\"contentLength\":5698,\"contentType\":\"application/octet-stream\",\"eTag\":\"\u003ce-tag\u003e\",\"requestId\":\"\u003crequest-id\u003e\",\"sequencer\":\"\u003csequencer\u003e\",\"storageDiagnostics\":{\"batchId\":\"\u003cbatch-id\u003e\"},\"url\":\"https://\u003cstorage-account\u003e.blob.core.windows.net/\u003cpath-to-file-in-blob\u003e\"}}' }\n[brigade:app] after: default event handler fired\n[brigade:app] beforeExit(2): destroying storage\n[brigade:k8s] Destroying PVC named brigade-worker-01cegwv9t48kva8wh093pw0hbn\n```\n\n# Building from source and running locally\n\nPrerequisites:\n- [the Go toolchain][8]\n- [`dep`][9]\n- `make` (optional)\n\nTo build from source:\n\n- `dep ensure`\n- `make build` or `go build` to build the binary for your OS\n- if running locally, you should provide an environment variable for the Kubernetes configuration file:\n  - on Linux (including Windows Subsystem for Linux) and macOS: `export KUBECONFIG=\u003cpath-to-config\u003e`\n  - on Windows: `$env:KUBECONFIG=\"\u003cpath-to-config\u003e\"` \n\n- starting the binary you should see the initial Gin output:\n\n```\n[GIN-debug] [WARNING] Running in \"debug\" mode. Switch to \"release\" mode in production.\n - using env:   export GIN_MODE=release\n - using code:  gin.SetMode(gin.ReleaseMode)\n\n[GIN-debug] GET    /healthz                  --\u003e main.healthz (2 handlers)\n[GIN-debug] POST   /eventgrid/:project       --\u003e main.azFn (3 handlers)\n[GIN-debug] POST   /eventgrid/:project/:token --\u003e main.azFn (3 handlers)\n[GIN-debug] POST   /cloudevents/v0.1/:project/:token --\u003e main.ceFn (3 handlers)\n[GIN-debug] Environment variable PORT is undefined. Using port :8080 by default\n[GIN-debug] Listening and serving HTTP on :8080\n```\n- at this point, your server should be able to start accepting incoming requests to `localhost:8080`\n- you can test the server locally, using [Postman][10] (POST requests with your desired JSON payload - see the `testdata` folders used for testing)\n- please note that running locally with a Kubernetes config file set is equivalent to running privileged inside the cluster, and any Brigade builds created will get executed!\n\n# Contributing\n\nThis Brigade project accepts contributions via GitHub pull requests. This document outlines the process to help get your contribution accepted.\n\n## Signed commits\n\nA DCO sign-off is required for contributions to repos in the brigadecore org.  See the documentation in\n[Brigade's Contributing guide](https://github.com/brigadecore/brigade/blob/master/CONTRIBUTING.md#signed-commits)\nfor how this is done.\n\n[1]: https://github.com/azure/brigade\n[2]: https://docs.microsoft.com/en-us/azure/event-grid/overview\n[3]: https://docs.microsoft.com/en-us/azure/event-grid/security-authentication#webhook-event-delivery\n\n[4]: https://github.com/jetstack/kube-lego\n[5]: https://github.com/jetstack/cert-manager/\n\n[6]: https://docs.brigade.sh/topics/gateways/\n[7]: charts/brigade-eventgrid-gateway/values.yaml\n\n[8]: https://golang.org/doc/install\n[9]: https://github.com/golang/dep\n\n[10]: https://www.getpostman.com/\n[11]: https://github.com/Azure/brigade/releases\n\n[12]: https://docs.microsoft.com/en-us/azure/event-grid/overview\n[13]: https://docs.microsoft.com/en-us/azure/event-grid/cloudevents-schema\n\n[14]: https://github.com/cloudevents/spec/blob/master/json-format.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrigadecore%2Fbrigade-eventgrid-gateway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrigadecore%2Fbrigade-eventgrid-gateway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrigadecore%2Fbrigade-eventgrid-gateway/lists"}