Search in sources :

Example 1 with IamResourceProto

use of com.google.api.codegen.IamResourceProto in project toolkit by googleapis.

the class GapicInterfaceConfig method createIamResources.

/**
 * Creates a list of fields that can be turned into IAM resources
 */
private static ImmutableList<FieldModel> createIamResources(Model model, List<IamResourceProto> resources) {
    ImmutableList.Builder<FieldModel> fields = ImmutableList.builder();
    for (IamResourceProto resource : resources) {
        TypeRef type = model.getSymbolTable().lookupType(resource.getType());
        if (type == null) {
            throw new IllegalArgumentException("type not found: " + resource.getType());
        }
        if (!type.isMessage()) {
            throw new IllegalArgumentException("type must be a message: " + type);
        }
        Field field = type.getMessageType().lookupField(resource.getField());
        if (field == null) {
            throw new IllegalArgumentException(String.format("type %s does not have field %s", resource.getType(), resource.getField()));
        }
        fields.add(new ProtoField(field));
    }
    return fields.build();
}
Also used : Field(com.google.api.tools.framework.model.Field) ImmutableList(com.google.common.collect.ImmutableList) TypeRef(com.google.api.tools.framework.model.TypeRef) IamResourceProto(com.google.api.codegen.IamResourceProto)

Aggregations

IamResourceProto (com.google.api.codegen.IamResourceProto)1 Field (com.google.api.tools.framework.model.Field)1 TypeRef (com.google.api.tools.framework.model.TypeRef)1 ImmutableList (com.google.common.collect.ImmutableList)1