Skip to content

Instantly share code, notes, and snippets.

jobs:
tests: # Job ID
name: Tests # Name of the job displayed on GitHub.
runs-on: ubuntu-latest # OS for the GitHub-hosted virtual machine
services: # Define Docker containers to use for this job.
backend-db: # Container ID for our database container
image: postgres:12.1 # Image to pull from Docker Hub
env:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
name: CI
on:
push:
branches:
- '**'
jobs:
tests:
name: Tests
{
"kind": "admin#directory#user",
"id": "10455555555555552791",
"etag": "enlFCt4L0-k8zzzzzzzzzz/3hRG05XNzzzzzzzzzzzobrHi6Erg",
"primaryEmail": "[email protected]",
"name": {
"givenName": "Hugobert",
"familyName": "Dinkelbaum",
"fullName": "Hugobert Dinkelbaum"
},
from django.contrib.auth.models import User
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.views import APIView
from .gsuite_client import GSuiteClient
from .gsuite_user_fetcher import GSuiteUserFetcher
# initlialize our GSuite client wrapper with the required settings
gsuite_client = GSuiteClient(
{
"kind": "api#channel",
"id": "01234567-89ab-xxx-012BAX6789ab", # ID generated for the channel.
"resourceId": "B4ibMJiIhTx123xf2K2bexk8G4", # ID of the watched resource.
"resourceUri": "https://www.googleapis.com/admin/directory/v1/users?domain=sennder.com&event=add", # Version-specific ID of the watched resource.
"token": "target=GSuiteCreateUser", # Present only if one was provided.
"expiration": 1384823632000, # Actual expiration time as Unix timestamp (in ms), if applicable.
}
from django.contrib import admin
from django.urls import path
from gs_example.gsuite_part.channel_generator import GSuiteChannelGenerator
from gs_example.gsuite_part.gsuite_client import GSuiteClient
from gs_example.gsuite_part.web_hook import WebHookReceiver
urlpatterns = [
path("admin/", admin.site.urls),
path("gsuite/user-webhook", WebHookReceiver.as_view()),
# initlialize our GSuite client wrapper with the required settings
gsuite_client = GSuiteClient(
permission_file_path="C:/gs_example/gsuite-integration-211111-627e77777b0a.json",
permission_scopes=["https://www.googleapis.com/auth/admin.directory.user"],
admin_user="[email protected]",
)
from typing import List
from google.oauth2 import service_account
from googleapiclient.discovery import build
class GSuiteClient:
def __init__(
self, permission_file_path: str, permission_scopes: List[str], admin_user: str
):
self._permission_file_path = permission_file_path
POST https://reinhardt.sennder.com/gsuite/user-webhook # Your receiving URL.
Content-Type: application/json; utf-8
Content-Length: 189
X-Goog-Channel-ID: addChannel
X-Goog-Channel-Token: 245tzzzzzzzzzz333
X-Goog-Channel-Expiration: Mon, 09 Dec 2013 22:24:23 GMT
X-Goog-Resource-ID: B4ibMJzzzzzzzzzzbexk8G4
X-Goog-Resource-URI: https://www.googleapis.com/admin/directory/v1/users?domain=sennder.com&event=add&alt=json
X-Goog-Resource-State: delete
X-Goog-Message-Number: 226440