How to get current database info from secret?

I’m playing with multiple child databases. For each child db, I created a key with bootstrap role.

So the question is, how do I know which database is associated with when I only have the key without knowing database ref?
KeyFromSecret doesn’t provide enough information for me. Do I need to attach the information(database ref) to the key itself?

also, can I get current database data (where gql metadata stores) without navigating to upstream database?

At the moment if you want to expose that data, you’ll want to add it to the key yourself. The reason things are setup as they are is that you can think of a key as a chroot. Every database sees itself as / in the hierarchy. This allows you to create child databases and give your users keys and not expose to them where they live in your hierarchy and change it without breaking them. Of course if you want to break this wall you can add metadata to keys. This might seem awkward but it does have some compelling advantages, which we use for instance to administer the platform. Do you think the database that you see as root is really root in the cluster? Do you think that’s air you’re breathing right now? matrix intensifies

I’ll elaborate on Ben’s answer, because it’s not always clear to everyone that pretty much everything is a Document, which means it can have data.

You can retrieve your key data by the ID or by the secret that you have

Ref(Keys(), '269132014783824403')
// OR
Select('ref', KeyFromSecret('A_VERY_SECRET_SECRET'))

If you create a key from a shell or driver, you can pass data directly to it:

CreateKey({
  role: 'admin',
  data: {
    some: 'meta data'
  }
})

{
  ref: Key("269132014783824403"),
  ts: 1592923140240000,
  role: "admin",
  data: {
    some: "meta data"
  },
  secret: "A_VERY_SECRET_SECRET",
  hashed_secret: "HASH_OF_SECRET"
}

You can also update the key with Update like any other Document.

Update(
  Ref(Keys(), '269132014783824403'),
  // OR
  // Select('ref', KeyFromSecret('A_VERY_SECRET_SECRET')),
  {
    data: {
      additional: 'meta data'
    }
  }
)

{
  ref: Key("269132014783824403"),
  ts: 1592923575430000,
  role: "admin",
  data: {
    some: "meta data",
    additional: "meta data"
  },
  hashed_secret: "HASH_OF_SECRET"
}
2 Likes

thanks for the clarifying above.

I just thought that it’ll be a way to find out 'where am i ', when I connect fauna client with secret, it already knows which database to associated with.

Right. But the answer the key would give you is not very satisfying. It would say “/”.