libelektra icon indicating copy to clipboard operation
libelektra copied to clipboard

kdb set with validation

Open markus2330 opened this issue 9 years ago • 25 comments

kdb set: always do cascading set (for validation)

Current behavior

kdb set user:/test value

does not validate.

Expected behavior

kdb set user:/test value should validate (except if -f is used)

markus2330 avatar Dec 03 '16 18:12 markus2330

Other problems with kdb set are:

  • internal/** metadata is not removed
  • origvalue metadata is not removed (breaks all future kdb get, until it is removed)

kodebach avatar Sep 29 '19 20:09 kodebach

I mark this issue stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping the issue by writing a message here or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart:

stale[bot] avatar Sep 28 '20 21:09 stale[bot]

I mark this issue stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping the issue by writing a message here or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart:

stale[bot] avatar Sep 29 '21 16:09 stale[bot]

@atmaxinger can you check if this is still open?

markus2330 avatar Aug 06 '22 12:08 markus2330

Okay so I tested this issue against the current master

The setup:

kdb mount `pwd`/i1164/spec.ni spec:/i1164 ni
kdb meta-set spec:/i1164/port type unsigned_short
kdb meta-set spec:/i1164/port check/type unsigned_short
kdb set user:/i1164/port 123

kdb meta-get user:/i1164/port check/type correctly returns unsigned_shortkdb meta-get /i1164/port check/type correctly returns unsigned_short

kdb set user:/i1164/port abc --> does not validate, sets the value as string ❌ kdb set -N user /i1164/port abc --> invalid option -- 'N'

atmaxinger avatar Aug 08 '22 13:08 atmaxinger

Thank you for reproducing! That -N doesn't work anymore is fine (it was redundant).

But kdb set user:/i1164/port abc should do validation, this is very problematic, as this is the main way how values should be changed.

I updated the top-post.

markus2330 avatar Aug 08 '22 14:08 markus2330

The setup: [...]

If that's the full setup, it cannot work. Neither the type plugin nor the any plugin for meta:/port are mounted. You either need an extra spec-mount or a more direct mount command with extra plugins.

EDIT: But looking at the code in src/tools/kdb/set.cpp, there is no attempt to assure a cascading parent key AFAICT, so adding the plugins probably won't change anything.

kodebach avatar Aug 08 '22 15:08 kodebach

If that's the full setup, it cannot work. Neither the type plugin nor the any plugin for meta:/port are mounted. You either need an extra spec-mount or a more direct mount command with extra plugins.

Yes that's the full setup. TBH I thougt it would need some plugins, but I followed this guide and there was no mentioning of extra mounting the namespace with the plugins. If this is the case, the documentation should be revised to include this information.

atmaxinger avatar Aug 08 '22 15:08 atmaxinger

Stopped before or you skipped the essential spec-mount step. This infers the required plugins from the meta:/ keys and creates appropriate mountpoints.

kodebach avatar Aug 08 '22 16:08 kodebach

Yes I skipped it, as the description

This specification mount makes sure that the paths where the concrete configuration should be (app.ni) are ready to fulfill our specification (spec.ni).

sounded like it was only necessary when mounting the configuration from a file. As Elektra is also usable without mounting specific files (i.e. elektrified applications), I didn't think this was necessary.

atmaxinger avatar Aug 08 '22 16:08 atmaxinger

It's not about whether or not you are using a file. It's about the existence of a mountpoint. If you don't call kdb mount (indirectly also happens via kdb spec-mount), your config will be saved in the default mountpoints (assuming no other more specific mountpoint exists from something else). But plugins only work, if they are explicitly added to a mountpoint. The default moutpoints only contain the bare minimum (storage and resolver plugins).

kodebach avatar Aug 08 '22 16:08 kodebach

Yes I understand that now, but we should really specify this clearly in the guide.

atmaxinger avatar Aug 08 '22 19:08 atmaxinger

@atmaxinger Can you please clarify what exactly should be specified in which guide?

markus2330 avatar Aug 10 '22 15:08 markus2330

@markus2330 In the How to Write a Specification in Elektra that it is mandatory to call kdb spec-mount for the check plugins to work. The way this is worded now makes it seem that you only need to do it if the configuration itself is mounted.

atmaxinger avatar Aug 11 '22 08:08 atmaxinger

I agree, the sentence

This specification mount makes sure that the paths where the concrete configuration should be (app.ni) are ready to fulfill our specification (spec.ni).

could be worded better. It is very much clear what "ready to fulfill a specification" means.

Maybe there should just be a quick overview of the required steps at the top. That could also be helpful for people who already read the tutorial once, but need a refresher.

kodebach avatar Aug 11 '22 12:08 kodebach

@atmaxinger I don't find the word mandatory on that page? Can you please create a separate issue (or PR) describing more precisely how to improve the documentation? It is very valuable input but we need to fix it precisely, otherwise we cause more damage than what it helps. (It is never wrong to do a spec-mount, this is why the tutorial is insisting on that spec-mount is called. To explain in which cases it is needed would be too much for such a tutorial.)

Maybe there should just be a quick overview of the required steps at the top.

I think that in most of our problems in the docu additional overviews/links/text won't help (except for, e.g., beginner devs, there we probably really missing something like that). We need to fix vague/misleading sentences.

markus2330 avatar Aug 12 '22 14:08 markus2330

I don't find the word mandatory on that page

Yes, and that's the problem. @kodebach pointed out that kdb spec-mount must be called for it to work. However, I interpreted the current wording in the guide that you only need to call it if the configuration is mounted as an external file.

It is never wrong to do a spec-mount

Then this should be stated explicitly.

atmaxinger avatar Aug 12 '22 14:08 atmaxinger

As said, please in a separate issue. Deeply hidden in unrelated discussions it does not help.

markus2330 avatar Aug 12 '22 15:08 markus2330

I think that in most of our problems in the docu additional overviews/links/text won't help [...] We need to fix vague/misleading sentences.

Just a quick comment on that. I think it's also a structural problem. See #4436 (caution lots of text)

kodebach avatar Aug 12 '22 16:08 kodebach

Aside from the discussion about the tutorial, is the main issue still relevant? @markus2330 Maybe a good issue for the FLOSS course (triage).

flo91 avatar Oct 05 '22 21:10 flo91

The question is if we should fix this in old code to be replaced by @hannes99 C implementation later?

markus2330 avatar Oct 08 '22 05:10 markus2330

hey @kodebach, a quick question regarding this.

EDIT: But looking at the code in src/tools/kdb/set.cpp, there is no attempt to assure a cascading parent key AFAICT, so adding the plugins probably won't change anything.

I'm not sure what you mean by

attempt to assure a cascading parent key

What would be needed so the plugin(if present) is used for validation? Is a ksLookup and keySetString enough? If not, what else is necessary to make this work?

hannes99 avatar Feb 28 '23 15:02 hannes99

You just need to make sure to only use a cascading keys as the parent key that is given to kdbGet and kdbSet.

I assume, you simply use the key given to kdb set in the CLI as the parent key. In that case, you can do something like:

// Note: very rough sketch
Key * keyFromCli;

Key * parentKey = keyDup (keyFromCli);
keySetNamespace (keyFromCli, KEY_NS_CASCADING);

kdbGet (kdb, ks, parentKey);

keySetString (ksLookup (ks, keyFromCli, 0), valueFromCli);

kdbSet (kdb, ks, parentKey);

kodebach avatar Feb 28 '23 16:02 kodebach

To explain this a little bit, if the parent key is not cascading, then only mountpoints with the same namespace will be considered, since other mountpoints can never contain data below the parent key. However, that means in most cases spec:/ keys will not be loaded. Therefore, the spec plugin will not copy metadata, which in turn means that most validation plugins won't do anything, since normally they rely on metadata copied from spec:.

kodebach avatar Feb 28 '23 16:02 kodebach

ohh I see, thanks for the explanation!

hannes99 avatar Feb 28 '23 16:02 hannes99

I mark this stale as it did not have any activity for one year. I'll close it in two weeks if no further activity occurs. If you want it to be alive again, ping by writing a message here or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart:

github-actions[bot] avatar Feb 29 '24 01:02 github-actions[bot]

I closed this now because it has been inactive for more than one year. If I closed it by mistake, please do not hesitate to reopen it or create a new issue with the remainder of this issue. Thank you for your contributions :sparkling_heart:

github-actions[bot] avatar Mar 14 '24 01:03 github-actions[bot]