Example #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)
Example #2
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)