Skip to content

Commit

Permalink
Propagate user attributes to fusion map
Browse files Browse the repository at this point in the history
  • Loading branch information
Skaar, Bjørn-Andre committed Aug 2, 2023
1 parent ed09d56 commit 059740f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ private Collection<Object> publishApps(
User user = userProvider.getUser(region);
Map<String, Object> fusion = new HashMap<>();
fusion.putAll((Map<String, Object>) requestDTO.getOptions());
// Substitute userAttribute value with actual value from user's attributes map
// This is a hack while we wait for this issue to be fixed: /~https://github.com/InseeFrLab/onyxia-web/issues/410
if (fusion.containsKey("userAttributes") && fusion.get("userAttributes") != null) {
Map<String, Object> props = (Map<String, Object>) fusion.get("userAttributes");
props.replace("value", user.getAttributes().getOrDefault(props.get("userAttribute"), ""));
}
return helmAppsService.installApp(
region, project, requestDTO, catalogId, pkg, user, fusion, skipTlsVerify, caFile);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ public class NoSecurityUserProvider {

@Bean
public UserProvider getUserProvider() {
return (Region region) ->
User.newInstance()
.setEmail("toto@tld.fr")
.setNomComplet("John doe")
.setIdep("default")
.setIp(
httpRequestUtils.getClientIpAddressIfServletRequestExist(
((ServletRequestAttributes)
RequestContextHolder
.currentRequestAttributes())
.getRequest()))
.build();
return (Region region) -> {
final User user = User.newInstance()
.setEmail("toto@tld.fr")
.setNomComplet("John doe")
.setIdep("default")
.setIp(
httpRequestUtils.getClientIpAddressIfServletRequestExist(
((ServletRequestAttributes)
RequestContextHolder
.currentRequestAttributes())
.getRequest()))
.build();
user.getAttributes().put("preferred_username", "toto");
user.getAttributes().put("access_token", "mock-token-string");
return user;
};
}
}

0 comments on commit 059740f

Please sign in to comment.