createProfile

var policies = [
  {roleId: 'myrole'},
  {
    roleId: 'default', 
    restrictedTo: [
      {index: 'index1'}, 
      {index: 'index2', collections: ['foo', 'bar'] } 
    ] 
  }
];

// You can chose to replace the given profile if already exists
var options = {
  replaceIfExist: true
};

// Using callbacks (NodeJS or Web Browser)
kuzzle
  .security
  .createProfile('myprofile', policies, options, function(error, profile) {

  });

// Using promises (NodeJS)
kuzzle
  .security
  .createProfilePromise('myprofile', policies, options)
  .then(profile => {

  });
JSONObject[] policies = new JSONObject[]{
  new JSONObject().put("roleId", "myrole"),
  new JSONObject()
    .put("roleId", "default")
    .put("restrictedTo", new JSONArray()
      .put(new JSONObject().put("index", "index1"))
      .put(new JSONObject()
        .put("index", "index2")
        .put("collections",new JSONArray().put("foo").put("bar"))
      )
    )
};

Options opts = new Options().setReplaceIfExist(true);

kuzzle
  .security
  .createProfile("myprofile", policies, opts, new ResponseListener<Profile>() {
    @Override
    public void onSuccess(Profile profile) {

    }

    @Override
    public void onError(JSONObject error) {

    }
  });
<?php

use \Kuzzle\Kuzzle;
use \Kuzzle\Security\Profile;

$profileId = 'myProfile';
$policies = [
  [
    'roleId' => 'myRole'
  ],
  [
    'roleId' => 'anonymous',
    'restrictedTo' => [
      ['index' => 'my-second-index', 'collection' => ['my-collection']]
    ]
  ]
];

$kuzzle = new Kuzzle('localhost');
$security = $kuzzle->security();

try {
  $profile = $security->createProfile($profileId, $profileDefinition);

  // $profile instanceof Profile
}
catch (ErrorException $e) {

}

Create a new profile in Kuzzle.


createProfile(id, content, [options], callback)

ArgumentsTypeDescription
idstringUnique profile identifier
policiesarray of JSON objectsList of policies to apply to this profile
optionsstring(Optional) Optional arguments
callbackfunctionCallback handling the response

Options

FilterTypeDescriptionDefault
replaceIfExistbooleanIf the same profile already exists: throw an error if sets to false. Replace the existing profile otherwisefalse
queuablebooleanMark this request as (not) queuabletrue

Callback response

Resolves to a Profile object.