Class DatadogApiCommands

java.lang.Object
edu.internet2.middleware.grouper.app.datadog.DatadogApiCommands

public class DatadogApiCommands extends Object
  • Field Details

    • doNotLogHeaders

      public static final Set<String> doNotLogHeaders
    • grouperLoaderConfig

      public static GrouperLoaderConfig grouperLoaderConfig
  • Constructor Details

    • DatadogApiCommands

      public DatadogApiCommands()
  • Method Details

    • main

      public static void main(String[] args)
    • retrieveUsers

      public static List<DatadogUser> retrieveUsers(String configId, DatadogSettings datadogSettings)
      Retrieve all users from Datadog, filtering out service accounts, disabled users, and ignored user emails (if datadogSettings is not null). Pages through results using page[number] (0-indexed) and page[size].
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      Returns:
      list of non-service-account, non-disabled, non-ignored users
    • retrieveUserByEmail

      public static DatadogUser retrieveUserByEmail(String configId, DatadogSettings datadogSettings, String email, boolean includeDisabledUsers)
      Retrieve a single user by email address from Datadog. Uses GET /api/v2/users?filter=email. Filters out service accounts and users whose email and handle don't match the input. Throws an exception if the email is in the ignore list (if datadogSettings is not null). Throws an exception if more than one matching user is found after filtering.
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      email - the email to look up
      includeDisabledUsers - true to include disabled users (e.g. for create conflict handling)
      Returns:
      the user, or null if not found
    • updateUser

      public static DatadogUser updateUser(String configId, DatadogSettings datadogSettings, DatadogUser datadogUser, Set<String> fieldNamesToSet)
      Update a user in Datadog via PATCH /api/v2/users/{id}. Throws an exception if the user's email is in the ignore list (if datadogSettings is not null).
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      datadogUser - the user with updated fields
      fieldNamesToSet - the set of field names to include in the update
      Returns:
      the updated user
    • createUser

      public static DatadogUser createUser(String configId, DatadogSettings datadogSettings, DatadogUser datadogUser)
      Create a user in Datadog. If the user already exists (looked up by email), re-enable if disabled and update. Otherwise POST /api/v2/users to create a new invitation. Throws an exception if the user's email is in the ignore list (if datadogSettings is not null).
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      datadogUser - the user to create
      Returns:
      the created or updated user
    • disableUser

      public static DatadogUser disableUser(String configId, DatadogSettings datadogSettings, DatadogUser datadogUser)
      Disable a user in Datadog by PATCHing disabled=true. This is the soft delete for Datadog users. Throws an exception if the user's email is in the ignore list (if datadogSettings is not null).
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      datadogUser - the user to disable (must have id set)
      Returns:
      the updated user
    • retrieveRoles

      public static List<DatadogGroup> retrieveRoles(String configId, DatadogSettings datadogSettings)
      Retrieve all roles from Datadog via GET /api/v2/roles. Pages through results using page[number] (0-indexed) and page[size]; the roles endpoint otherwise defaults to a small page size, which would silently truncate the list and make existing roles look missing (leading to 409 "already exists" on insert). Filters out ignored roles (if datadogSettings is not null).
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      Returns:
      list of non-ignored roles as DatadogGroup objects with groupType="role"
    • createRole

      public static DatadogGroup createRole(String configId, DatadogSettings datadogSettings, DatadogGroup datadogGroup)
      Create a role in Datadog via POST /api/v2/roles.
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      datadogGroup - the role to create (must have name set)
      Returns:
      the created role as DatadogGroup with groupType="role"
    • updateRole

      public static DatadogGroup updateRole(String configId, DatadogSettings datadogSettings, DatadogGroup datadogGroup, Set<String> fieldNamesToSet)
      Update a role in Datadog via PATCH /api/v2/roles/{id}.
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      datadogGroup - the role with updated fields (must have id set)
      fieldNamesToSet - the set of field names to include in the update
      Returns:
      the updated role as DatadogGroup with groupType="role"
    • deleteRole

      public static void deleteRole(String configId, DatadogSettings datadogSettings, DatadogGroup datadogGroup)
      Delete a role in Datadog via DELETE /api/v2/roles/{id}. Throws an exception if the role name is in the ignore list (if datadogSettings is not null).
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      datadogGroup - the role to delete (must have id set, name for ignore check)
    • getRoleUsers

      public static List<DatadogUser> getRoleUsers(String configId, DatadogSettings datadogSettings, String roleId)
      Retrieve users assigned to a role via GET /api/v2/roles/{roleId}/users. Pages through results.
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      roleId - the UUID of the role
      Returns:
      list of users assigned to the role
    • addUserToRole

      public static void addUserToRole(String configId, DatadogSettings datadogSettings, String roleId, String userId)
      Add a user to a role via POST /api/v2/roles/{roleId}/users.
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      roleId - the UUID of the role
      userId - the UUID of the user to add
    • removeUserFromRole

      public static void removeUserFromRole(String configId, DatadogSettings datadogSettings, String roleId, String userId)
      Remove a user from a role via DELETE /api/v2/roles/{roleId}/users. Note: this is a DELETE with a request body. Accepts 200 and 404 (already removed).
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      roleId - the UUID of the role
      userId - the UUID of the user to remove
    • retrieveTeams

      public static List<DatadogGroup> retrieveTeams(String configId, DatadogSettings datadogSettings)
      Retrieve all teams from Datadog via GET /api/v2/team. Pages through results using page[number] (0-indexed) and page[size].
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      Returns:
      list of teams as DatadogGroup objects with groupType="team"
    • createTeam

      public static DatadogGroup createTeam(String configId, DatadogSettings datadogSettings, DatadogGroup datadogGroup)
      Create a team in Datadog via POST /api/v2/team.
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      datadogGroup - the team to create (must have name and handle set)
      Returns:
      the created team as DatadogGroup with groupType="team"
    • updateTeam

      public static DatadogGroup updateTeam(String configId, DatadogSettings datadogSettings, DatadogGroup datadogGroup, Set<String> fieldNamesToSet)
      Update a team in Datadog via PATCH /api/v2/team/{id}.
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      datadogGroup - the team with updated fields (must have id set)
      fieldNamesToSet - the set of field names to include in the update
      Returns:
      the updated team as DatadogGroup with groupType="team"
    • deleteTeam

      public static void deleteTeam(String configId, DatadogSettings datadogSettings, DatadogGroup datadogGroup)
      Delete a team in Datadog via DELETE /api/v2/team/{id}.
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      datadogGroup - the team to delete (must have id set)
    • getTeamMemberships

      public static List<DatadogMembership> getTeamMemberships(String configId, DatadogSettings datadogSettings, String teamId)
      Retrieve memberships for a team via GET /api/v2/team/{teamId}/memberships. Pages through results. Returns DatadogMembership objects with userId and role.
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      teamId - the UUID of the team
      Returns:
      list of memberships for the team
    • addUserToTeam

      public static void addUserToTeam(String configId, DatadogSettings datadogSettings, String teamId, String userId)
      Add a user to a team via POST /api/v2/team/{teamId}/memberships. The membership role defaults to "member".
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      teamId - the UUID of the team
      userId - the UUID of the user to add
    • updateTeamMembershipRole

      public static void updateTeamMembershipRole(String configId, DatadogSettings datadogSettings, String teamId, String userId, String role)
      Update a team membership role via PATCH /api/v2/team/{teamId}/memberships/{userId}.
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      teamId - the UUID of the team
      userId - the UUID of the user
      role - the role to set ("admin"), or null/blank to remove admin privileges (Datadog API only supports "admin"; omit role to demote)
    • removeUserFromTeam

      public static void removeUserFromTeam(String configId, DatadogSettings datadogSettings, String teamId, String userId)
      Remove a user from a team via DELETE /api/v2/team/{teamId}/memberships/{userId}. Accepts 204 and 404 (already removed).
      Parameters:
      configId - the id of the external system
      datadogSettings - the settings, or null to skip ignore checks
      teamId - the UUID of the team
      userId - the UUID of the user to remove