C# Config class

Updated at:

The Config class holds the connection and authentication parameters for OpenSearch API requests. Pass a configured Config instance when initializing the SDK client.

Parameters

ParameterDescriptionRequired
EndpointOpenSearch API endpoint. Omit the http:// or https:// prefix — the protocol is set separately via Protocol.No
ProtocolNetwork protocol. Valid values: HTTP, HTTPS.No
TypeAuthentication method. Valid values: access_key (Alibaba Cloud account or RAM user), sts (STS-based temporary credentials).No
AccessKeyIdAccessKey ID for authenticating API requests. Required when Type is access_key.Conditional
AccessKeySecretAccessKey secret for authenticating API requests. Required when Type is access_key.Conditional
SecurityTokenSTS token for authentication. Required when Type is sts. Call the AssumeRole operation of Alibaba Cloud RAM to get an STS token.Conditional
UserAgentCustom user agent string. Not required in most cases.No
Note: Store your AccessKey ID and AccessKey secret in environment variables rather than hardcoding them in your source code.

Examples

AccessKey authentication

Use this approach when authenticating as an Alibaba Cloud account or RAM user.

using System;
using Tea;

var config = new Config
{
    Endpoint        = "<your-endpoint>",          // e.g., opensearch-cn-hangzhou.aliyuncs.com
    Protocol        = "HTTPS",
    Type            = "access_key",
    AccessKeyId     = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
    AccessKeySecret = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
};

Replace <your-endpoint> with your OpenSearch API endpoint (without the https:// prefix).

To create an AccessKey pair, go to the AccessKey Management page.

STS authentication

Use this approach when your application requires short-lived, scoped credentials.

using System;
using Tea;

var config = new Config
{
    Endpoint        = "<your-endpoint>",          // e.g., opensearch-cn-hangzhou.aliyuncs.com
    Protocol        = "HTTPS",
    Type            = "sts",
    AccessKeyId     = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
    AccessKeySecret = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
    SecurityToken   = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_SECURITY_TOKEN")
};

Call the AssumeRole operation of Alibaba Cloud RAM to get an STS token.

Class definition

using System;
using System.Collections.Generic;
using System.IO;
using Tea;

public class Config : TeaModel
{
    [NameInMap("endpoint")]
    [Validation(Required = false)]
    public string Endpoint { get; set; }

    [NameInMap("protocol")]
    [Validation(Required = false)]
    public string Protocol { get; set; }

    [NameInMap("type")]
    [Validation(Required = false)]
    public string Type { get; set; }

    [NameInMap("securityToken")]
    [Validation(Required = false)]
    public string SecurityToken { get; set; }

    [NameInMap("accessKeyId")]
    [Validation(Required = false)]
    public string AccessKeyId { get; set; }

    [NameInMap("accessKeySecret")]
    [Validation(Required = false)]
    public string AccessKeySecret { get; set; }

    [NameInMap("userAgent")]
    [Validation(Required = false)]
    public string UserAgent { get; set; }
}