Skip to content

Commit

Permalink
feat: add additional velocity variables (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcScheib committed Nov 1, 2023
1 parent 64f231c commit bfcb327
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@

@ApplicationScoped
public class ExportSecrets {
private static final String TEMPLATE_NAME_PLACEHOLDER = "client-name";
private static final String VARIABLE_CLIENT_ID = "client_id";
private static final String VARIABLE_REALM = "realm";
private static final String VARIABLE_AUTH_SERVER_URL = "auth_server_url";
private static final String VARIABLE_SECRET = "secret";

@Inject
ExportSecretsCommandConfiguration configuration;
Expand Down Expand Up @@ -87,13 +90,16 @@ private void writeFiles(final ClientRepresentation client, final Template templa
private String generateFileContent(final ClientRepresentation client, final Template template) {
return VelocityUtils.mergeTemplate(template, VelocityUtils.createVelocityContext(
Map.ofEntries(
Map.entry("secret", client.getSecret())
Map.entry(VARIABLE_REALM, configuration.getRealmName()),
Map.entry(VARIABLE_AUTH_SERVER_URL, configuration.getServer()),
Map.entry(VARIABLE_SECRET, client.getSecret()),
Map.entry(VARIABLE_CLIENT_ID, client.getClientId())
)
));
}

private Path getTargetFile(final String clientId, final String templateName) {
final String filename = templateName.replace(TEMPLATE_NAME_PLACEHOLDER, clientId);
final String filename = templateName.replace(VARIABLE_CLIENT_ID, clientId);
return Paths.get(configuration.getOutputDirectory(), filename);
}
}

0 comments on commit bfcb327

Please sign in to comment.