CreateKey

CreateKey( param_object )
CreateKey( param_object )
CreateKey( param_object )
CreateKey( param_object )
create_key( param_object )
create_key param_object
CreateKey( param_object )
CreateKey( param_object )

Description

CreateKey creates a new key to access a database with the specified param_object. It requires an admin key for authentication.

Parameters

Argument Type Definition and Requirements

param_object

Object

The param_object fields are described below.

param_object

Field Name Field Type Definition and Requirements

database

String

The logical name of an existing database.

role

String

The access roles include admin, server, server-readonly, or client.

priority

Number

Optional - A relative weight between 1 and 500, inclusive, indicating how many resources this key will be allowed to utilize. Defaults to 1. A higher number means more resources.

data

Object

Optional - This is user-defined metadata for the key. It is provided for the developer to store information at the key level.

Returns

An object containing the metadata about the results of CreateKey operations.

Field Name Field Type Definition and Requirements

ref

Reference

The reference is an automatically generated unique identifier within the database to the key that was created.

database

String

The name of the database the key belongs to.

role

String

The access role for this key.

ts

Long

The timestamp associated with the creation of the index.

secret

String

The key’s authentication secret. It is only present at creation. You must copy the key’s secret and store it securely for future use.

hashed_secret

String

The key’s hashed authentication secret.

Examples

The query below creates a key for the prydain database with an access role of server.

curl https://db.fauna.com/ \
    -u fnAChGwBacACAEZtRZFDXpyjIvq-sln34m-va4Km: \
    -d '{
          "create_key": {
            "object": { "database": { "database": "prydain" }, "role": "server" }
          }
        }'
client.Query(
  CreateKey(
    Obj("database", Database("prydain"), "role", "server")));
System.out.println(
      client.query(
          CreateKey(
              Obj(
                 "database", Database(Value("prydain")),
                 "role", Value("server")
              ))
        ).get());
result, _ := client.Query(
    f.CreateKey(
        f.Obj{"database": f.Database("prydain"), "role": "server"},
    ),
)

fmt.Println(result)
client.query(
  CreateKey(
    Obj("database" -> Database("prydain"), "role" -> "server")))
client.query(
  q.create_key(
    {"database": q.database("prydain"), "role": "server"}
  ))
$client.query do
  create_key database: database('prydain'), role: 'server'
end
client.query(
    CreateKey(
        Obj(
            "database" => Database("prydain"),
            "role" => "server"
        )
    )
)
client.query(
  q.CreateKey(
    { database: q.Database("prydain"), role: "server" }))
.then((ret) => console.log(ret))
HTTP/1.1 201 Created
{
  "resource": {
    "ref": { "@ref": "keys/181388642789360128" },
    "class": { "@ref": "keys" },
    "ts": 1509244539905476,
    "database": { "@ref": "databases/prydain" },
    "role": "server",
    "secret": "fnAChGwCc8ACAJ14XId4jxQlr2sn496g1J7Ysq42",
    "hashed_secret": "$2a$05$xVX/E8zRRLTPgRvVGacOJOVUDa9UdaY9wTGoDOCbqoLQj9yJHwNsO"
  }
}
{
  "ref": { "@ref": "keys/181388642789360128" },
  "class": { "@ref": "keys" },
  "ts": 1509244539905476,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "fnAChGwCc8ACAJ14XId4jxQlr2sn496g1J7Ysq42",
  "hashed_secret": "$2a$05$xVX/E8zRRLTPgRvVGacOJOVUDa9UdaY9wTGoDOCbqoLQj9yJHwNsO"
}
{
  ref: ref(id = "199665350603702784", class = ref(id = "keys")),
  ts: 1526674566735005,
  database: ref(id = "prydain", class = ref(id = "databases")),
  role: "server",
  secret: "fnACxVqUGLACAMdiPcGMWvtTPn__pBKRjqwjkj38",
  hashed_secret: "$2a$05$bwfQwJxBr468C15NHM37KOo4krZbdvxiEXyDZ6Xll6DN5MhAjSvqa"
}
map[ref:{181388642789360128 0xc4201c3a40 <nil>} ts:1509244539905476 database:{prydain 0xc4201c3be0 <nil>} role:server secret:fnAChGwCc8ACAJ14XId4jxQlr2sn496g1J7Ysq42 hashed_secret:$2a$05$xVX/E8zRRLTPgRvVGacOJOVUDa9UdaY9wTGoDOCbqoLQj9yJHwNsO]
{
  "ref": { "@ref": "keys/181388642789360128" },
  "class": { "@ref": "keys" },
  "ts": 1509244539905476,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "fnAChGwCc8ACAJ14XId4jxQlr2sn496g1J7Ysq42",
  "hashed_secret": "$2a$05$xVX/E8zRRLTPgRvVGacOJOVUDa9UdaY9wTGoDOCbqoLQj9yJHwNsO"
}
{
  "ref": { "@ref": "keys/181388642789360128" },
  "class": { "@ref": "keys" },
  "ts": 1509244539905476,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "fnAChGwCc8ACAJ14XId4jxQlr2sn496g1J7Ysq42",
  "hashed_secret": "$2a$05$xVX/E8zRRLTPgRvVGacOJOVUDa9UdaY9wTGoDOCbqoLQj9yJHwNsO"
}
{
  "ref": { "@ref": "keys/181388642789360128" },
  "class": { "@ref": "keys" },
  "ts": 1509244539905476,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "fnAChGwCc8ACAJ14XId4jxQlr2sn496g1J7Ysq42",
  "hashed_secret": "$2a$05$xVX/E8zRRLTPgRvVGacOJOVUDa9UdaY9wTGoDOCbqoLQj9yJHwNsO"
}
{
  "ref": { "@ref": "keys/181388642789360128" },
  "class": { "@ref": "keys" },
  "ts": 1509244539905476,
  "database": { "@ref": "databases/prydain" },
  "role": "server",
  "secret": "fnAChGwCc8ACAJ14XId4jxQlr2sn496g1J7Ysq42",
  "hashed_secret": "$2a$05$xVX/E8zRRLTPgRvVGacOJOVUDa9UdaY9wTGoDOCbqoLQj9yJHwNsO"
}
{ ref: Ref(id=200295040051839490, class=Ref(id=keys)),
  ts: 1527275085327966,
  database: Ref(id=prydain, class=Ref(id=databases)),
  role: 'server',
  secret: 'fnACx5dHGJACAvbi1rpiKJFPsvWEdwvJjmEllT1q',
  hashed_secret:
   '$2a$05$cNALKjEyHHbx5XcxdQDd1uFlg9w7ILiGCkPiOBm.GkqdRvqLYTJpe' }

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!