Open Closed

General Query: How to store 3rd party service connection URL and API Keys #8404


User avatar
0
Bryan-EDV created

Business requirement: We need to connect to 3rd party services (OpenAI) via connection sting and API key. Each tenant would have their own connection sting and API key. However if not defined on the tenant level, we need to fallback to a host-defined connection string and API key.

Question: Would settings module be suitable for handling this use case or would it be better add new columns to the SaasTenant table to track the connection string and API keys? We need the API keys to be encrypted if it is being stored in the Database. Would need your support on the optimal solution for this requirement

Thank you


23 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can define a setting for the tenant and host levels, and the setting value supports encryption.

    IsEncrypted: A boolean value indicates that whether this setting value should be encrypted on save and decrypted on read. It makes possible to secure the setting value in the database.

    https://abp.io/docs/latest/framework/infrastructure/settings?_redirected=B8ABF606AA1BDF5C629883DF1061649A#defining-settings

    https://github.com/abpframework/abp/blob/dev/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/TenantSettingManagerExtensions.cs#L11-L49

  • User Avatar
    0
    Bryan-EDV created

    How can we have these settings configurable form the UI (Angular)?

    I would like to be able to log in as a tenant admin and configure the URL and API key for the 3rd party service in the UI

    I know ABP has a settings page but was not able to find the documentation for updating the UI page for new properties

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    https://abp.io/docs/latest/modules/setting-management#angular-ui

  • User Avatar
    0
    Bryan-EDV created

    Hi,

    When using the TenantSettingValueProvider to retrieve the setting, is it possible to get a value for the host as well? for example, if the value is null for the tenant i want to fallback to the value from the host level

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Don't use TenantSettingValueProvider , Please use ISettingProvider to get setting value.

    ISettingProvider will try to get from User -> Tenant - Host - Default

  • User Avatar
    0
    Bryan-EDV created

    Thank you.

    Can i check what the difference is with using ISettingProvider and using configuration like so:

    or something like this

  • User Avatar
    0
    Bryan-EDV created

    I've also tried to add the component

    However the settings page still does not show the new tab

    Edit:

    I've also tried adding it in the ngOnInit method

  • User Avatar
    0
    Bryan-EDV created

    end result we want is something like this:

    whereby it can be defined on the host and also the tenant level.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can create a new question for the angular UI part. I will forward to our angular team.

    Thanks.

  • User Avatar
    0
    Bryan-EDV created

    Okay will pick up on the UI part later on

    For the settings defined in the BE, how do we retrieve the values and avaialble settings?

    e.g assuming I create the Llm.Url setting, how would my frontend be able to know that there is such a setting "Llm.Url" and retrieve its value? In the swagger UI it seems like there is no api for the user-defined settings names / values

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    assuming I create the Llm.Url setting, how would my frontend be able to know that there is such a setting Llm.Url and retrieve its value?

    You should hardcode the setting name in angular to get values.

    https://abp.io/docs/latest/framework/ui/angular/settings#how-to-get-a-specific-setting This requires the IsVisibleToClients(A boolean value indicates that whether this setting value is available in the client side or not. Default value is false to prevent accidently publishing an internal critical setting value.) of your setting definition is true:

    If your setting is not visible to the client. You have to add new API endpoints to get/set, just like

  • User Avatar
    0
    Bryan-EDV created

    https://abp.io/docs/latest/framework/ui/angular/settings#how-to-get-a-specific-setting

    Thanks, I will use the above link to get a value from the backend. Is there also a way to set a value using the this.config? Thanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Add a new api endpoint to change the setting value.

  • User Avatar
    0
    Bryan-EDV created

    Hi

    I noted that setting provider does not have setter methods (https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.Settings/Volo/Abp/Settings/ISettingProvider.cs)

    What service can i use to set the values of the setting? Thank you

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You need to add your custom API endpoints to update the setting value.

    You can also add a GET endpoint to get the setting value. Just like oauth

  • User Avatar
    0
    Bryan-EDV created

    Hi

    Are you able to point me to the source code for controller method for settings/oauth? I assume inside the controller method it would call some service like settingsProvider.setAsync('Llm.Url', newValue) but i might be mistaken

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The code exists in the Identity.Pro module.

    Volo.Abp.Identity.Pro.Application/Volo/Abp/Identity/IdentitySettingsAppService.cs Volo.Abp.Identity.Pro.HttpApi/Volo/Abp/Identity/IdentitySettingsController.cs

  • User Avatar
    0
    Bryan-EDV created

    Hi,

    Just to check

    SetGlobalAsync -> will set for host level?

    Then SetForTenantAsync / SetForCurrentTenantAsync -> will set for tenant level? What if SetForCurrentTenant is used while logged in as Host? Will it set for Host? Thanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    SetGlobalAsync -> will set for host level?

    Yes, the provider name will be G(global)

    Then SetForTenantAsync / SetForCurrentTenantAsync -> will set for tenant level?

    Yes, the provider name will be T(Tenant) and provider key will be current tenant id or the tenant id that your provider.

  • User Avatar
    0
    Bryan-EDV created

    Thank you,

    Meaning that G provider will apply to all tenants unless overwritten on a T level

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    You're right.

    User => Tenant => Global => Default

  • User Avatar
    0
    Bryan-EDV created

    Thanks so much. I think i've got all the info i need now. as mentioend earlier, we'll raise another ticket on the angular support https://abp.io/qa/questions/8404/3a169e3e-9f81-d082-1017-310a3927bd1e or if you could help get any details on that would be great

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Our angular team will check your question.

    Thanks.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09