Skip to content
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

[#467] setup objecttypes through django-setup-configuration #489

Closed
wants to merge 24 commits into from

Conversation

SonnyBA
Copy link
Contributor

@SonnyBA SonnyBA commented Dec 10, 2024

Fixes #467

Changes

Updates the existing django-setup-configuration steps and removed the DemoUserStep as that will be replaced by #482

@SonnyBA SonnyBA self-assigned this Dec 10, 2024
@SonnyBA SonnyBA marked this pull request as ready for review December 10, 2024 11:09
@SonnyBA
Copy link
Contributor Author

SonnyBA commented Dec 10, 2024

@danielmursa-dev I made some changes to the django-setup-configuration setup in this project which will also affect #485. To work on the earlier mentioned ticket you'll have to rebase onto this branch (or onto master if it gets merged).

Copy link
Contributor

@stevenbal stevenbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good generally, though I think the ObjectType configuration stuff is out of scope


def execute(self, model: SitesConfigurationModel) -> None:
for item in model.items:
site_kwargs = dict(domain=item.domain, name=item.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented the same step when refactoring it in Open Notificaties: https://github.com/open-zaak/open-notificaties/pull/201/files#diff-9d74a1ba740219a222b8fb9dea30f135ebe2f5ad67f77ca87074ae55c13cb1ceR23

The behavior of the original step is a bit different, since it would let you specify an organization which would be used to create the name (Objects {organization}). To be honest I'm fine with either option (specifying organization or specifying name directly), but I think it would be good to pick one of these and be consistent.

Perhaps we could define this step in django-setup-configuration itself, so that we can reuse it?

@swrichards do you have an opinion on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it indeed makes sense to put this in django-setup-configuration itself. I am bit reluctant to delay these PRs though, so I would recommend leaving this in given that it works. It would be good if the two of you agree on whose step is leading to avoid divergence on the yaml structures, so the upgrade will be easier later on.

Copy link
Contributor Author

@SonnyBA SonnyBA Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the points to consider here (and in other projects?) are:

  1. Upgrade the site related configuration and allow multiple sites to be configured (as is done in this PR)
  2. Upgrade the site related configuration and allow configuration of one site (or update the current site, behavior of the previous site step for this project)
  3. Remove the step altogether
  4. Move the step to django-setup-configuration

Edit: made the list ordered to make referencing a bit easier

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am bit reluctant to delay these PRs

agree, though I think in that case it's important that the format is the same everywhere, otherwise we'll still end up with breaking changes. Let's use the step as it's implemented here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we're gonna apply point 1 to all projects which use a site configuration step?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we're gonna apply point 1 to all projects which use a site configuration step?
That sounds right to me.

Copy link
Contributor

@stevenbal stevenbal Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In hindsight, it might actually be better to just allow one site to be configured, afaik we do not use multiple sites anywhere and if you now run on a freshly deployed instance, you end up with this:

image

Either that, or we should delete existing sites at the start of the configurationstep

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed this morning, this will be replaced by a configuration step from django-setup-configuration

DEMO_PERSON="Demo",
DEMO_EMAIL="[email protected]",
)
class SetupConfigurationTests(TestCase):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we want a similar test for the new setup. It might feel a bit excessive but I guess it does verify that all expected steps are executed and work together when used with an example.yaml file

@swrichards what do you think about this?

from objects.core.models import ObjectType


class ObjectTypeConfigurationModel(ConfigurationModel):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swrichards @joeribekker I don't think this was very clear from the issue, but I think the scope of setup-configuration here was to be able to configure the connection from Objects API to Objecttypes API, and not to be able to configure objecttypes, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the question here is whether an objects-api/objecttypes-api can meaningfully function without being seeded with some object types of which objects-api has knowledge. I can imagine the bar of "minimum viable connectivity" here includes a certain level of seeding core objects, but I don't know enough about the Objects API to say for sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Objecttypes can be created with the API once a token is obtained. So, no, objecttypes should not be created via the YAML file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this behavior in 4a256d9. I'm wondering though if we should use a fixed identifier (for example objecttypes-api) and remove the ability to modify it.

src/objects/setup_configuration/steps/objecttypes.py Outdated Show resolved Hide resolved

def execute(self, model: SitesConfigurationModel) -> None:
for item in model.items:
site_kwargs = dict(domain=item.domain, name=item.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it indeed makes sense to put this in django-setup-configuration itself. I am bit reluctant to delay these PRs though, so I would recommend leaving this in given that it works. It would be good if the two of you agree on whose step is leading to avoid divergence on the yaml structures, so the upgrade will be easier later on.

src/objects/setup_configuration/steps/sites.py Outdated Show resolved Hide resolved
Comment on lines 89 to 91
Objecttypes require a corresponding ``Service`` to work correctly. Creating
these ``Service``'s can be done by defining these in the same yaml file. ``Service``
instances will be created before the ``ObjectType``'s are created.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Objecttypes require a corresponding ``Service`` to work correctly. Creating
these ``Service``'s can be done by defining these in the same yaml file. ``Service``
instances will be created before the ``ObjectType``'s are created.
Objecttypes require a corresponding ``Service`` to work correctly. Creating
these ``Service``'s can be done by defining these in the same yaml file (i.e. in the ``zgw_consumers`` block above). ``Service``
instances will be created before the ``ObjectType``'s are created.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See thread, this description is not relevant anymore.

Comment on lines 62 to 63
zgw_consumers:
services:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zgw_consumers:
services:
zgw_consumers:
services:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

service_identifier: objecttypen-bar
...

.. note:: The ``uuid`` field will be used to lookup existing ``ObjectType``'s.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. note:: The ``uuid`` field will be used to lookup existing ``ObjectType``'s.
.. note:: The `uuid` field is used to look up existing `ObjectType` entries through the `object-types` API of the service specified by `service_identifier`.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/objects/setup_configuration/models/sites.py Outdated Show resolved Hide resolved


class ObjectTypesConfigurationModel(ConfigurationModel):
items: list[ObjectTypeConfigurationModel] = Field()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
items: list[ObjectTypeConfigurationModel] = Field()
items: list[ObjectTypeConfigurationModel]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from objects.core.models import ObjectType


class ObjectTypeConfigurationModel(ConfigurationModel):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the question here is whether an objects-api/objecttypes-api can meaningfully function without being seeded with some object types of which objects-api has knowledge. I can imagine the bar of "minimum viable connectivity" here includes a certain level of seeding core objects, but I don't know enough about the Objects API to say for sure.

Comment on lines 15 to 16
namespace = "sites"
enable_setting = "sites_config_enable"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this regard, I suggest having a unique naming convention for all projects and apps, so as not to create problems with different yaml files.
%s_%s' % (app_label, model_name)

  • something like how the url is made in admin
Suggested change
namespace = "sites"
enable_setting = "sites_config_enable"
namespace = "sites_site"
enable_setting = "sites_site_config_enable"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, although the suggested namespace probably will clash whenever other projects allow their Site to be configured as well. Consider for instance the following configuration file:

# Objects-api
sites_site_config_enable: true
sites_site:
  items:
    ....

# Objecttypes-api
sites_site_config_enable: true
sites_site:
  items:
    ....

I think prefixing it with the project name will fix this, for example objects_api_sites_config and objects_api_sites_config_enable.

Copy link
Contributor Author

@SonnyBA SonnyBA Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielmursa-dev I think the collision of the namespaces, like mentioned above, also applies to the token configuration for certain projects?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes exactly, everywhere the same namespaces must be used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielmursa-dev I think the collision of the namespaces, like mentioned above, also applies to the token configuration for certain projects?

Discussed through the chat, this comment can be ignored as the namespace collision will not happen (different configuration file per project). The project prefix is not necessary for Site configuration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SonnyBA OK , so let's continue with this format yes?

# %s_%s' % (app_label,  model_name)

sites_site_config_enable:` true
sites_site:
  items:
    ....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary to change this in the steps in existing projects but this might be a good scheme for steps that are going to be added.

Comment on lines 8 to 22
objects_api_objecttypes_connection:
identifier: objecttypes-api
label: Objecttypen API
api_root: https://objecttypes.nl/api/v1/
api_connection_check_path: objecttypes
api_type: orc
auth_type: zgw
header_key: Authorization
header_value: Token foo
client_id: client
secret: secret
nlx: http://some-outway-adress.local:8080/
user_id: objects-api
user_representation: Objects API
timeout: 60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed off-line: revert back to using zgw_consumers, this basically just replicates that logic. We found that there is no central config model that has a ForeignKey to a Service (as in other projects), rather each Object Type has such a foreign key. But because we said we wouldn't be configuring the actual object types here, we only have to configure Services (without having other models point to those services). TLDR: zgw_consumers is sufficient.

Copy link
Contributor

@swrichards swrichards left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SonnyBA
Copy link
Contributor Author

SonnyBA commented Dec 12, 2024

The objecttypes connection part is now handled through the zgw-consumers configuration step. It might be practical to leave this PR open until there also is a configuration step provided from django-setup-configuration to setup site objects.

There should also be decided upon loading in objecttypes (locally) so that tokens also can be loaded in (as they will have no function without any objecttype attached to it).

@SonnyBA
Copy link
Contributor Author

SonnyBA commented Dec 12, 2024

Closing this PR in favor of #492

@SonnyBA SonnyBA closed this Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Objecttype-configuration via django-setup-configuration
5 participants