j3k0 / ganomede-usermeta

ganomede's user metadata microservice
0 stars 0 forks source link
api ganomede metadata microservice

Usermeta API

Attach metadata to users.

Configuration

Reading and writing different keys requires different access levels:

Keys that are not listed in env vars can't be read or written.

GET /:userIds/:keys

Retrieve publicly available metadata. Both, :userIds and :keys are comma-separated list. Attach secret query string param to retrieve fields up to internal.

Missing or unknown keys, and those you are not allowed to read will be omitted (as opposed to being HTTP error).

response [200] OK (application/json)

Suppose country is public key and email is a protected one.

GET /alice,bob/country,email results in following JSON response:

  { "alice": {"country": "USA"},
    "bob": {"country": "France"}
  }

GET /auth/:token/:keys

Retrieve public, protected and private keys for a user with login token equal :token. Make :token be "API_SECRET.${userId}" to retrieve fields up to internal.

Missing or unknown keys, and those you are not allowed to read will be omitted (as opposed to being HTTP error).

response [200] OK (application/json)

Suppose country is public key, email is a protected one, and internalId is internal one.

GET /auth/alice-auth-token/country,email,internalId results in following JSON response:

  { "alice": {
      "country": "USA",
      "email": "alice@wonderland.com"
    }
  }

response [401] Not Authorzied

In case of invalid token.

POST /auth/:token/:key

Write public and protected meta value to a :key of a user :token points to. Make :token be "API_SECRET.${userId}" to write fields up to internal and no byte limit.

body (application/json)

JSON with single key "value" and value being a string.

 { "value": "string to write as a meta value"
 }

response [200] OK

response [401] Not Authorzied

In case of invalid token, trying to write private and up without API_SECRET, or unknown key.

 { "restCode": "InvalidCredentialsError",
   "statusCode": 401,
   "message": "Invalid credentials"
 }

response [413] Payload Too Big

In case of writing public or protected value of byte size greater than USERMETA_MAX_LENGTH env var without API_SECRET.

 { "restCode": "ValueTooBigError",
   "statusCode": 413,
   "message": "Value exceeds ${USERMETA_MAX_LENGTH} byte limit"
 }

POST /auth/:token

Transactionally write multiple public and protected meta values of a user :token points to. Make :token be "API_SECRET.${userId}" to write fields up to internal and no byte limit.

Unlike getting multiple keys, this will either write all metas, or return an error.

body (application/json)

Flat JSON object with strings. Keys are metanames.

 { "useful_info": "something valuable",
   "second_key": "second key's value and so on…",
   "more_keys": "{\"possibly\": true}"
 }

response [200] OK

response [401] Not Authorzied

In case of invalid token, trying to write private and up without API_SECRET, or unknown key.

 { "restCode": "InvalidCredentialsError",
   "statusCode": 401,
   "message": "Invalid credentials"
 }

response [413] Payload Too Big

In case of writing public or protected value of byte size greater than USERMETA_MAX_LENGTH env var without API_SECRET.

 { "restCode": "ValueTooBigError",
   "statusCode": 413,
   "message": "Value exceeds ${USERMETA_MAX_LENGTH} byte limit"
 }