forked from kubernetes-sigs/aws-load-balancer-controller
/
listener_rule.go
147 lines (126 loc) · 4.51 KB
/
listener_rule.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package elbv2
import (
"github.com/sonal-chauhan/aws-load-balancer-controller/pkg/model/core"
)
var _ core.Resource = &ListenerRule{}
// ListenerRule represents a ELBV2 ListenerRule
type ListenerRule struct {
core.ResourceMeta `json:"-"`
// desired state of ListenerRule
Spec ListenerRuleSpec `json:"spec"`
// observed state of ListenerRule
// +optional
Status *ListenerRuleStatus `json:"status,omitempty"`
}
// NewListenerRule constructs new ListenerRule resource.
func NewListenerRule(stack core.Stack, id string, spec ListenerRuleSpec) *ListenerRule {
lr := &ListenerRule{
ResourceMeta: core.NewResourceMeta(stack, "AWS::ElasticLoadBalancingV2::ListenerRule", id),
Spec: spec,
Status: nil,
}
stack.AddResource(lr)
lr.registerDependencies(stack)
return lr
}
// SetStatus sets the ListenerRule's status
func (lr *ListenerRule) SetStatus(status ListenerRuleStatus) {
lr.Status = &status
}
// register dependencies for ListenerRule.
func (lr *ListenerRule) registerDependencies(stack core.Stack) {
for _, dep := range lr.Spec.ListenerARN.Dependencies() {
stack.AddDependency(dep, lr)
}
}
type RuleConditionField string
const (
RuleConditionFieldHTTPHeader RuleConditionField = "http-header"
RuleConditionFieldHTTPRequestMethod RuleConditionField = "http-request-method"
RuleConditionFieldHostHeader RuleConditionField = "host-header"
RuleConditionFieldPathPattern RuleConditionField = "path-pattern"
RuleConditionFieldQueryString RuleConditionField = "query-string"
RuleConditionFieldSourceIP RuleConditionField = "source-ip"
)
// Information for a host header condition.
type HostHeaderConditionConfig struct {
// One or more host names.
Values []string `json:"values"`
}
// Information for an HTTP header condition.
type HTTPHeaderConditionConfig struct {
// The name of the HTTP header field.
HTTPHeaderName string `json:"httpHeaderName"`
// One or more strings to compare against the value of the HTTP header.
Values []string `json:"values"`
}
// Information for an HTTP method condition.
type HTTPRequestMethodConditionConfig struct {
// The name of the request method.
Values []string `json:"values"`
}
// Information about a path pattern condition.
type PathPatternConditionConfig struct {
// One or more path patterns to compare against the request URL.
Values []string `json:"values"`
}
// Information about a key/value pair.
type QueryStringKeyValuePair struct {
// The key.
// +optional
Key *string `json:"key,omitempty"`
// The value.
Value string `json:"value"`
}
// Information about a query string condition.
type QueryStringConditionConfig struct {
// One or more key/value pairs or values to find in the query string.
Values []QueryStringKeyValuePair `json:"values"`
}
// Information about a source IP condition.
type SourceIPConditionConfig struct {
// One or more source IP addresses, in CIDR format.
Values []string `json:"values"`
}
// Information about a condition for a rule.
type RuleCondition struct {
// The field in the HTTP request.
Field RuleConditionField `json:"field"`
// Information for a host header condition.
// +optional
HostHeaderConfig *HostHeaderConditionConfig `json:"hostHeaderConfig,omitempty"`
// Information for an HTTP header condition.
// +optional
HTTPHeaderConfig *HTTPHeaderConditionConfig `json:"httpHeaderConfig,omitempty"`
// Information for an HTTP method condition.
// +optional
HTTPRequestMethodConfig *HTTPRequestMethodConditionConfig `json:"httpRequestMethodConfig,omitempty"`
// Information for a path pattern condition.
// +optional
PathPatternConfig *PathPatternConditionConfig `json:"pathPatternConfig,omitempty"`
// Information for a query string condition.
// +optional
QueryStringConfig *QueryStringConditionConfig `json:"queryStringConfig,omitempty"`
// Information for a source IP condition.
// +optional
SourceIPConfig *SourceIPConditionConfig `json:"sourceIPConfig,omitempty"`
}
// ListenerRuleSpec defines the desired state of ListenerRule
type ListenerRuleSpec struct {
// The Amazon Resource Name (ARN) of the listener.
ListenerARN core.StringToken `json:"listenerARN"`
// The rule priority.
Priority int64 `json:"priority"`
// The actions.
Actions []Action `json:"actions"`
// The conditions.
Conditions []RuleCondition `json:"conditions"`
// The tags.
// +optional
Tags map[string]string `json:"tags,omitempty"`
}
// ListenerRuleStatus defines the observed state of ListenerRule
type ListenerRuleStatus struct {
// The Amazon Resource Name (ARN) of the rule.
RuleARN string `json:"ruleARN"`
}