-
Notifications
You must be signed in to change notification settings - Fork 16
Add batch secret retrieval API support #127
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,61 +7,100 @@ | |
| import java.net.URI; | ||
|
|
||
| /** | ||
| * An <code>Endpoints</code> instance provides endpoint URIs for the various conjur services. | ||
| * An <code>Endpoints</code> instance provides endpoint URIs for the various Conjur services. | ||
| * | ||
| * <p>The canonical way to construct an {@code Endpoints} is from an appliance URL and account name. | ||
| * All service URIs are derived from these two values:</p> | ||
| * <ul> | ||
| * <li>Authentication: {@code {applianceUrl}/authn/{account}}</li> | ||
| * <li>Secrets (single): {@code {applianceUrl}/secrets/{account}/variable}</li> | ||
| * <li>Secrets (batch): {@code {applianceUrl}/secrets}</li> | ||
| * </ul> | ||
| * | ||
| * <p>For non-standard authenticators (LDAP, OIDC, etc.), supply a custom authn URL.</p> | ||
| */ | ||
| public class Endpoints implements Serializable { | ||
|
|
||
| private static final long serialVersionUID = 1L; | ||
| private final String applianceUrl; | ||
| private final String account; | ||
| private final URI authnUri; | ||
| private final URI secretsUri; | ||
|
|
||
| public Endpoints(final URI authnUri, final URI secretsUri){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing The old constructors should stay, adjusted for the new functionality. |
||
| this.authnUri = Args.notNull(authnUri, "authnUri"); | ||
| this.secretsUri = Args.notNull(secretsUri, "secretsUri"); | ||
| /** | ||
| * Create Endpoints from appliance URL and account, using standard authentication. | ||
| * | ||
| * @param applianceUrl the base Conjur appliance URL (e.g. {@code https://conjur.example.com}) | ||
| * @param account the Conjur account name (e.g. {@code conjur} for SaaS, or your org name) | ||
| */ | ||
| public Endpoints(String applianceUrl, String account) { | ||
| this(applianceUrl, account, applianceUrl + "/authn"); | ||
| } | ||
|
|
||
| public Endpoints(String authnUri, String secretsUri){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing as with the other constructor. |
||
| this(URI.create(authnUri), URI.create(secretsUri)); | ||
| /** | ||
| * Create Endpoints from appliance URL, account, and a custom authentication URL. | ||
| * Use this when authenticating via a non-standard authenticator (LDAP, OIDC, etc.). | ||
| * | ||
| * @param applianceUrl the base Conjur appliance URL | ||
| * @param account the Conjur account name | ||
| * @param authnUrl the authentication service base URL | ||
| * (e.g. {@code https://conjur.example.com/authn-ldap/my-service}) | ||
| */ | ||
| public Endpoints(String applianceUrl, String account, String authnUrl) { | ||
| this.applianceUrl = Args.notNull(applianceUrl, "applianceUrl"); | ||
| this.account = Args.notNull(account, "account"); | ||
| this.authnUri = URI.create(String.format("%s/%s", authnUrl, account)); | ||
| this.secretsUri = URI.create(String.format("%s/secrets/%s/variable", applianceUrl, account)); | ||
| } | ||
|
|
||
| public URI getAuthnUri(){ return authnUri; } | ||
| public URI getAuthnUri() { return authnUri; } | ||
|
|
||
| public URI getSecretsUri() { | ||
| return secretsUri; | ||
| public URI getSecretsUri() { return secretsUri; } | ||
|
|
||
| public String getAccount() { return account; } | ||
|
|
||
| public String getApplianceUrl() { return applianceUrl; } | ||
|
|
||
| /** | ||
| * Returns the base URI for batch secret retrieval: {@code {applianceUrl}/secrets} | ||
| * | ||
| * @return the batch secrets URI | ||
| */ | ||
| public URI getBatchSecretsUri() { | ||
| return URI.create(applianceUrl + "/secrets"); | ||
| } | ||
|
|
||
| public static Endpoints fromSystemProperties(){ | ||
| /** | ||
| * Create Endpoints from system properties / environment variables. | ||
| * Reads {@code CONJUR_ACCOUNT}, {@code CONJUR_APPLIANCE_URL}, and optionally {@code CONJUR_AUTHN_URL}. | ||
| */ | ||
| public static Endpoints fromSystemProperties() { | ||
| String account = Properties.getMandatoryProperty(Constants.CONJUR_ACCOUNT_PROPERTY); | ||
| String applianceUrl = Properties.getMandatoryProperty(Constants.CONJUR_APPLIANCE_URL_PROPERTY); | ||
| String authnUrl = Properties.getMandatoryProperty(Constants.CONJUR_AUTHN_URL_PROPERTY, applianceUrl + "/authn"); | ||
| String authnUrl = Properties.getMandatoryProperty( | ||
| Constants.CONJUR_AUTHN_URL_PROPERTY, applianceUrl + "/authn"); | ||
|
|
||
| return new Endpoints( | ||
| getAuthnServiceUri(authnUrl, account), | ||
| getServiceUri("secrets", account, "variable") | ||
| ); | ||
| return new Endpoints(applianceUrl, account, authnUrl); | ||
| } | ||
|
|
||
| public static Endpoints fromCredentials(Credentials credentials){ | ||
| /** | ||
| * Create Endpoints using the authentication URL from the given credentials. | ||
| * Account and appliance URL are read from system properties / environment variables. | ||
| */ | ||
| public static Endpoints fromCredentials(Credentials credentials) { | ||
| String account = Properties.getMandatoryProperty(Constants.CONJUR_ACCOUNT_PROPERTY); | ||
| return new Endpoints( | ||
| getAuthnServiceUri(credentials.getAuthnUrl(), account), | ||
| getServiceUri("secrets", account, "variable") | ||
| ); | ||
| } | ||
|
|
||
| private static URI getAuthnServiceUri(String authnUrl, String accountName) { | ||
| return URI.create(String.format("%s/%s", authnUrl, accountName)); | ||
| } | ||
| String applianceUrl = Properties.getMandatoryProperty(Constants.CONJUR_APPLIANCE_URL_PROPERTY); | ||
|
|
||
| private static URI getServiceUri(String service, String accountName, String path){ | ||
| return URI.create(String.format("%s/%s/%s/%s", Properties.getMandatoryProperty(Constants.CONJUR_APPLIANCE_URL_PROPERTY), service, accountName, path)); | ||
| return new Endpoints(applianceUrl, account, credentials.getAuthnUrl()); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Endpoints{" + | ||
| "authnUri=" + authnUri + | ||
| "secretsUri=" + secretsUri + | ||
| "applianceUrl=" + applianceUrl + | ||
| ", account=" + account + | ||
| ", authnUri=" + authnUri + | ||
| ", secretsUri=" + secretsUri + | ||
| '}'; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an unnecessary shortcut. This method is already defined in the
variablesand should be accessed through there.