steering_policy.go raw

   1  // Copyright (c) 2016, 2018, 2025, Oracle and/or its affiliates.  All rights reserved.
   2  // This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
   3  // Code generated. DO NOT EDIT.
   4  
   5  // DNS API
   6  //
   7  // API for the DNS service. Use this API to manage DNS zones, records, and other DNS resources.
   8  // For more information, see Overview of the DNS Service (https://docs.oracle.com/iaas/Content/DNS/Concepts/dnszonemanagement.htm).
   9  //
  10  
  11  package dns
  12  
  13  import (
  14  	"encoding/json"
  15  	"fmt"
  16  	"strings"
  17  
  18  	"github.com/nrdcg/oci-go-sdk/common/v1065"
  19  )
  20  
  21  // SteeringPolicy A DNS steering policy.
  22  // **Warning:** Oracle recommends that you avoid using any confidential information when you supply string values using the API.
  23  type SteeringPolicy struct {
  24  
  25  	// The OCID of the compartment containing the steering policy.
  26  	CompartmentId *string `mandatory:"true" json:"compartmentId"`
  27  
  28  	// A user-friendly name for the steering policy. Does not have to be unique and can be changed.
  29  	// Avoid entering confidential information.
  30  	DisplayName *string `mandatory:"true" json:"displayName"`
  31  
  32  	// The Time To Live (TTL) for responses from the steering policy, in seconds.
  33  	// If not specified during creation, a value of 30 seconds will be used.
  34  	Ttl *int `mandatory:"true" json:"ttl"`
  35  
  36  	// A set of predefined rules based on the desired purpose of the steering policy. Each
  37  	// template utilizes Traffic Management's rules in a different order to produce the desired
  38  	// results when answering DNS queries.
  39  	//
  40  	// **Example:** The `FAILOVER` template determines answers by filtering the policy's answers
  41  	// using the `FILTER` rule first, then the following rules in succession: `HEALTH`, `PRIORITY`,
  42  	// and `LIMIT`. This gives the domain dynamic failover capability.
  43  	//
  44  	// It is **strongly recommended** to use a template other than `CUSTOM` when creating
  45  	// a steering policy.
  46  	//
  47  	// All templates require the rule order to begin with an unconditional `FILTER` rule that keeps
  48  	// answers contingent upon `answer.isDisabled != true`, except for `CUSTOM`. A defined
  49  	// `HEALTH` rule must follow the `FILTER` rule if the policy references a `healthCheckMonitorId`.
  50  	// The last rule of a template must must be a `LIMIT` rule. For more information about templates
  51  	// and code examples, see Traffic Management API Guide (https://docs.oracle.com/iaas/Content/TrafficManagement/Concepts/trafficmanagementapi.htm).
  52  	// **Template Types**
  53  	// * `FAILOVER` - Uses health check information on your endpoints to determine which DNS answers
  54  	// to serve. If an endpoint fails a health check, the answer for that endpoint will be removed
  55  	// from the list of available answers until the endpoint is detected as healthy.
  56  	//
  57  	// * `LOAD_BALANCE` - Distributes web traffic to specified endpoints based on defined weights.
  58  	//
  59  	// * `ROUTE_BY_GEO` - Answers DNS queries based on the query's geographic location. For a list of geographic
  60  	// locations to route by, see Traffic Management Geographic Locations (https://docs.oracle.com/iaas/Content/TrafficManagement/Reference/trafficmanagementgeo.htm).
  61  	//
  62  	// * `ROUTE_BY_ASN` - Answers DNS queries based on the query's originating ASN.
  63  	//
  64  	// * `ROUTE_BY_IP` - Answers DNS queries based on the query's IP address.
  65  	//
  66  	// * `CUSTOM` - Allows a customized configuration of rules.
  67  	Template SteeringPolicyTemplateEnum `mandatory:"true" json:"template"`
  68  
  69  	// Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace.
  70  	// For more information, see Resource Tags (https://docs.oracle.com/iaas/Content/General/Concepts/resourcetags.htm).
  71  	//
  72  	// **Example:** `{"Department": "Finance"}`
  73  	FreeformTags map[string]string `mandatory:"true" json:"freeformTags"`
  74  
  75  	// Defined tags for this resource. Each key is predefined and scoped to a namespace.
  76  	// For more information, see Resource Tags (https://docs.oracle.com/iaas/Content/General/Concepts/resourcetags.htm).
  77  	//
  78  	// **Example:** `{"Operations": {"CostCenter": "42"}}`
  79  	DefinedTags map[string]map[string]interface{} `mandatory:"true" json:"definedTags"`
  80  
  81  	// The set of all answers that can potentially issue from the steering policy.
  82  	Answers []SteeringPolicyAnswer `mandatory:"true" json:"answers"`
  83  
  84  	// The series of rules that will be processed in sequence to reduce the pool of answers
  85  	// to a response for any given request.
  86  	//
  87  	// The first rule receives a shuffled list of all answers, and every other rule receives
  88  	// the list of answers emitted by the one preceding it. The last rule populates the
  89  	// response.
  90  	Rules []SteeringPolicyRule `mandatory:"true" json:"rules"`
  91  
  92  	// The canonical absolute URL of the resource.
  93  	Self *string `mandatory:"true" json:"self"`
  94  
  95  	// The OCID of the resource.
  96  	Id *string `mandatory:"true" json:"id"`
  97  
  98  	// The date and time the resource was created, expressed in RFC 3339 timestamp format.
  99  	// **Example:** `2016-07-22T17:23:59:60Z`
 100  	TimeCreated *common.SDKTime `mandatory:"true" json:"timeCreated"`
 101  
 102  	// The current state of the resource.
 103  	LifecycleState SteeringPolicyLifecycleStateEnum `mandatory:"true" json:"lifecycleState"`
 104  
 105  	// The OCID of the health check monitor providing health data about the answers of the
 106  	// steering policy. A steering policy answer with `rdata` matching a monitored endpoint
 107  	// will use the health data of that endpoint. A steering policy answer with `rdata` not
 108  	// matching any monitored endpoint will be assumed healthy.
 109  	//
 110  	// **Note:** To use the Health Check monitoring feature in a steering policy, a monitor
 111  	// must be created using the Health Checks service first. For more information on how to
 112  	// create a monitor, please see Managing Health Checks (https://docs.oracle.com/iaas/Content/HealthChecks/Tasks/managinghealthchecks.htm).
 113  	HealthCheckMonitorId *string `mandatory:"false" json:"healthCheckMonitorId"`
 114  }
 115  
 116  func (m SteeringPolicy) String() string {
 117  	return common.PointerString(m)
 118  }
 119  
 120  // ValidateEnumValue returns an error when providing an unsupported enum value
 121  // This function is being called during constructing API request process
 122  // Not recommended for calling this function directly
 123  func (m SteeringPolicy) ValidateEnumValue() (bool, error) {
 124  	errMessage := []string{}
 125  	if _, ok := GetMappingSteeringPolicyTemplateEnum(string(m.Template)); !ok && m.Template != "" {
 126  		errMessage = append(errMessage, fmt.Sprintf("unsupported enum value for Template: %s. Supported values are: %s.", m.Template, strings.Join(GetSteeringPolicyTemplateEnumStringValues(), ",")))
 127  	}
 128  	if _, ok := GetMappingSteeringPolicyLifecycleStateEnum(string(m.LifecycleState)); !ok && m.LifecycleState != "" {
 129  		errMessage = append(errMessage, fmt.Sprintf("unsupported enum value for LifecycleState: %s. Supported values are: %s.", m.LifecycleState, strings.Join(GetSteeringPolicyLifecycleStateEnumStringValues(), ",")))
 130  	}
 131  
 132  	if len(errMessage) > 0 {
 133  		return true, fmt.Errorf("%s", strings.Join(errMessage, "\n"))
 134  	}
 135  	return false, nil
 136  }
 137  
 138  // UnmarshalJSON unmarshals from json
 139  func (m *SteeringPolicy) UnmarshalJSON(data []byte) (e error) {
 140  	model := struct {
 141  		HealthCheckMonitorId *string                           `json:"healthCheckMonitorId"`
 142  		CompartmentId        *string                           `json:"compartmentId"`
 143  		DisplayName          *string                           `json:"displayName"`
 144  		Ttl                  *int                              `json:"ttl"`
 145  		Template             SteeringPolicyTemplateEnum        `json:"template"`
 146  		FreeformTags         map[string]string                 `json:"freeformTags"`
 147  		DefinedTags          map[string]map[string]interface{} `json:"definedTags"`
 148  		Answers              []SteeringPolicyAnswer            `json:"answers"`
 149  		Rules                []steeringpolicyrule              `json:"rules"`
 150  		Self                 *string                           `json:"self"`
 151  		Id                   *string                           `json:"id"`
 152  		TimeCreated          *common.SDKTime                   `json:"timeCreated"`
 153  		LifecycleState       SteeringPolicyLifecycleStateEnum  `json:"lifecycleState"`
 154  	}{}
 155  
 156  	e = json.Unmarshal(data, &model)
 157  	if e != nil {
 158  		return
 159  	}
 160  	var nn interface{}
 161  	m.HealthCheckMonitorId = model.HealthCheckMonitorId
 162  
 163  	m.CompartmentId = model.CompartmentId
 164  
 165  	m.DisplayName = model.DisplayName
 166  
 167  	m.Ttl = model.Ttl
 168  
 169  	m.Template = model.Template
 170  
 171  	m.FreeformTags = model.FreeformTags
 172  
 173  	m.DefinedTags = model.DefinedTags
 174  
 175  	m.Answers = make([]SteeringPolicyAnswer, len(model.Answers))
 176  	copy(m.Answers, model.Answers)
 177  	m.Rules = make([]SteeringPolicyRule, len(model.Rules))
 178  	for i, n := range model.Rules {
 179  		nn, e = n.UnmarshalPolymorphicJSON(n.JsonData)
 180  		if e != nil {
 181  			return e
 182  		}
 183  		if nn != nil {
 184  			m.Rules[i] = nn.(SteeringPolicyRule)
 185  		} else {
 186  			m.Rules[i] = nil
 187  		}
 188  	}
 189  	m.Self = model.Self
 190  
 191  	m.Id = model.Id
 192  
 193  	m.TimeCreated = model.TimeCreated
 194  
 195  	m.LifecycleState = model.LifecycleState
 196  
 197  	return
 198  }
 199  
 200  // SteeringPolicyTemplateEnum Enum with underlying type: string
 201  type SteeringPolicyTemplateEnum string
 202  
 203  // Set of constants representing the allowable values for SteeringPolicyTemplateEnum
 204  const (
 205  	SteeringPolicyTemplateFailover    SteeringPolicyTemplateEnum = "FAILOVER"
 206  	SteeringPolicyTemplateLoadBalance SteeringPolicyTemplateEnum = "LOAD_BALANCE"
 207  	SteeringPolicyTemplateRouteByGeo  SteeringPolicyTemplateEnum = "ROUTE_BY_GEO"
 208  	SteeringPolicyTemplateRouteByAsn  SteeringPolicyTemplateEnum = "ROUTE_BY_ASN"
 209  	SteeringPolicyTemplateRouteByIp   SteeringPolicyTemplateEnum = "ROUTE_BY_IP"
 210  	SteeringPolicyTemplateCustom      SteeringPolicyTemplateEnum = "CUSTOM"
 211  )
 212  
 213  var mappingSteeringPolicyTemplateEnum = map[string]SteeringPolicyTemplateEnum{
 214  	"FAILOVER":     SteeringPolicyTemplateFailover,
 215  	"LOAD_BALANCE": SteeringPolicyTemplateLoadBalance,
 216  	"ROUTE_BY_GEO": SteeringPolicyTemplateRouteByGeo,
 217  	"ROUTE_BY_ASN": SteeringPolicyTemplateRouteByAsn,
 218  	"ROUTE_BY_IP":  SteeringPolicyTemplateRouteByIp,
 219  	"CUSTOM":       SteeringPolicyTemplateCustom,
 220  }
 221  
 222  var mappingSteeringPolicyTemplateEnumLowerCase = map[string]SteeringPolicyTemplateEnum{
 223  	"failover":     SteeringPolicyTemplateFailover,
 224  	"load_balance": SteeringPolicyTemplateLoadBalance,
 225  	"route_by_geo": SteeringPolicyTemplateRouteByGeo,
 226  	"route_by_asn": SteeringPolicyTemplateRouteByAsn,
 227  	"route_by_ip":  SteeringPolicyTemplateRouteByIp,
 228  	"custom":       SteeringPolicyTemplateCustom,
 229  }
 230  
 231  // GetSteeringPolicyTemplateEnumValues Enumerates the set of values for SteeringPolicyTemplateEnum
 232  func GetSteeringPolicyTemplateEnumValues() []SteeringPolicyTemplateEnum {
 233  	values := make([]SteeringPolicyTemplateEnum, 0)
 234  	for _, v := range mappingSteeringPolicyTemplateEnum {
 235  		values = append(values, v)
 236  	}
 237  	return values
 238  }
 239  
 240  // GetSteeringPolicyTemplateEnumStringValues Enumerates the set of values in String for SteeringPolicyTemplateEnum
 241  func GetSteeringPolicyTemplateEnumStringValues() []string {
 242  	return []string{
 243  		"FAILOVER",
 244  		"LOAD_BALANCE",
 245  		"ROUTE_BY_GEO",
 246  		"ROUTE_BY_ASN",
 247  		"ROUTE_BY_IP",
 248  		"CUSTOM",
 249  	}
 250  }
 251  
 252  // GetMappingSteeringPolicyTemplateEnum performs case Insensitive comparison on enum value and return the desired enum
 253  func GetMappingSteeringPolicyTemplateEnum(val string) (SteeringPolicyTemplateEnum, bool) {
 254  	enum, ok := mappingSteeringPolicyTemplateEnumLowerCase[strings.ToLower(val)]
 255  	return enum, ok
 256  }
 257  
 258  // SteeringPolicyLifecycleStateEnum Enum with underlying type: string
 259  type SteeringPolicyLifecycleStateEnum string
 260  
 261  // Set of constants representing the allowable values for SteeringPolicyLifecycleStateEnum
 262  const (
 263  	SteeringPolicyLifecycleStateActive   SteeringPolicyLifecycleStateEnum = "ACTIVE"
 264  	SteeringPolicyLifecycleStateCreating SteeringPolicyLifecycleStateEnum = "CREATING"
 265  	SteeringPolicyLifecycleStateDeleted  SteeringPolicyLifecycleStateEnum = "DELETED"
 266  	SteeringPolicyLifecycleStateDeleting SteeringPolicyLifecycleStateEnum = "DELETING"
 267  )
 268  
 269  var mappingSteeringPolicyLifecycleStateEnum = map[string]SteeringPolicyLifecycleStateEnum{
 270  	"ACTIVE":   SteeringPolicyLifecycleStateActive,
 271  	"CREATING": SteeringPolicyLifecycleStateCreating,
 272  	"DELETED":  SteeringPolicyLifecycleStateDeleted,
 273  	"DELETING": SteeringPolicyLifecycleStateDeleting,
 274  }
 275  
 276  var mappingSteeringPolicyLifecycleStateEnumLowerCase = map[string]SteeringPolicyLifecycleStateEnum{
 277  	"active":   SteeringPolicyLifecycleStateActive,
 278  	"creating": SteeringPolicyLifecycleStateCreating,
 279  	"deleted":  SteeringPolicyLifecycleStateDeleted,
 280  	"deleting": SteeringPolicyLifecycleStateDeleting,
 281  }
 282  
 283  // GetSteeringPolicyLifecycleStateEnumValues Enumerates the set of values for SteeringPolicyLifecycleStateEnum
 284  func GetSteeringPolicyLifecycleStateEnumValues() []SteeringPolicyLifecycleStateEnum {
 285  	values := make([]SteeringPolicyLifecycleStateEnum, 0)
 286  	for _, v := range mappingSteeringPolicyLifecycleStateEnum {
 287  		values = append(values, v)
 288  	}
 289  	return values
 290  }
 291  
 292  // GetSteeringPolicyLifecycleStateEnumStringValues Enumerates the set of values in String for SteeringPolicyLifecycleStateEnum
 293  func GetSteeringPolicyLifecycleStateEnumStringValues() []string {
 294  	return []string{
 295  		"ACTIVE",
 296  		"CREATING",
 297  		"DELETED",
 298  		"DELETING",
 299  	}
 300  }
 301  
 302  // GetMappingSteeringPolicyLifecycleStateEnum performs case Insensitive comparison on enum value and return the desired enum
 303  func GetMappingSteeringPolicyLifecycleStateEnum(val string) (SteeringPolicyLifecycleStateEnum, bool) {
 304  	enum, ok := mappingSteeringPolicyLifecycleStateEnumLowerCase[strings.ToLower(val)]
 305  	return enum, ok
 306  }
 307