Clément Denis
Clément Denis

Reputation: 11

What is useDatastoreForAdditionalConfig in the @Api / @ApiClass annotations of Google Cloud Endpoints

When looking at the Javadoc for @com.google.api.server.spi.config.Api of Google Cloud Endpoints Java annotations, I found a property that is not documented anywhere : useDatastoreForAdditionalConfig.

It looks like it provides a way to override Cloud Endpoints configuration from the datastore, but I did not find how to use it.

Does anyone know if it works and how it works ?

Upvotes: 1

Views: 167

Answers (1)

Bruno Carneiro
Bruno Carneiro

Reputation: 71

It looks like it provides a way to override Cloud Endpoints configuration from the datastore, but I did not find how to use it.

Yes you can override Cloud Endpoints configuration. It is possible to override settings like OAuth client ids, scopes and audiences.

Does anyone know if it works and how it works ?

The good news is it works!

  1. In you @Api annotation enable the property useDatastoreForAdditionalConfig. Like this:

    @Api(name = "myapi", version = "v1", authLevel = AuthLevel.REQUIRED, clientIds = {Constants.WEB_CLIENT_ID, Constants.API_EXPLORER_CLIENT_ID}, scopes = {Constants.EMAIL_SCOPE}, useDatastoreForAdditionalConfig = AnnotationBoolean.TRUE)

  2. Create a new kind on Datastore named GoogleCloudEndpointConfiguration. It must have the properties (typed as String or List) clientIds, scopes and audiences. Example of this entity written in Java and using Objectify.

    @Entity public class GoogleCloudEndpointConfiguration extends BaseEntity {

    @Id
    private String className;
    
    private List<String> clientIds;
    
    private List<String> scopes;
    
    private List<String> audiences;
    

    ... }

  3. For each endpoint you want to configure, add an entity on that kind with its id being its class name (with package).

Upvotes: 1

Related Questions