Skip to content

Commit

Permalink
fix timeout when running in lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiago Posse committed Aug 29, 2023
1 parent c2832bb commit 90a8506
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,4 @@ dist

# build dirs
build
build.zip
lambda.zip
9 changes: 8 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ const gitlabScim = new GitlabScim()
const gitlabApi = new GitlabApi()
let slack: Slack | null = null;


if (process.env.SLACK_WEBHOOK_URL !== undefined) {
slack = new Slack()
}

logger.debug("clients initialized")

async function getGoogleUserGroups(): Promise<{ [key: string]: string[] }> {
const userGroups: { [key: string]: string[] } = {}
Expand All @@ -34,7 +36,7 @@ async function getGoogleUserGroups(): Promise<{ [key: string]: string[] }> {

const googleGroups = await google.listGroups(groupFilter)
for (const group of googleGroups) {
logger.debug(`listing google groups for ${group.email}`)
logger.debug(`listing members for google group ${group.email}`)
const members = await google.listGroupMembers(group.id)
for (const member of members) {
if (!userGroups.hasOwnProperty(member.email)) {
Expand All @@ -56,8 +58,11 @@ async function execute() {

const userGroups: { [key: string]: string[] } = await getGoogleUserGroups()
const googleUsers = await google.listUsers(Object.keys(userGroups))
logger.debug("retrieved google users")
const gitlabScimUsers = await gitlabScim.listScimUsers()
logger.debug("retrieved gitlab scim users")
const gitlabUsers = await gitlabApi.listGroupSamlMembers()
logger.debug("retrieved gitlab group users")
// Compute updates to execute

const membershipUpdates: GitlabAccessUpdate[] = []
Expand Down Expand Up @@ -221,7 +226,9 @@ if (
}

export const handler: Handler = async () => {
logger.debug("Starting execution")
await execute()
logger.debug("Finished execution")

return {}
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "gitlab-google-scim",
"version": "0.1.2",
"version": "0.1.3",
"main": "index.ts",
"type": "module",
"scripts": {
"compile": "rm -rf build/ && ./node_modules/typescript/bin/tsc -p . --noEmit false --allowImportingTsExtensions false",
"package": "rm build.zip && zip -r build.zip package.json build node_modules",
"package": "rm -rf lambda.zip && zip -r lambda.zip package.json build node_modules",
"lambda": "npm run compile && npm run package"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion src/gitlab/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { GitlabGroup, GitlabApiUser, GitlabAccessUpdate, GitlabMembership, Gitla
import { Gitlab } from './index';
import { getSecretFromAws } from "../utils/aws";
import fs from 'fs';
import { logger } from "../utils/logging";

const GITLAB_API_TOKEN = await resolveGitlabApiToken()

Expand Down Expand Up @@ -78,7 +79,7 @@ export class GitlabApi extends Gitlab {

while (page !== -1) {
const resp = await this.rawRequest(`/${groupName}/members?page=${page}`, {})
if (resp.headers.get("x-next-page") !== null) {
if (resp.headers.get("x-next-page") !== null && resp.headers.get("x-next-page") !== undefined && resp.headers.get("x-next-page") !== "") {
page = +resp.headers.get("x-next-page")!
} else {
page = -1
Expand Down
1 change: 0 additions & 1 deletion src/gitlab/scim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import fs from 'fs';
const GITLAB_SCIM_TOKEN = await resolveGitlabScimToken()

async function resolveGitlabScimToken(): Promise<string> {

if (process.env.GITLAB_SCIM_TOKEN_SECRET !== undefined) {
return await getSecretFromAws(process.env.GITLAB_SCIM_TOKEN_SECRET)
}
Expand Down
1 change: 1 addition & 0 deletions src/google/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { GoogleUser, GoogleGroupMember, GoogleGroupsListResponse, GoogleUsersLis
import { minimatch } from 'minimatch';
import { getSecretFromAws } from "../utils/aws";
import fs from 'fs';
import { logger } from '../utils/logging';

const SCOPES = [
'https://www.googleapis.com/auth/admin.directory.user.readonly',
Expand Down

0 comments on commit 90a8506

Please sign in to comment.