C# Config class

更新时间:
复制 MD 格式

Config holds the parameters required to authenticate and connect to the OpenSearch API. Pass a Config instance to the client constructor to initialize a connection.

Parameters

ParameterTypeDescription
EndpointstringThe OpenSearch API endpoint. Omit the http:// or https:// prefix — the protocol is set separately by the Protocol parameter.
ProtocolstringThe request protocol. Valid values: HTTP, HTTPS.
TypestringThe authentication method. Valid values: access_key (Alibaba Cloud account or RAM user) and sts (Security Token Service).
AccessKeyIdstringThe AccessKey ID used to access OpenSearch.
AccessKeySecretstringThe AccessKey secret used to access OpenSearch.
SecurityTokenstringThe security token for Security Token Service (STS) authentication. Required only when Type is set to sts. To get a token, call the AssumeRole operation of Alibaba Cloud Resource Access Management (RAM).
UserAgentstringCustom user agent information. Leave blank in most cases.

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

Sample code

The following example defines a Config class that inherits from TeaModel:

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; }
}

Authentication methods

AccessKey authentication — use for Alibaba Cloud accounts and RAM users:

var config = new Config
{
    Endpoint        = "<your-endpoint>",
    Protocol        = "HTTPS",
    Type            = "access_key",
    AccessKeyId     = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_ID"),
    AccessKeySecret = Environment.GetEnvironmentVariable("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
};

STS authentication — use for temporary credentials issued via RAM's AssumeRole operation:

var config = new Config
{
    Endpoint        = "<your-endpoint>",
    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"),
};

Replace <your-endpoint> with your OpenSearch API endpoint, without the protocol prefix.