-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added automatic removal of past parents from groups
- Loading branch information
1 parent
4245a3e
commit e08c872
Showing
14 changed files
with
188 additions
and
11 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,43 @@ | ||
import * as df from "durable-functions"; | ||
import { InvocationContext } from "@azure/functions"; | ||
import { admin_directory_v1 as adminDirectoryV1 } from "googleapis"; | ||
|
||
import { Logger, Severity } from "../../lib/Logger"; | ||
import { GoogleAPI } from "../../lib/Google"; | ||
|
||
import environment from "../../environment"; | ||
|
||
export const FUNCTION_NAME = "googleFindGroups"; | ||
|
||
/** | ||
* Finds Google Groups using the specified query | ||
* @param params A {@link adminDirectoryV1.Params$Resource$Groups$List} object with query options | ||
* @param context The invocation context for the function | ||
* @returns A list of {@link adminDirectoryV1.Schema$Group} groups if found, otherwise undefined | ||
*/ | ||
export async function googleFindGroups( | ||
params: adminDirectoryV1.Params$Resource$Groups$List, | ||
context: InvocationContext | ||
): Promise<adminDirectoryV1.Schema$Group[]> { | ||
const logger = new Logger(context, "Google"); | ||
|
||
const google = new GoogleAPI(); | ||
|
||
try { | ||
const groupList = await google.listGroups({ | ||
domain: environment.google.domain, | ||
...params | ||
}); | ||
|
||
return groupList.groups; | ||
} catch (err) { | ||
logger.log(Severity.Error, err, "\nInput Parameters:", params); | ||
|
||
throw err; | ||
} | ||
} | ||
|
||
df.app.activity(FUNCTION_NAME, { | ||
extraInputs: [df.input.durableClient()], | ||
handler: googleFindGroups | ||
}); |
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,52 @@ | ||
import * as df from "durable-functions"; | ||
import { InvocationContext } from "@azure/functions"; | ||
|
||
import { Logger, Severity } from "../../lib/Logger"; | ||
import { GoogleAPI } from "../../lib/Google"; | ||
|
||
export const FUNCTION_NAME = "googleRemoveMemberFromGroup"; | ||
|
||
/** | ||
* Outlines the parameters needed for {@link googleRemoveMemberFromGroup} | ||
*/ | ||
export interface GoogleRemoveMemberFromGroupParams { | ||
/** The ID of the Google Group */ | ||
groupId: string; | ||
/** The email of the user to remove */ | ||
email: string; | ||
} | ||
|
||
/** | ||
* Removes a member from the specified Google Group | ||
* @param params A {@link GoogleRemoveMemberFromGroupParams} object containing the group ID and email of the member to remove | ||
* @param context The invocation context for the function | ||
* @returns True if successful | ||
*/ | ||
export async function googleRemoveMemberFromGroup( | ||
params: GoogleRemoveMemberFromGroupParams, | ||
context: InvocationContext | ||
): Promise<boolean> { | ||
const logger = new Logger(context, "Google"); | ||
|
||
const google = new GoogleAPI(); | ||
|
||
try { | ||
await google.removeMemberFromGroup({ | ||
groupKey: params.groupId, | ||
memberKey: params.email | ||
}); | ||
|
||
return true; | ||
} catch (err) { | ||
if (err?.includes("Resource Not Found: memberKey")) return true; | ||
|
||
logger.log(Severity.Error, err, "\nInput Parameters:", params); | ||
|
||
throw err; | ||
} | ||
} | ||
|
||
df.app.activity(FUNCTION_NAME, { | ||
extraInputs: [df.input.durableClient()], | ||
handler: googleRemoveMemberFromGroup | ||
}); |
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
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"outDir": "dist", | ||
"rootDir": "src", | ||
"sourceMap": true, | ||
"strict": false | ||
"strict": false, | ||
"lib": ["es2021"] | ||
} | ||
} |