Skip to content

Instantly share code, notes, and snippets.

@evilUrge
Last active July 12, 2021 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evilUrge/c4bad49d667a458568cc5059932348cf to your computer and use it in GitHub Desktop.
Save evilUrge/c4bad49d667a458568cc5059932348cf to your computer and use it in GitHub Desktop.
Add\remove user automatically to JFrog from a triggered github webhook call
exports.handler = async (event, context, callback) => {
const
baseJFrogURL = 'https://yourorg.jfrog.io/artifactory',
request = event.Records[0].cf.request,
body = request.body;
switch (body.action) {
case 'added':
const orgEmailAddress = useJeffUserQueryHere(body.member.login) // Your place to shine!
const payload = {
"schemas": [
"urn:ietf:params:scim:schemas:core:2.0:User"
],
"userName": orgEmailAddress,
"active": true,
"internalPasswordDisabled": true,
"admin": true, // Need to figure out from where to fetch this one?
"emails": [
{
"value": orgEmailAddress,
"primary": true
}
],
"groups": [
"readers",
body.team.name, // As long as our names are the same!
`${body.team.name}-admin` // If admin!
],
}
const response = await fetch(`${baseJFrogURL}/api/v1/scim/v2/Users`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}, body: JSON.stringify(payload),
}).then(res => res.ok ? res.json : false)
return callback(null, response);
case 'removed':
// Probably the same as above
break;
}
}
@cuperman
Copy link

cuperman commented Jul 9, 2021

oh interesting idea. you want us to use github as the source of truth for our users, and automatically propagate users to our other cloud tools?

@evilUrge
Copy link
Author

Indeed, then again, as we're managing users via Azure-AD, maybe it makes more sense to trigger the same from AD based on the user's security groups

https://docs.microsoft.com/en-us/azure/active-directory-b2c/azure-monitor#62-create-a-workbook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment