Set a User Singleton Configuration
You can define user-specific settings that remain consistent across environments or clusters. Mix UserSingleton with a user-defined Type or ConfigUserSingleton with a user-defined configuration Type to create a user-specific instance of its configuration.
After you mix UserSingleton or ConfigUserSingleton with a Type and set a user-specific configuration, only you can access the configuration. When another user accesses the Type, they can only access the default configuration.
The following example demonstrates how to create a user-specific instance of a configuration, and how to confirm access to the configuration. The user-defined Type in this example is GoogleDrive.c3typ.
Set a user singleton configuration
Mix
UserSingletonwith the Type you want to set a user-specific configuration for. If the Type is a configuration Type, mix it withConfigUserSingleton:Type/** * Represents interactions with Google Drive. */ type GoogleDrive mixes ConfigUserSingleton { /** * The client ID for Google Drive API. */ @config(secret=true) clientId: string /** * The client secret for Google Drive API. */ @config(secret=true) clientSecret: string }This is an example Type called GoogleDrive.c3typ that stores credentials for integrating a C3 AI application with Google Drive.
Set a user-specific configuration for the Type at the environment or cluster level. Run the following code snippet in C3 AI Console to set the configuration:
JavaScriptGoogleDrive.make({clientId: '<your-client-id>', clientSecret: `<your-client-secret>`}).setConfig(ENV)This example code sets the client ID and client secret value for your user across the entire environment.
Confirm the user singleton configuration
Confirm the user singleton configuration persists across the environment or cluster, and that it is only accessible to your user.
Confirm configuration across environment or cluster
To confirm that your configuration persists across the environment, run the following code in the C3 AI Console of another application within the cluster to fetch the configuration:
GoogleDrive.make().inst()Optionally, you can run the following code instead:
GoogleDrive.make().getConfig()This returns the user-specific configuration that you set for the GoogleDrive Type, which persists across all applications in the environment.
Confirm configuration is restricted to your user
To confirm that another user cannot access the configuration, use the TestIdp Type to fetch the configuration as a role different than your user:
TestIdp.executeAsUser("MyTypeBasicUser", () => GoogleDrive.make().inst()) This does not return the configuration that you set for the GoogleDrive Type, because mixing the UserSingleton or ConfigUserSingleton Types sets a user-specific configuration.