Skip to main content

oci_rust_sdk/core/models/
security_rule.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4#[allow(unused_imports)]
5use super::*;
6/// A security rule is one of the items in a {@link NetworkSecurityGroup}. It is a virtual firewall rule for the VNICs in the network security group. A rule can be for either inbound ({@code direction}= INGRESS) or outbound ({@code direction}= EGRESS) IP packets.
7#[derive(Debug, Clone, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct SecurityRule {
10    /// Direction of the security rule. Set to {@code EGRESS} for rules to allow outbound IP packets, or {@code INGRESS} for rules to allow inbound IP packets.
11    pub direction: SecurityRuleDirection,
12
13    /// The transport protocol. Specify either {@code all} or an IPv4 protocol number as defined in [Protocol Numbers](http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml). Options are supported only for ICMP (\"1\"), TCP (\"6\"), UDP (\"17\"), and ICMPv6 (\"58\").
14    pub protocol: String,
15
16    /// An optional description of your choice for the rule.
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub description: Option<String>,
19
20    /// Conceptually, this is the range of IP addresses that a packet originating from the instance can go to. <p> Allowed values: <p> An IP address range in CIDR notation. For example: {@code 192.168.1.0/24} or {@code 2001:0db8:0123:45::/56} IPv6 addressing is supported for all commercial and government regions. See [IPv6 Addresses](https://docs.oracle.com/iaas/Content/Network/Concepts/ipv6.htm). <p> The {@code cidrBlock} value for a {@link Service}, if you're setting up a security rule for traffic destined for a particular {@code Service} through a service gateway. For example: {@code oci-phx-objectstorage}. <p> The [OCID](https://docs.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of a {@link NetworkSecurityGroup} in the same VCN. The value can be the NSG that the rule belongs to if the rule's intent is to control traffic between VNICs in the same NSG.
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub destination: Option<String>,
23
24    /// Type of destination for the rule. Required if {@code direction} = {@code EGRESS}. <p> Allowed values: <p> {@code CIDR_BLOCK}: If the rule's {@code destination} is an IP address range in CIDR notation. <p> {@code SERVICE_CIDR_BLOCK}: If the rule's {@code destination} is the {@code cidrBlock} value for a {@link Service} (the rule is for traffic destined for a particular {@code Service} through a service gateway). <p> {@code NETWORK_SECURITY_GROUP}: If the rule's {@code destination} is the [OCID](https://docs.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of a {@link NetworkSecurityGroup}.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub destination_type: Option<SecurityRuleDestinationType>,
27
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub icmp_options: Option<IcmpOptions>,
30
31    /// An Oracle-assigned identifier for the security rule. You specify this ID when you want to update or delete the rule. <p> Example: {@code 04ABEC}
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub id: Option<String>,
34
35    /// A stateless rule allows traffic in one direction. Remember to add a corresponding stateless rule in the other direction if you need to support bidirectional traffic. For example, if egress traffic allows TCP destination port 80, there should be an ingress rule to allow TCP source port 80. Defaults to false, which means the rule is stateful and a corresponding rule is not necessary for bidirectional traffic.
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub is_stateless: Option<bool>,
38
39    /// Whether the rule is valid. The value is {@code True} when the rule is first created. If the rule's {@code source} or {@code destination} is a network security group, the value changes to {@code False} if that network security group is deleted.
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub is_valid: Option<bool>,
42
43    /// Conceptually, this is the range of IP addresses that a packet coming into the instance can come from. <p> Allowed values: <p> An IP address range in CIDR notation. For example: {@code 192.168.1.0/24} or {@code 2001:0db8:0123:45::/56} IPv6 addressing is supported for all commercial and government regions. See [IPv6 Addresses](https://docs.oracle.com/iaas/Content/Network/Concepts/ipv6.htm). <p> The {@code cidrBlock} value for a {@link Service}, if you're setting up a security rule for traffic coming from a particular {@code Service} through a service gateway. For example: {@code oci-phx-objectstorage}. <p> The [OCID](https://docs.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of a {@link NetworkSecurityGroup} in the same VCN. The value can be the NSG that the rule belongs to if the rule's intent is to control traffic between VNICs in the same NSG.
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub source: Option<String>,
46
47    /// Type of source for the rule. Required if {@code direction} = {@code INGRESS}. <p> {@code CIDR_BLOCK}: If the rule's {@code source} is an IP address range in CIDR notation. <p> {@code SERVICE_CIDR_BLOCK}: If the rule's {@code source} is the {@code cidrBlock} value for a {@link Service} (the rule is for traffic coming from a particular {@code Service} through a service gateway). <p> {@code NETWORK_SECURITY_GROUP}: If the rule's {@code source} is the [OCID](https://docs.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of a {@link NetworkSecurityGroup}.
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub source_type: Option<SecurityRuleSourceType>,
50
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub tcp_options: Option<TcpOptions>,
53
54    /// The date and time the security rule was created. Format defined by [RFC3339](https://tools.ietf.org/html/rfc3339).
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub time_created: Option<DateTime<Utc>>,
57
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub udp_options: Option<UdpOptions>,
60}
61
62/// Required fields for SecurityRule
63pub struct SecurityRuleRequired {
64    /// Direction of the security rule. Set to {@code EGRESS} for rules to allow outbound IP packets, or {@code INGRESS} for rules to allow inbound IP packets.
65    pub direction: SecurityRuleDirection,
66
67    /// The transport protocol. Specify either {@code all} or an IPv4 protocol number as defined in [Protocol Numbers](http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml). Options are supported only for ICMP (\"1\"), TCP (\"6\"), UDP (\"17\"), and ICMPv6 (\"58\").
68    pub protocol: String,
69}
70
71impl SecurityRule {
72    /// Create a new SecurityRule with required fields
73    pub fn new(required: SecurityRuleRequired) -> Self {
74        Self {
75            direction: required.direction,
76
77            protocol: required.protocol,
78
79            description: None,
80
81            destination: None,
82
83            destination_type: None,
84
85            icmp_options: None,
86
87            id: None,
88
89            is_stateless: None,
90
91            is_valid: None,
92
93            source: None,
94
95            source_type: None,
96
97            tcp_options: None,
98
99            time_created: None,
100
101            udp_options: None,
102        }
103    }
104
105    /// Set description
106    pub fn set_description(mut self, value: Option<String>) -> Self {
107        self.description = value;
108        self
109    }
110
111    /// Set destination
112    pub fn set_destination(mut self, value: Option<String>) -> Self {
113        self.destination = value;
114        self
115    }
116
117    /// Set destination_type
118    pub fn set_destination_type(mut self, value: Option<SecurityRuleDestinationType>) -> Self {
119        self.destination_type = value;
120        self
121    }
122
123    /// Set direction
124    pub fn set_direction(mut self, value: SecurityRuleDirection) -> Self {
125        self.direction = value;
126        self
127    }
128
129    /// Set icmp_options
130    pub fn set_icmp_options(mut self, value: Option<IcmpOptions>) -> Self {
131        self.icmp_options = value;
132        self
133    }
134
135    /// Set id
136    pub fn set_id(mut self, value: Option<String>) -> Self {
137        self.id = value;
138        self
139    }
140
141    /// Set is_stateless
142    pub fn set_is_stateless(mut self, value: Option<bool>) -> Self {
143        self.is_stateless = value;
144        self
145    }
146
147    /// Set is_valid
148    pub fn set_is_valid(mut self, value: Option<bool>) -> Self {
149        self.is_valid = value;
150        self
151    }
152
153    /// Set protocol
154    pub fn set_protocol(mut self, value: String) -> Self {
155        self.protocol = value;
156        self
157    }
158
159    /// Set source
160    pub fn set_source(mut self, value: Option<String>) -> Self {
161        self.source = value;
162        self
163    }
164
165    /// Set source_type
166    pub fn set_source_type(mut self, value: Option<SecurityRuleSourceType>) -> Self {
167        self.source_type = value;
168        self
169    }
170
171    /// Set tcp_options
172    pub fn set_tcp_options(mut self, value: Option<TcpOptions>) -> Self {
173        self.tcp_options = value;
174        self
175    }
176
177    /// Set time_created
178    pub fn set_time_created(mut self, value: Option<DateTime<Utc>>) -> Self {
179        self.time_created = value;
180        self
181    }
182
183    /// Set udp_options
184    pub fn set_udp_options(mut self, value: Option<UdpOptions>) -> Self {
185        self.udp_options = value;
186        self
187    }
188
189    /// Set description (unwraps Option)
190    pub fn with_description(mut self, value: impl Into<String>) -> Self {
191        self.description = Some(value.into());
192        self
193    }
194
195    /// Set destination (unwraps Option)
196    pub fn with_destination(mut self, value: impl Into<String>) -> Self {
197        self.destination = Some(value.into());
198        self
199    }
200
201    /// Set destination_type (unwraps Option)
202    pub fn with_destination_type(mut self, value: SecurityRuleDestinationType) -> Self {
203        self.destination_type = Some(value);
204        self
205    }
206
207    /// Set icmp_options (unwraps Option)
208    pub fn with_icmp_options(mut self, value: IcmpOptions) -> Self {
209        self.icmp_options = Some(value);
210        self
211    }
212
213    /// Set id (unwraps Option)
214    pub fn with_id(mut self, value: impl Into<String>) -> Self {
215        self.id = Some(value.into());
216        self
217    }
218
219    /// Set is_stateless (unwraps Option)
220    pub fn with_is_stateless(mut self, value: bool) -> Self {
221        self.is_stateless = Some(value);
222        self
223    }
224
225    /// Set is_valid (unwraps Option)
226    pub fn with_is_valid(mut self, value: bool) -> Self {
227        self.is_valid = Some(value);
228        self
229    }
230
231    /// Set source (unwraps Option)
232    pub fn with_source(mut self, value: impl Into<String>) -> Self {
233        self.source = Some(value.into());
234        self
235    }
236
237    /// Set source_type (unwraps Option)
238    pub fn with_source_type(mut self, value: SecurityRuleSourceType) -> Self {
239        self.source_type = Some(value);
240        self
241    }
242
243    /// Set tcp_options (unwraps Option)
244    pub fn with_tcp_options(mut self, value: TcpOptions) -> Self {
245        self.tcp_options = Some(value);
246        self
247    }
248
249    /// Set time_created (unwraps Option)
250    pub fn with_time_created(mut self, value: DateTime<Utc>) -> Self {
251        self.time_created = Some(value);
252        self
253    }
254
255    /// Set udp_options (unwraps Option)
256    pub fn with_udp_options(mut self, value: UdpOptions) -> Self {
257        self.udp_options = Some(value);
258        self
259    }
260}