Skip to content

Instantly share code, notes, and snippets.

@lmoorejc
Last active October 4, 2022 17:40
Show Gist options
  • Select an option

  • Save lmoorejc/abaa2e5a0bc31991ac0c403c3433d89a to your computer and use it in GitHub Desktop.

Select an option

Save lmoorejc/abaa2e5a0bc31991ac0c403c3433d89a to your computer and use it in GitHub Desktop.

Directory DI Events

What I’m trying to accomplish:

  • Log association_change DI Events from within Directory
  • Get these events to look as similar to the events currently logged in SI

Questions

  1. How do I get similar metadata to what SI currently logs?
  2. How do I want to format the core event data?
  3. Is there a meaningful distinction between generic event metadata and the core event schema?
    1. Between something like provider that can potentially be on every event, and something like association that will only be present on association_change events.
    2. It sounds like the RequestMetaData is correct place for the generic stuff.
    3. Does it make sense to have separate structs for specific event schemas?
  4. Does this RequestMetaData mechanism allow the data to get as far as it needs to get?
    1. The data must make it from WebUI -> directory.Graph (directory-api) -> SQS -> directory-worker

Schema

This is a pseudocode example of the 'specific event schema' referred to above. This data doesn't really make sense to bake into the RequestMetaData as it's not metadata on the request, it's the actual event itself. How do we encapsulate this?

  • Can have this be a dedicated schema (as below)
  • We can just fill out a generic map of map[String]interface{} and pass that to the event logger
    • This feels prone to misuse/mistakes
struct AssociationChangeEvent {
	Op           String
	ActionSource String
	Attributes   map[String]interface{}
	Connection   Connection
}

struct Connection {
	From GraphEntity
	To   GraphEntity
}

Existing Event as logged from SI:

  • The end goal is to capture as similar event as possible as what SI is logging
{
  "initiated_by": {
    "id": "62b0d5bdb90dc69e9739bf89",
    "type": "admin",
    "email": "[email protected]"
  },
  "geoip": {},
  "useragent": {
    "patch": "0",
    "os_full": "Linux",
    "major": "106",
    "minor": "0",
    "os": "Linux",
    "name": "Chrome",
    "os_name": "Linux",
    "device": "Other",
    "version": "106.0.0.0"
  },
  "association": {
    "op": "add",
    "action_source": "manual",
    "attributes": null,
    "connection": {
      "from": {
        "name": "ExemptionsGroup",
        "type": "user_group",
        "object_id": "630fb4f5d30dc2000132abae"
      },
      "to": {
        "name": "user-2",
        "type": "user",
        "object_id": "62b22397839f664293876809"
      }
    }
  },
  "auth_method": "session",
  "@timestamp": "2022-09-29T21:27:41.994Z",
  "event_type": "association_change",
  "provider": null,
  "service": "directory",
  "file_input_timestamp": "2022-09-29T21:27:41.892Z",
  "success": true,
  "organization": "62b0d5bdb90dc63ffb39bf8b",
  "@version": "1",
  "client_ip": "172.24.0.1",
  "id": "63360dcd9bf548b867c7eef5",
  "timestamp": "2022-09-29T21:27:41.308Z"
}
.
.
.
.
EventUtils.logEvent(reqCtx, common.AssociationChangeEvent{ ...... });

``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment