Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OPAProperties to structure properties #21

Closed
ali-jalaal opened this issue Jan 26, 2025 · 1 comment
Closed

Add OPAProperties to structure properties #21

ali-jalaal opened this issue Jan 26, 2025 · 1 comment

Comments

@ali-jalaal
Copy link
Contributor

Expected behaviour

Externalize OPA-related properties using configuration properties to improve configurability.

Actual behaviour

We have some properties such as opaURL, opaPath, and reasonKey. Currently, these properties can only be set through code. Moreover, there are some constants which can be defined as properties.

How to improve

By externalizing these properties using a @ConfigurationProperties (link1, link2), we could:

  • manage these properties as a Spring bean
  • setting default values
  • standardize their name
  • validate them
  • enable client applications to change them through properties/yaml file, environment variables, system properties, ... without rebuilding code

We could define OPAProperties class:

...
@ConfigurationProperties(prefix = "opa")
@Data
@NoArgsConstructor
public class OpaProperties {
    private String url = "http://localhost:8181";
    private String path;
    private String reasonKey = "en";
    private String requestContextType = "http";
    private String requestContextSubjectType = "java_authentication";
    private String requestResourceType = "endpoint";
    ...
}

and use these properties in classes like OPAAuthorizationManager. (request... properties can also be wrapped in a separate object.)

On the flip side, client applications can easily define and change these properties, for instance in:

  • application.yaml:
opa:
  url: http://localhost:8181
  path: tickets/main
  reason-key: de
  ...
  • command-line arguments (system properties):
java -jar myapp.jar --opa.url=http://localhost:8181 --opa.path=tickets/main
  • environment variables:
export OPA_URL=http://localhost:8181
export OPA_PATH=tickets/main

java -jar myapp.jar
@chendrix
Copy link
Collaborator

This was actually on our internal roadmap and we never got to it, so this also looks good to me.

ali-jalaal added a commit to ali-jalaal/opa-springboot that referenced this issue Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants