示例#1
0
  def Run(self, args):
    client = devices.DevicesClient()

    device_ref = args.CONCEPTS.device.Parse()
    new_credential = util.ParseCredential(
        args.path, args.type, args.expiration_time, messages=client.messages)

    credentials = client.Get(device_ref).credentials
    if len(credentials) >= util.MAX_PUBLIC_KEY_NUM:
      raise util.InvalidPublicKeySpecificationError(
          'Cannot create a new public key credential for this device; '
          'maximum {} keys are allowed.'.format(util.MAX_PUBLIC_KEY_NUM))
    credentials.append(new_credential)
    response = client.Patch(device_ref, credentials=credentials)
    log.CreatedResource(device_ref.Name(), 'credentials for device')
    return response
示例#2
0
    def Run(self, args):
        client = devices.DevicesClient()

        device_ref = util.ParseDevice(args.device,
                                      registry=args.registry,
                                      region=args.region)
        new_credential = util.ParseCredential(args.path,
                                              args.type,
                                              args.expiration_time,
                                              messages=client.messages)

        credentials = client.Get(device_ref).credentials
        if len(credentials) >= util.MAX_PUBLIC_KEY_NUM:
            raise util.InvalidPublicKeySpecificationError(
                'Cannot create a new public key credential for this device; '
                'maximum {} keys are allowed.'.format(util.MAX_PUBLIC_KEY_NUM))
        credentials.append(new_credential)
        return client.Patch(device_ref, credentials=credentials)