public String bucketId(RateLimitingConfig config, BucketIdBuilderContext context) {
        Api api = context.getApi();
        StringBuilder builder = new StringBuilder();
        // Public API in this branch
        if (context.getContract() == null) {
            builder.append("PUBLIC||"); //$NON-NLS-1$
            builder.append("||"); //$NON-NLS-1$
            builder.append(api.getOrganizationId());
            builder.append("||"); //$NON-NLS-1$
            builder.append(api.getApiId());
            builder.append("||"); //$NON-NLS-1$
            builder.append(api.getVersion());
            if (config.getGranularity() == RateLimitingGranularity.User) {
                String user = context.getUserSupplier().get();
                builder.append("||"); //$NON-NLS-1$
                builder.append(user);
            } else if (config.getGranularity() == RateLimitingGranularity.Ip) {
                builder.append("||"); //$NON-NLS-1$
                builder.append(context.getRemoteAddr());
            } else if (config.getGranularity() == RateLimitingGranularity.Api) {
            } else {
                return NO_CLIENT_AVAILABLE;
            }
        } else {
            // Have a fully valid contract in this branch.
            ApiContract contract = context.getContract();
            Client client = contract.getClient();
            String apiKey = client.getApiKey();
            builder.append(apiKey);
            if (config.getGranularity() == RateLimitingGranularity.User) {
                String user = context.getUserSupplier().get();
                if (user == null) {
                    return NO_USER_AVAILABLE;
                } else {
                    builder.append("||USER||"); //$NON-NLS-1$
                    builder.append(client.getOrganizationId());
                    builder.append("||"); //$NON-NLS-1$
                    builder.append(client.getClientId());
                    builder.append("||"); //$NON-NLS-1$
                    builder.append(user);
                }
            } else if (config.getGranularity() == RateLimitingGranularity.Client) {
                builder.append(apiKey);
                builder.append("||APP||"); //$NON-NLS-1$
                builder.append(client.getOrganizationId());
                builder.append("||"); //$NON-NLS-1$
                builder.append(client.getClientId());
            } else if (config.getGranularity() == RateLimitingGranularity.Ip) {
                builder.append(apiKey);
                builder.append("||IP||"); //$NON-NLS-1$
                builder.append(client.getOrganizationId());
                builder.append("||"); //$NON-NLS-1$
                builder.append(context.getRemoteAddr());
            } else {
                builder.append(apiKey);
                builder.append("||SERVICE||"); //$NON-NLS-1$
                builder.append(api.getOrganizationId());
                builder.append("||"); //$NON-NLS-1$
                builder.append(api.getApiId());
            }
        }
        return builder.toString();
    }
Creates the ID of the rate bucket to use.  The ID is composed differently
depending on the configuration of the policy.
gateway/engine/policies/src/main/java/io/apiman/gateway/engine/policies/limiting/BucketFactory.java