With this functionality, you can change at runtime the Storage Provider set in the Storage Provider property, change its settings, or connect to other Storage Providers configured in cloudservices.config.
An external object called GeneXus.Common.Configuration.ExternalStorage that is part of the GeneXus Core module exposes all the methods needed for this functionality.
Returns an instance of the Storage Provider that is being used in the programs as configured in the Storage Provider property configured in the environment.
Return value |
Boolean |
Parameters |
ProviderType:StorageProviderType,
Properties:Properties Data Type,
OutStorageProvider:StorageProvider,
OutMessages:Messages |
Warning: Temporary Restriction: The &Properties input must include authentication credentials for your provider.
Connect method
Given a ProfileName defined in cloudservices.config, returns an instance of the corresponding Storage Provider.
Return value |
Boolean |
Parameters |
ProfileName:Character,
Properties:Properties Data Type,
OutStorageProvider:StorageProvider,
OutMessages:Messages |
Note: Temporary Restriction: The only supported value for ProfileName is 'Default'.
Enumerated domain with the Storage Provider Types available in Storage Provider property:
Amazon_S3 |
|
Box |
Not supported |
Google_CloudStorage |
|
IBM_Bluemix |
Not supported |
IBM_ObjectStorage |
|
Microsoft_Azure |
|
OpenStack |
Not supported |
Note: Supported values depend on the existence of the corresponding implementation in
Storage Provider property for the generator or installation that is being used.
In these samples:
- &Properties is of Properties Data Type
- &StorageProvider, &fromStorageProvider, &toStorageProvider are of Storage Provider API data type
- &ExternalStorage, &fromExternalStorage, &toExternalStorage are of GeneXus.Common.Configuration.ExternalStorage data type
- &Messages is of GeneXus.Common.Messages data type.
Use case 1: Just change a property (i.e.: the Bucket name)
&Properties = new()
&Properties.set(!"BUCKET_NAME", !"my-bucket")
if &ExternalStorage.Connect(!"Default", &Properties, &StorageProvider, &Messages)
//{{ use &StorageProvider }}
endIf
Use case 2: Completely configure a provider at runtime
&Properties = new()
&Properties.set(!"STORAGE_PROVIDER_ACCESSKEYID", !"{access-key-id_by-S3}")
&Properties.set(!"STORAGE_PROVIDER_SECRETACCESSKEY", !"{secret-access-key_by-S3}")
&Properties.set(!"STORAGE_PROVIDER_REGION", !"{region}")
&Properties.set(!"STORAGE_ENDPOINT", !"{endpoint_by-S3}")
if &ExternalStorage.Create(StorageProviderType.Amazon_S3, &Properties, &StorageProvider, &Messages)
//{{ use &StorageProvider }}
endIf
Note: This case is useful for multitenant scenarios, where for each tenant you need to use another storage environment.
Use case 3: Copy objects (files) from one Bucket or storage environment to another
&AWSProperties.clear()
&AzureProperties.clear()
if &ExternalStorage.Create(StorageProviderType.Amazon_S3, &AWSProperties, &OutStorageProvider, &OutMessages)
//{{ &OutStorageProvider points to Amazon, now you can download the files from there }}
if &ExternalStorage.Create(StorageProviderType.Microsoft_Azure, &AzureProperties, &OutStorageProvider, &OutMessages)
//{{ &OutStorageProvider now points to Azure, and you can upload the previously downloaded files to Azure }}
endIf
endIf
Warning: Only one instance of StorageProvider Data type can be used in a program. That is why the same variable &OutStorageProvider has been used in case 3.
Use case 4: Get the names of the properties
Here is how to get the names of the properties that can be configured for the storage provider in the Storage section of the cloudservices.config file.
- In the GeneXus IDE you must assign values to the properties (for example, those used to configure the connection to Google Cloud Storage): Service Account Key, Project ID and Application Name.
- To obtain the names of these properties, you can perform the following steps:
- Perform a Build of your Knowledge Base so that GeneXus generates the configuration files.
- Find the cloudservices.config file of your model. This file is generated during the Build and contains the cloud services configuration.
- Open the cloudservices.config file in a text editor.
- Inside the file, find the Storage section.
- Inside the Storage section, you will see the properties with their respective names and values. Copy the names of the properties that correspond to the properties you configured.
The dlls/jars of the provider used must be manually copied to the webapp. For example, for Java and Amazon S3, it is needed to copy manually the jars in the folder "GXInstallationFolder\Services\Storage\AmazonS3\services" into the lib folder of the application in the webapp "Tomcat\webapps\KBNameJavaEnvironment\WEB-INF\lib".
Cases 1 and 2 are supported in .NET, .NET Core, and Java generators.
Case 3 is, as of GeneXus 16 Upgrade 10, only supported in .NET and .NET Core generators.
This feature is available since GeneXus 16 upgrade 10.
Storage Provider API