Official Content

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.

image_202061995517_1_png image_202061711259_1_png

Methods

Create method

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'.

Domains

StorageProvider domain

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.

Examples

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

Note: "Default" makes reference to the one defined in the Storage Provider property at design time.

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.

  1. 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.
  2. 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.

Scope

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.

Availability

This feature is available since GeneXus 16 upgrade 10.

See Also

Storage Provider API

Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant