Hi Steinar,

I have also tackled this before, and I achieved it using the ConfigAdmin
service. I think it has the advantage of being agnostic of the OSGi
runtime, which might be useful for some. When running in Karaf, the config
will be persisted to the cfg file backing it up. It has the disadvantage of
the properties in the cfg file becoming "typed".
One remark. I consider the cfg files in Karaf as another "interface" to set
configurations (similar to using config:edit), instead of being the files
where the configurations are persisted. The actual configurations are
stored by ConfigAdmin as typed properties inside ConfigAdmin's bundle
directory.

Best regards,
João Assunção




On Sat, Apr 12, 2025 at 8:25 PM Steinar Bang <[email protected]> wrote:

> >>>>> Steinar Bang <[email protected]>:
>
> >>> Is there a code example somewhere of an SCR component that saves a
> >>> value to a cfg file in karaf?
>
> > Looks like injecting a ConfigRepository service may be the way to go...?
> >
> https://github.com/apache/karaf/blob/main/config/core/src/main/java/org/apache/karaf/config/core/ConfigRepository.java#L26
>
> > I will try!
>
> Using ConfigReposity worked.
>
> This code gets config matching a pid which is the fully qualified
> classname and looks for the value "cipherkey". If no value can be found
> a new value is created and saved using ConfigRepository:
>
> https://github.com/steinarb/authservice/blob/fc6c29fb5cede9d9f3e8d4212124adc815ac6cf6/authservice/authservice.web.security.cipherkey/src/main/java/no/priv/bang/authservice/web/security/cipherkey/ChipherKeyServiceProvider.java#L32
>
>

Reply via email to