示例#1
0
def ConvertEmailToMembershipResourceName(
    group_email, member_email, group_arg_name, member_arg_name):
  """Convert email to membership resource name.

  Args:
    group_email: group email
    member_email: member email
    group_arg_name: argument/parameter name related to group info
    member_arg_name: argument/parameter name related to member info

  Returns:
    Membership Id (e.g. groups/11zu0gzc3tkdgn2/memberships/1044279104595057141)

  """

  # Resource name example: groups/03qco8b4452k99t
  group_id = groups_hooks.ConvertEmailToResourceName(
      group_email, group_arg_name)

  lookup_membership_name_resp = ci_client.LookupMembershipName(
      group_id, member_email)

  if 'name' in lookup_membership_name_resp:
    return lookup_membership_name_resp['name']

  # If there is no group exists (or deleted) for the given group email,
  # print out an error message.
  parameter_name = group_arg_name + ', ' + member_arg_name
  error_msg = ('There is no such a membership associated with the specified '
               'arguments:{}, {}').format(group_email, member_email)

  raise exceptions.InvalidArgumentException(parameter_name, error_msg)
示例#2
0
def SetMembershipResourceName(unused_ref, args, request):
    """Set membership resource name to request.name.

  Args:
    unused_ref: unused.
    args: The argparse namespace.
    request: The request to modify.
  Returns:
    The updated request.
  """

    group_id = ''
    if args.IsSpecified('group_email'):
        group_id = groups_hooks.ConvertEmailToResourceName(
            args.group_email, 'group_email')
    else:
        raise exceptions.InvalidArgumentException(
            'Must specify group-email argument.')

    member_id = ''
    if args.IsSpecified('group_email') and args.IsSpecified('member_email'):
        member_id = ConvertEmailToMembershipResourceName(
            args.group_email, args.member_email, 'group_email', 'member_email')
    else:
        raise exceptions.InvalidArgumentException(
            'Must specify member-email argument.')

    name = 'groups/' + group_id + '/memberships/' + member_id
    if hasattr(request, 'group'):
        request.group.name = name
    else:
        request.name = name

    return request
示例#3
0
def ConvertEmailToMembershipResourceName(version, args, group_arg_name,
                                         member_arg_name):
    """Convert email to membership resource name.

  Args:
    version: Release track information
    args: The argparse namespace
    group_arg_name: argument/parameter name related to group info
    member_arg_name: argument/parameter name related to member info

  Returns:
    Membership Id (e.g. groups/11zu0gzc3tkdgn2/memberships/1044279104595057141)

  """

    # Resource name example: groups/03qco8b4452k99t
    group_id = groups_hooks.ConvertEmailToResourceName(version,
                                                       args.group_email,
                                                       group_arg_name)

    try:
        return ci_client.LookupMembershipName(version, group_id,
                                              args.member_email).name
    except (apitools_exceptions.HttpForbiddenError,
            apitools_exceptions.HttpNotFoundError):
        # If there is no group exists (or deleted) for the given group email,
        # print out an error message.
        parameter_name = group_arg_name + ', ' + member_arg_name
        error_msg = (
            'There is no such membership associated with the specified '
            'arguments: {}, {}').format(args.group_email, args.member_email)

        raise exceptions.InvalidArgumentException(parameter_name, error_msg)
示例#4
0
def SetMembershipParent(unused_ref, args, request):
    """Set resource name to request.parent.

  Args:
    unused_ref: unused.
    args: The argparse namespace.
    request: The request to modify.
  Returns:
    The updated request.
  """

    if args.IsSpecified('group_email'):
        # Resource name example: groups/03qco8b4452k99t
        request.parent = groups_hooks.ConvertEmailToResourceName(
            args.group_email, 'group_email')

    return request
示例#5
0
def SetTransitiveMembershipParent(unused_ref, args, request):
    """Set resource name to request.parent.

  Args:
    unused_ref: unused.
    args: The argparse namespace.
    request: The request to modify.

  Returns:
    The updated request.

  """

    version = groups_hooks.GetApiVersion(args)
    if hasattr(args, 'group_email') and args.IsSpecified('group_email'):
        # Resource name example: groups/03qco8b4452k99t
        request.parent = groups_hooks.ConvertEmailToResourceName(
            version, args.group_email, '--group-email')
    else:
        # If this hook is used and no group_emails provided then set the parent to
        # be the groups wildcard.
        request.parent = 'groups/-'
    return request