Skip to content

Commit f491bdd

Browse files
committed
chore: minor changes for consistency
1 parent 4451853 commit f491bdd

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

examples/get_acl_tokens.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ async fn main() {
2626
token
2727
.policies
2828
.iter()
29-
.filter(|p| !p.is_empty())
3029
.map(|p| format!(" ({:?})", p))
3130
.collect::<Vec<_>>()
3231
.join(", ")

src/acl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ impl Consul {
119119
.await?;
120120
serde_json::from_reader(resp.reader()).map_err(ConsulError::ResponseDeserializationFailed)
121121
}
122+
122123
/// Creates a new ACL token.
123124
///
124125
/// Sends a `PUT` to `/v1/acl/token` to generate a new token which can be attached to ACL policies.

src/acl_types.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ pub struct ACLToken {
1616
/// Description
1717
pub description: String,
1818
/// Policies
19-
pub policies: Option<Vec<ACLTokenPolicyLink>>,
19+
#[serde(default)]
20+
pub policies: Vec<ACLTokenPolicyLink>,
2021
/// Token only valid in this datacenter
2122
#[serde(default)]
2223
pub local: bool,
@@ -61,8 +62,8 @@ pub struct CreateACLTokenPayload {
6162
#[serde(skip_serializing_if = "Option::is_none")]
6263
pub description: Option<String>,
6364
/// Policies
64-
#[serde(skip_serializing_if = "Option::is_none")]
65-
pub policies: Option<Vec<ACLTokenPolicyLink>>,
65+
#[serde(skip_serializing_if = "Vec::is_empty")]
66+
pub policies: Vec<ACLTokenPolicyLink>,
6667
/// Token only valid in this datacenter
6768
#[serde(default)]
6869
pub local: bool,
@@ -77,24 +78,26 @@ pub struct CreateACLTokenPayload {
7778
pub expiration_time: Option<Duration>,
7879
}
7980

80-
/// Acl Policy
81+
/// Represents an ACL (Access Control List) policy.
8182
#[derive(Debug, Serialize, Deserialize)]
8283
#[serde(rename_all = "PascalCase")]
8384
pub struct ACLPolicy {
84-
/// id
85+
/// Unique identifier for the policy.
8586
#[serde(rename = "ID")]
8687
pub id: String,
87-
/// name
88+
/// The name of the policy
8889
pub name: String,
89-
/// Description
90+
/// Description of the policy.
9091
pub description: String,
91-
/// hash
92+
/// Hash of the policy.
9293
pub hash: String,
93-
/// Create index
94+
/// Index at which the policy was created.
9495
pub create_index: u32,
95-
/// Datacenters
96-
pub datacenters: Option<String>,
97-
/// modify index
96+
// `datacenters` is Option::Vec because when `datacenters` is set to `null` we would need
97+
// to define a custom deserializer in case we had `Vec` directly
98+
/// List of applicable datacenters.
99+
pub datacenters: Option<Vec<String>>,
100+
/// Index at which the policy was last modified.
98101
pub modify_index: u32,
99102
}
100103

tests/test_runner.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ mod smoke_acl {
100100
description: Some("Smmoke test".to_owned()),
101101
secret_id: Some("00000000-9494-1111-1111-222222222229".to_owned()),
102102
accessor_id: Some("8d5faa9a-1111-1111-b0c8-52ea5346d814".to_owned()),
103-
policies: Some(policy_link_vec),
103+
policies: policy_link_vec,
104104
..Default::default()
105105
};
106106
let _ = consul.create_acl_token(&token_payload).await.unwrap();
@@ -110,10 +110,7 @@ mod smoke_acl {
110110
.read_acl_token("8d5faa9a-1111-1111-b0c8-52ea5346d814".to_owned())
111111
.await
112112
.unwrap();
113-
assert!(
114-
result.policies.unwrap().first().unwrap().name
115-
== Some("smoke_test_policy_1".to_owned())
116-
);
113+
assert!(result.policies.first().unwrap().name == Some("smoke_test_policy_1".to_owned()));
117114

118115
assert!(result.secret_id == "00000000-9494-1111-1111-222222222229".to_owned());
119116

tests/utils/test_setup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use rs_consul::*;
2-
use std::env;
32
type Result<T> = std::result::Result<T, rs_consul::ConsulError>;
43

54
pub(crate) fn get_client() -> Consul {
@@ -10,6 +9,7 @@ pub(crate) fn get_client() -> Consul {
109
#[cfg(feature = "acl")]
1110
/// a consul client with write permission allows for manipulating tokens
1211
pub(crate) fn get_privileged_client() -> Consul {
12+
use std::env;
1313
let addr = env::var("CONSUL_HTTP_ADDR").unwrap_or_else(|_| "http://127.0.0.1:8500".to_string());
1414
let conf: Config = Config {
1515
address: addr,

0 commit comments

Comments
 (0)