DataDog/datadog-api-client-java

Confusing documentation for setting app key, is it needed at all?

dan-lind opened this issue · 2 comments

Describe the bug

Looking at the documentation at
https://github.com/DataDog/datadog-api-client-java#documentation-for-authorization
to set the appKey and apiKey, we should do

HashMap<String, String> secrets = new HashMap<>();
secrets.put("apiKeyAuth", "<YOUR API KEY>");
secrets.put("appKeyAuth", "<YOUR APPLICATION KEY>");
generalApiClient.configureApiKeys(secrets);

But looking at the source for configureApiKeys, it looks like this

public ApiClient configureApiKeys(Map<String, String> secrets) {
    for (Map.Entry<String, Authentication> authEntry : authentications.entrySet()) {
      Authentication auth = authEntry.getValue();
      if (auth instanceof ApiKeyAuth) {
        String name = authEntry.getKey();
        if (secrets.containsKey(name)) {
          ((ApiKeyAuth) auth).setApiKey(secrets.get(name));
        }
      }
    }
    return this;
  }

This method doesn't bother looking at the appKey at all, only the api key.
I'm not sure if this is an issue with the documentation, or if it's an actual bug in the code.

Expected behavior
I expect the app key to be configured according to the example in the documentation,
or if the the app key is not required, remove it from the example in the docs.

Environment and Versions (please complete the following information):
2.12.0

Hi,

The method does look at the app key, as it iterates on all items in the secrets map. So name is set first to apiKeyAuth then appKeyAuth in the loop. The internal object is still named ApiKeyAuth but there are 2 of them, the API key and the Application key. Does that make sense? Thanks.

Oh I see, sorry for the confusion 😅