-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an HTTP API to configure contacts and contactgroups #176
Comments
So there will be two places where group memberships can be updated? Will the behavior be that on an update, memberships that aren't given, will be removed, i.e. to add a group to a user, you have to query the user first? Does omitting the
That column is used to store an optional reference to an Icinga Web user. That would imply that each contact is linked to one then.
That column currently stores a display name. Sure, that can be encoded as part of an URL, but is this desired here? But in general, sounds like you want/need a user-chosen primary key for those tables. I wouldn't rule out just doing this instead. |
Yes. Yes. Yes. My expectation is that whoever uses this API, just imports data from another source, so there's no need to fetch anything first, as all information is already available.
I had a discussion with Eric about the use of UUIDs, which I'd chosen first. Though, they'd still need to reference an identifier (UUIDv5) that is known to both sides, i.e. mandatory in any case. Otherwise (UUIDv4) we'd had to prevent changes in the UI to resources created through the API and vice versa. The primary key isn't an option, hence the username. The group name is indeed more of a label right now. My goal was, not to limit edits in any way. A resource created through the API should be changeable in the UI. This means, by creating one in the UI, the identifier must be provided, just the same as when creating it through the API. |
Sounds like you think something is a problem where I'd say it's perfectly fine. UUIDs are an obvious choice, so let's stick to that. I'd say it's perfectly fine to make the primary key a UUID without any restrictions on the version. If a contact ist created using Web, it just gets a random UUID (v4) assigned. If a contact is created using the API, the client chooses the UUID however it desires. If it syncs from somewhere else that already uses an UUID to identify the source object, use that, otherwise, use a hash-based UUID (v5) or even use a random UUID and keep some state, doesn't matter for us, that would be a decision for the API client author. Creating a contact in Web and then updating it using the API should be possible, yes, but if your sync source is the primary data source anyways, why wouldn't you create all contacts using the API? If your use-case is to just update individual attributes like an e-mail address for existing contacts, the API client could still query the contact by username using the filter mechanism and then update it by the returned ID. Or it could just query all contacts and then update those, where an update is necessary. So that would still be possible without a predictable ID. |
Fine. Let's use UUIDs as identifier. Oh, btw, I forgot to include addresses. -.- |
Yes, but it sounds like the way cleaner option, doesn't it? Would this result in an unreasonable amount of work in Notifications Web? |
It's not required. I'd rather add a new column for this, as a start. We still don't have versioning, so the schema isn't stable anyway.. |
However, if we just replace the primary key type of these two columns, it's a bit of an arbitrary mix. Another idea for how two different columns could make sense in my opinion: keep the current numeric ID as-is and add a second column, something like |
Nope. That goes against everything I read. If we keep our numeric ID, it's won't be exposed in the API.
A single type. I really don't want to support multiple ways if UUID is one of them. It should be the only one.
This is something we already solved and agreed on:
Then let's introduce a new column of type UUID and make it required. |
Why not? Also, I'm not really sure what you read.
Of course we should pick one. Just wanted to say that the exact choice won't matter for the rest I wrote.
That's not what I wanted to say with that. If you have a field large enough to store an unhashed reference, an API client could retrieve a list of all contacts, look them up by say a stored LDAP DN, and check if anything needs to be updated. Not sure how commonly someone would want to build something like this, I just wanted to say that's something that would additionally be possible if it was a "store whatever you want" type. |
To prevent enumeration attacks.
If the identifier is a UUID, chosen by the client, no checks are necessary. The client just PUTs the data it has and nothing else. And all with a "store whatever you want" type. |
Yes, in general, unpredictable IDs add an additional layer of defense. But isn't the API supposed to allow listing all objects anyways?
Syncing object deletion would be annoying that way though as you don't really have a way of telling how that UUID was generated. If you have an contact that says |
We concluded that two columns (pk + external_uuid), both required, are sufficient for now. Making the pk the UUID can be done at a later point, together with a custom fact for the client to identify its own resources. (To allow safe removals) |
RequestsNote Captions:
|
Thanks for the tests. Please write directly in the PR next time. |
Current State
At the moment contacts can only be configured by using the UI. Contactgroups cannot be configured at all. (see #174)
Problem
We can safely assume that consumers already have their users and usergroups defined somewhere. Maintaining them again for Icinga Notifications shouldn't be necessary.
Solution
We should provide a way to automate their creation. The easiest way is to provide a basic HTTP API to do so:
Authorization
The API must require the
notifications/api/v1
permission.Endpoints
Users:
notifications/api/v1/contacts[/<identifier> | ?<filter>]
Groups:
notifications/api/v1/contactgroups[/<identifier> | ?<filter>]
Parameters
identifier
This is a UUID. For resources created in the UI, this is a UUIDv4.
filter
A usual filter query string
Request Body Validity
Resource Structure (Request and Response)
Contact
Contactgroup
Methods
GET
POST
id
in the body is equal)Location
headerLocation
headerPUT
id
in the body is invalid)DELETE
Schema Changes
external_uuid
tocontact
andcontactgroup
icinga-notifications#192Implementation Requirements
GET ?filter
responses like https://github.com/Icinga/icingadb-web/blob/v1.1.2/library/Icingadb/Data/JsonResultSetUtils.php#L70-L100 and disable PHP's output bufferingThe text was updated successfully, but these errors were encountered: