Commit Graph

47 Commits

Author SHA1 Message Date
9de4163d22 fix the modified_by and modified_at columns
As all changes are already written into history, why not enforce the
proper changing of modified_at and modified_by columns?

This way we can be sure these are properly changed and don't have to
take care of that in the SQL statements anymore.
2021-05-21 21:07:08 +02:00
25e2046e78 add container functions
This is the first major container draft and implements most of the
functions to create containers, remove them, show and set attributes on
them.

It also implements the special case in dim, that a list of all
containers and their free space is returned.
It currently does not implement a partial output when a subnet or
layer3domain is returned.
First I want to know how well it actually scales and works as this is a
major pain point in the python implementation.

At the moment the output also has the problem that it can grow quite
large in memory as the tree is built in the middleware. A better way
would be to build the json directly in the database so it can be
returned directly. We will have to see when this becomes a major issue.
2021-05-21 20:56:50 +02:00
211877d18b fix sql driver interface for subnet type
Without this fix the interface was not recognized and resulted in an
error message.
2021-05-21 20:56:17 +02:00
cb13ceab8f add a debug output mode
This can be enabled in the config, but needs to be added in other
places.
2021-05-21 20:55:48 +02:00
1696b6e15e ignore unmapped values
When a name is not mapped then the field should not be updated. This is
a bit weird and maybe should throw an error, but at least we avoid
chaning columns that are not meant to be changed.
2021-05-21 20:54:44 +02:00
f28b0d0ae3 fix not null constraint
The default not null constraint only checks for the SQL null, not a json
null.
Therefore add an extended not null constraint by checking both possible
null values.
2021-05-21 20:53:50 +02:00
c5f0a86886 add endpoints for ipblocks/containers 2021-05-21 17:51:35 +02:00
08808fe984 add IPVersion type to properly parse a 4 or 6 2021-05-21 17:51:35 +02:00
d746ad7ac0 add function to get subnets to schema
This also adds a view to get a list of all containers and their free
space in between.
This is needed for ippool_list to get a nice overview over everything.

The code of the function is based on
https://pkg.go.dev/inet.af/netaddr#IPRange.Prefixes

Many thanks to Brad Fitzpatrick for the awesome code and changelog to
make it possible to understand what is going on.
2021-05-21 17:50:31 +02:00
c2bf09fd9e add view to get container hierarchy 2021-05-21 17:50:19 +02:00
af625344a5 add more detials to parsing errors 2021-05-15 21:18:19 +02:00
5bb473404f add support for attributes in pools
Add support to show all pool attributes and set them.

Also add some helper functions to FieldMap to change and check the
requested attributes.
This was needed because the layer3domain needs to be set through
attributes instead of a link function (this should be changed, but for
now we will be compatible to ndcli).

So we filter out the layer3domain name and replace it with the ID, so
that the update can do both at the same time. Maybe there is a better
way to handle this in the future.
2021-05-09 21:22:52 +02:00
64eb4aa99d fix a small typo 2021-05-09 21:22:20 +02:00
8131e0a7e7 add history support
This commit consists of two things.

1. server.go will now set two variables for the current transaction, the
   username and request id. These are transaction local and therefore do
   not leak into the connection.

2. The initial schema received a history table and a trigger. This
   trigger writes changes into the history table. When inserting records
   the function will pull the transaction local variables and add them
   to the record.
   The trigger is added to all tables, so that a complete changelog is
   created.

These changes serve as the basis for further features. One is the
searching for changes on specific resources (think history rr, history
zone, ...).
The other feature is a way to subscribe to changes in the database based
on filters. This will be the way to implement the output feature of dim.
2021-05-09 20:32:34 +02:00
b3b14b9894 fix wrong error message
The old message was copied over from the layer3domains.
2021-05-09 20:32:05 +02:00
7c986e59ec add initial pool support
This is more or less a copy of the layer3domain support to support
pools.
2021-05-08 22:40:02 +02:00
a19eaa851f add missing fields to initial schema 2021-05-08 22:39:42 +02:00
c22873990b add layer3domain show API call
This adds the API call to return all fields for a single layer3domain.
This should serve as a nice basis for other parts to be implemented.

All fields are put together into a single json document, merged together
with the other attributes of the table and then returned to the
requester.
2021-05-07 21:23:49 +02:00
e9135c9c10 add missing table name
The table name was missing from the implementation of FieldsToJSON.
This was also fixed in the tests.
2021-05-07 21:17:13 +02:00
88c271667b add function FieldsToJSON
This function enables the show view to be much less write overhead.
By defining which columns to return and automatically merging the
attributes into the main view, this can be made so much easier.

It doesn't support the recursive view for now, so that is something a
client would need to handle, but for now this should be good enough.

This also fixes a small issue in the update clause handler by moving
the index handler into the handler when a column was found.
If that was not done, the index gets moved to the wrong position and the
resulting query would be wrongly indexed.
2021-05-07 21:03:58 +02:00
f96f8ba4ed fix jsonb output generator
When selecting content of a jsonb field the type per default is jsonb.
But we need to proper posgres type, so that the output can be parsed
properly.
Therefore make sure that the field has the proper output operator
attached.
2021-05-07 11:35:48 +02:00
554d6abf7f add missing function links 2021-05-07 10:20:33 +02:00
01b87332d9 add a way to set attributes
For this to work, I have added a new function that takes a list of
key looking things and converts them into json.
At the same time, it also can convert json looking payloads and
prepare it for the database (that last part was not intended, but
works).

With the many columns where setting attributes is possible, this
functionality should help quite a bit.
2021-05-07 10:17:05 +02:00
56b7b823db add new dim config name to block list 2021-05-03 22:41:58 +02:00
1857bdd05a add layer3domain create and ipblock create
This is the first draft of creating layer3domains and
ipblocks/containers.

This allows some testing with different things, like list building for
complex container output, but also how containers should behave.
2021-05-03 22:40:27 +02:00
5ed6482400 the pool_id should be nullable
Containers are subnets in vairous ranges. But only when a subnet is
assigned a pool, it is truly a subnet. When it is not assigned to a
pool, it is considered a container.

This serves the purpose of grouping or blocking containers for different
purposes, so we need to keep that up.
2021-05-03 22:38:49 +02:00
0f42d2b9ed fix query tests
After the query API was a bit adjusted, the tests weren't fixed.
2021-05-03 21:14:08 +02:00
849ce2d791 make dim.conf the default config name
Toml as a file ending for a config file format feels weird, so make it
use a better name.
2021-05-03 19:58:44 +02:00
8b36602e09 add dependency file
This is the current list of all dependency versions.
2021-05-03 19:44:28 +02:00
eb3dfb3aec add example handlers to the server
This is currently work in progress, but shows how the system is intended
to work.
2021-05-03 19:43:56 +02:00
8953b10faa define result as interface{}
This way we can easily reset the result after we hit an error, which
then omits the result.
2021-05-03 19:43:25 +02:00
9e6a6fbe28 define a base table for attributes
When extra fields are fetched from the attributes column it must be
specified from which table that should be. If not done and another table
also has an attribute column, it will end in an error.
2021-05-03 19:41:28 +02:00
c18d165a5f fix some schema issues 2021-05-03 19:41:06 +02:00
c7ead94934 convert query result to dim result
This modifies the zone list command in such a way, that a query result
could be directly returned to the response.

With a bit of work, large query results could be rendered with a
streaming json renderer to the output.
2021-05-03 19:39:41 +02:00
feb4569547 provide initial versions of zone endpoints
These are only examples for now and nothing serious yet but showcase the
innards of query and types for now.

It is a beginning.
2021-04-28 21:09:38 +02:00
b8f2414675 add a FieldList type
This type represents a list of fields someone might want to have
returned.
This can be used together with the query library to build select
statements that return the exact data the user might need or want.

This way we may be able to avoid selecting data one might not need at
the end and therefore provide better performance.
2021-04-28 21:08:24 +02:00
888655cc03 add String() method to zone
This way we can print it in nicer ways.
2021-04-28 21:06:38 +02:00
ee5acc6ded add query interface
This is a small library to build queries and put the result into the
world.
Currently it supports building the select clause and converting rows
into a list of maps, so that it can be returned as a list.
2021-04-28 21:05:31 +02:00
1015861af8 add initial database schema
Usermanagement is still missing, but it is a first sketch on how things
could look like.
2021-04-24 21:42:19 +02:00
61d7ed2536 change zone type name to zonename
This should make it more obvious for what this type is intended.
2021-04-24 21:36:11 +02:00
3f04987290 add go.mod
We want it to be buildable by others, don't we?
2021-04-22 10:07:16 +02:00
9b3f2fddb1 add documentation for types package 2021-04-22 08:42:33 +02:00
7acd4803d0 add types package
This package will contain all the parameter types that need parsing from
the outside world into internal types.

Each type is required to implement its own UnmarshalJSON. At this point
it should also make the checks, if the incoming data is valid input, but
is not required to check against the database.
2021-04-22 08:35:24 +02:00
979164f4d2 add functions to parse incoming request parameters
These helpers enable the parameter parsing into method specific structs.
As the parameter list is an array, the order of arguments is important.

Sadly type checks can be done at runtime, because all parameters are
converted to a list of interface{}. So if there is an error, it will
only result in an error at runtime, so be careful.
2021-04-22 08:33:32 +02:00
35bf70b410 ignore generated binary 2021-04-21 21:58:14 +02:00
bf0f3c5eac add transaction to context
This adds the transaction handling to the connection and context
handling.
It will raise an error and inform the client if anything is going wrong
with the transaction.
2021-04-21 21:50:46 +02:00
2ee6db04e5 initial release 2021-04-21 21:40:55 +02:00