createComputer method

Future<CreateComputerResult> createComputer({
  1. required String computerName,
  2. required String directoryId,
  3. required String password,
  4. List<Attribute>? computerAttributes,
  5. String? organizationalUnitDistinguishedName,
})

Creates an Active Directory computer object in the specified directory.

May throw AuthenticationFailedException. May throw DirectoryUnavailableException. May throw EntityAlreadyExistsException. May throw EntityDoesNotExistException. May throw InvalidParameterException. May throw UnsupportedOperationException. May throw ClientException. May throw ServiceException.

Parameter computerName : The name of the computer account.

Parameter directoryId : The identifier of the directory in which to create the computer account.

Parameter password : A one-time password that is used to join the computer to the directory. You should generate a random, strong password to use for this parameter.

Parameter computerAttributes : An array of Attribute objects that contain any LDAP attributes to apply to the computer account.

Parameter organizationalUnitDistinguishedName : The fully-qualified distinguished name of the organizational unit to place the computer account in.

Implementation

Future<CreateComputerResult> createComputer({
  required String computerName,
  required String directoryId,
  required String password,
  List<Attribute>? computerAttributes,
  String? organizationalUnitDistinguishedName,
}) async {
  ArgumentError.checkNotNull(computerName, 'computerName');
  _s.validateStringLength(
    'computerName',
    computerName,
    1,
    15,
    isRequired: true,
  );
  ArgumentError.checkNotNull(directoryId, 'directoryId');
  ArgumentError.checkNotNull(password, 'password');
  _s.validateStringLength(
    'password',
    password,
    8,
    64,
    isRequired: true,
  );
  _s.validateStringLength(
    'organizationalUnitDistinguishedName',
    organizationalUnitDistinguishedName,
    1,
    2000,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'DirectoryService_20150416.CreateComputer'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'ComputerName': computerName,
      'DirectoryId': directoryId,
      'Password': password,
      if (computerAttributes != null)
        'ComputerAttributes': computerAttributes,
      if (organizationalUnitDistinguishedName != null)
        'OrganizationalUnitDistinguishedName':
            organizationalUnitDistinguishedName,
    },
  );

  return CreateComputerResult.fromJson(jsonResponse.body);
}