-
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.
- Loading branch information
1 parent
6487e02
commit fe7d049
Showing
9 changed files
with
136 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
#!/bin/bash | ||
docker buildx create --use --name multi --platform linux/arm64,linux/amd64 | ||
docker buildx build \ | ||
--platform linux/arm64,linux/amd64 \ | ||
-t rorylshanks/veriflow:latest \ | ||
-t rorylshanks/veriflow:debug \ | ||
--push \ | ||
-f Dockerfile \ | ||
. | ||
docker buildx rm multi | ||
|
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,64 @@ | ||
import redisHelper from "../util/redis.js" | ||
import Bossbat from 'bossbat'; | ||
import log from '../util/logging.js' | ||
import { getConfig } from '../util/config.js' | ||
import timestring from 'timestring'; | ||
|
||
const idpUpdater = new Bossbat({ | ||
connection: redisHelper.getRedisConfig(), | ||
prefix: 'bossbat:', | ||
ttl: timestring(getConfig().idp_refresh_directory_interval) * 1000 | ||
}); | ||
|
||
var currentConfig = getConfig() | ||
let importedAdapter = await import(`./idp_adapters/${currentConfig.idp_provider}.js`) | ||
let adapter = importedAdapter.default | ||
|
||
async function update() { | ||
try { | ||
var startDate = Date.now() | ||
await adapter.runUpdate() | ||
var endDate = Date.now() | ||
var duration = (endDate - startDate) / 1000 | ||
log.info(`Updated users from IDP in ${duration} seconds`) | ||
} catch (error) { | ||
log.error({error, details: error.message}) | ||
} | ||
} | ||
|
||
async function scheduleUpdate() { | ||
let config = getConfig() | ||
if (config.refresh_idp_at_start) { | ||
update() | ||
} | ||
idpUpdater.hire('update-idp', { | ||
every: getConfig().idp_refresh_directory_interval, | ||
work: async () => { | ||
try { | ||
await update() | ||
} catch (error) { | ||
log.error({ message: "Failed up update users and groups from IDP", error }) | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
async function getUserById(userId) { | ||
var user = await adapter.getUserById(userId) | ||
return user | ||
} | ||
|
||
async function addNewUserFromClaims(userClaims) { | ||
if (!adapter.addNewUserFromClaims) { | ||
log.debug({ message: `Adapter ${currentConfig.idp_provider} does not support adding new users via claims, returning`, context: { claims: userClaims } }) | ||
return | ||
} | ||
log.debug({ message: "Attempting to add new user from claims", context: { claims: userClaims } }) | ||
await adapter.addNewUserFromClaims(userClaims) | ||
} | ||
|
||
export default { | ||
getUserById, | ||
scheduleUpdate, | ||
addNewUserFromClaims | ||
} |
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,50 @@ | ||
import log from '../../util/logging.js' | ||
import Cache from 'cache'; | ||
import redisHelper from '../../util/redis.js' | ||
import { getConfig } from '../../util/config.js'; | ||
|
||
const redisClient = redisHelper.getClient() | ||
|
||
let idpRedisResponse = new Cache(60 * 1000); | ||
|
||
async function runUpdate() { | ||
return true | ||
} | ||
|
||
async function getUserById(id) { | ||
var idpResponse = idpRedisResponse.get(`veriflow:users:${id}`) | ||
if (idpResponse) { | ||
log.trace(`Returning IDP user ${id} from cache`) | ||
return idpResponse | ||
} else { | ||
try { | ||
log.debug("Cache miss, returning results from Redis") | ||
var idpResponse = JSON.parse(await redisClient.get(`veriflow:users:${id}`)) | ||
idpRedisResponse.put(`veriflow:users:${id}`, idpResponse) | ||
return idpResponse | ||
} catch (error) { | ||
log.error({ message: "Error getting user by ID", error: error.message }) | ||
return null | ||
} | ||
} | ||
} | ||
|
||
async function addNewUserFromClaims(claims) { | ||
var currentConfig = getConfig() | ||
var userId = claims[currentConfig.idp_provider_user_id_claim] | ||
|
||
var userData = { | ||
id: userId, | ||
mail: claims.email, | ||
...claims | ||
}; | ||
|
||
await redisClient.set(`veriflow:users:${userId}`, JSON.stringify(userData)) | ||
await redisClient.expire(`veriflow:users:${userId}`, 87000); // expire in 24 hours | ||
} | ||
|
||
export default { | ||
runUpdate, | ||
getUserById, | ||
addNewUserFromClaims | ||
}; |
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