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

Fix parameter_sensitivities checking the values instead of the keys #357

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

michaelarnauts
Copy link
Contributor

This PR fixes creation of ParameterContexts.

The swagger-codegen package adds a validation on the keys instead of the values. See swagger-api/swagger-codegen#9138.

Luckily, the default templates from the swagger-codegen package are overridden in this repo, so we can make the change here. Looking at the age of the issue, it doesn't seem they are interested in changing their default templates.

@michaelarnauts michaelarnauts marked this pull request as draft June 19, 2024 12:24
@michaelarnauts
Copy link
Contributor Author

michaelarnauts commented Jun 19, 2024

Hold on with this... I do still see a case where NiFi returns with null as sensitivity.

It seems to happen when calling the fetch_parameters API.

ValueError: Invalid values in parameter_sensitivities [None], must be a subset of [SENSITIVE, NON_SENSITIVE]

EDIT:

I've noticed something wrong with the Swagger API docs for the /parameter-providers/{id}/parameters/fetch-requests endpoint.

The docs states that the reply is a ParameterProviderEntity. Going further, it contains a .component.parameterGroupConfigurations[0].parameterSensitivities of the type ParameterSensitivity. This ParameterSensitivity only allows to be SENSITIVE or NON_SENSITIVE:

...
        "parameterSensitivities" : {
          "type" : "object",
          "description" : "All fetched parameter names that should be applied.",
          "additionalProperties" : {
            "type" : "string",
            "enum" : [ "SENSITIVE", "NON_SENSITIVE" ]
          }
        },
...

However, the /parameter-providers/{id}/parameters/fetch-requests endpoint returns null as a sensitivity if it hasn't been setup yet.

This causes the parsing of the reply to fail.

… what NiFi returns when the value is not yet set
@michaelarnauts
Copy link
Contributor Author

I had to add None to the allowed_values. This is not optimal, since a codegen will override this from the swagger file, however, it seems that it isn't possible to specify a null value in Swagger 2.0.

NiFI does return null on purpose here: https://github.com/apache/nifi/blob/rel/nifi-1.26.0/nifi-api/src/main/java/org/apache/nifi/parameter/ParameterGroupConfiguration.java#L68

On Swagger 3.0, the following should be possible, but when running the codegen here, it doesn't update the models.

        "parameterSensitivities" : {
          "type" : "object",
          "description" : "All fetched parameter names that should be applied.",
          "additionalProperties" : {
            "type" : "string",
            "nullable": true,
            "enum" : [ "SENSITIVE", "NON_SENSITIVE", null ]
          }
        },

I'm not sure how to proceed here.

@michaelarnauts
Copy link
Contributor Author

I've created a ticket at the NiFi Jira here: https://issues.apache.org/jira/browse/NIFI-13419

@@ -101,10 +101,10 @@ class {{classname}}(object):
)
{{/isListContainer}}
{{#isMapContainer}}
if not set({{{name}}}.keys()).issubset(set(allowed_values)):
if not set({{{name}}}.values()).issubset(set(allowed_values)):
Copy link
Owner

Choose a reason for hiding this comment

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

Could this have an or None to satisfy the response from NiFi without breaking the codebase?

@asm72
Copy link

asm72 commented Sep 17, 2024

+1

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.

3 participants