Search in sources :

Example 1 with Service

use of com.google.api.Service in project toolkit by googleapis.

the class ProductServiceConfig method getAuthScopes.

/**
 * Return a list of scopes for authentication.
 */
public List<String> getAuthScopes(Model model) {
    Set<String> result = new TreeSet<>();
    Service config = model.getServiceConfig();
    Authentication auth = config.getAuthentication();
    for (AuthenticationRule rule : auth.getRulesList()) {
        // Scopes form a union and the union is used for down-scoping, so adding more scopes that
        // are subsets of the others already in the union essentially has no effect.
        // We are doing this for implementation simplicity so we don't have to compute which scopes
        // are subsets of the others.
        String scopesString = rule.getOauth().getCanonicalScopes();
        for (String scope : scopesString.split(",")) {
            result.add(scope.trim());
        }
    }
    return new ArrayList<>(result);
}
Also used : TreeSet(java.util.TreeSet) Authentication(com.google.api.Authentication) AuthenticationRule(com.google.api.AuthenticationRule) ArrayList(java.util.ArrayList) Service(com.google.api.Service)

Example 2 with Service

use of com.google.api.Service in project toolkit by googleapis.

the class PhpGapicSurfaceTransformer method generateRestInterfaceConfigViews.

private List<RestInterfaceConfigView> generateRestInterfaceConfigViews(GapicInterfaceContext context) {
    List<RestInterfaceConfigView> configViews = new ArrayList<>();
    GapicInterfaceConfig interfaceConfig = context.getInterfaceConfig();
    SurfaceNamer namer = context.getNamer();
    Map<String, List<HttpRule>> interfaces = new TreeMap<>();
    Service serviceConfig = serviceModel.getServiceConfig();
    for (MethodModel methodModel : context.getSupportedMethods()) {
        GapicMethodContext methodContext = context.asDynamicMethodContext(methodModel);
        MethodConfig methodConfig = methodContext.getMethodConfig();
        Method method = methodContext.getMethod();
        // REST does not support streaming methods
        if (methodConfig.isGrpcStreaming()) {
            continue;
        }
        String interfaceName = methodConfig.getRerouteToGrpcInterface() == null ? context.getInterface().getFullName() : methodConfig.getRerouteToGrpcInterface();
        HttpRule httpRule = getHttpRule(method.getOptionFields()).toBuilder().setSelector(String.format("%s.%s", interfaceName, method.getSimpleName())).build();
        addHttpRuleToMap(interfaces, interfaceName, httpRule);
    }
    for (HttpRule httpRule : serviceConfig.getHttp().getRulesList()) {
        String selector = httpRule.getSelector();
        String interfaceName = selector.substring(0, selector.lastIndexOf("."));
        addHttpRuleToMap(interfaces, interfaceName, httpRule);
    }
    for (Map.Entry<String, List<HttpRule>> entry : interfaces.entrySet()) {
        configViews.add(generateRestInterfaceConfigView(entry.getKey(), entry.getValue(), namer));
    }
    return configViews;
}
Also used : MethodModel(com.google.api.codegen.config.MethodModel) RestInterfaceConfigView(com.google.api.codegen.viewmodel.RestInterfaceConfigView) ArrayList(java.util.ArrayList) GapicInterfaceConfig(com.google.api.codegen.config.GapicInterfaceConfig) Service(com.google.api.Service) Method(com.google.api.tools.framework.model.Method) TreeMap(java.util.TreeMap) HttpRule(com.google.api.HttpRule) MethodConfig(com.google.api.codegen.config.MethodConfig) GapicMethodContext(com.google.api.codegen.transformer.GapicMethodContext) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) TreeMap(java.util.TreeMap) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 3 with Service

use of com.google.api.Service in project toolkit by googleapis.

the class ProtoApiModel method getAuthScopes.

@Override
public List<String> getAuthScopes() {
    Set<String> result = new TreeSet<>();
    Service config = protoModel.getServiceConfig();
    Authentication auth = config.getAuthentication();
    for (AuthenticationRule rule : auth.getRulesList()) {
        // Scopes form a union and the union is used for down-scoping, so adding more scopes that
        // are subsets of the others already in the union essentially has no effect.
        // We are doing this for implementation simplicity so we don't have to compute which scopes
        // are subsets of the others.
        String scopesString = rule.getOauth().getCanonicalScopes();
        for (String scope : scopesString.split(",")) {
            result.add(scope.trim());
        }
    }
    return new ArrayList<>(result);
}
Also used : TreeSet(java.util.TreeSet) Authentication(com.google.api.Authentication) AuthenticationRule(com.google.api.AuthenticationRule) ArrayList(java.util.ArrayList) Service(com.google.api.Service)

Aggregations

Service (com.google.api.Service)3 ArrayList (java.util.ArrayList)3 Authentication (com.google.api.Authentication)2 AuthenticationRule (com.google.api.AuthenticationRule)2 TreeSet (java.util.TreeSet)2 HttpRule (com.google.api.HttpRule)1 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)1 MethodConfig (com.google.api.codegen.config.MethodConfig)1 MethodModel (com.google.api.codegen.config.MethodModel)1 GapicMethodContext (com.google.api.codegen.transformer.GapicMethodContext)1 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)1 RestInterfaceConfigView (com.google.api.codegen.viewmodel.RestInterfaceConfigView)1 Method (com.google.api.tools.framework.model.Method)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1