Skip to content

Commit

Permalink
Alter configuration: improve json format for user tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickR315516 authored Dec 2, 2024
1 parent 3ddfb4f commit f1b9be8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
15 changes: 5 additions & 10 deletions Sources/PIRService/PIRService.docc/TestingInstructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,13 @@ Copy the following to a file called `service-config.json`.
{
"users": [
{
"tier1": {}
"tier": "tier1",
"tokens": ["AAAA"]
},
[
"AAAA"
],
{
"tier2": {}
},
[
"BBBB",
"CCCC"
]
"tier": "tier2",
"tokens": ["BBBB", "CCCC"]
}
],
"usecases": [
{
Expand Down
18 changes: 12 additions & 6 deletions Sources/PIRService/ReloadService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ struct ServerConfiguration: Codable {
let versionCount: Int?
}

struct UserGroup: Codable {
let tier: UserTier
let tokens: [String]
}

let issuerRequestUri: String?
let users: [UserTier: [String]]
let users: [UserGroup]
let usecases: [Usecase]
}

Expand Down Expand Up @@ -71,17 +76,18 @@ actor ReloadService: Service {
let config = try JSONDecoder().decode(ServerConfiguration.self, from: configData)

var allowedUsers: [String: UserTier] = [:]
for (tier, users) in config.users {
for user in users {
if let existingTier = allowedUsers[user],
for userGroup in config.users {
let tier = userGroup.tier
for token in userGroup.tokens {
if let existingTier = allowedUsers[token],
existingTier != tier
{
logger.warning("""
User token '\(user)' is assigned to multiple tiers '\(existingTier)' \
User token '\token' is assigned to multiple tiers '\(existingTier)' \
and '\(tier)', using the latter.
""")
}
allowedUsers[user] = tier
allowedUsers[token] = tier
}
}
await privacyPassState.userAuthenticator.update(allowList: allowedUsers)
Expand Down

0 comments on commit f1b9be8

Please sign in to comment.