Skip to content

Commit 2b480dc

Browse files
committed
refactor: use ExitNodeStatus::new constructor
1 parent cc2add4 commit 2b480dc

File tree

4 files changed

+45
-21
lines changed

4 files changed

+45
-21
lines changed

src/cloud/aws.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,21 @@ impl Provisioner for AWSProvisioner {
206206
}
207207
};
208208

209-
let exit_node = ExitNodeStatus {
210-
name: name.clone(),
211-
ip: public_ip,
212-
id: Some(instance.instance_id.unwrap()),
213-
provider: provisioner.clone(),
214-
service_binding: vec![],
215-
};
209+
// let exit_node = ExitNodeStatus {
210+
// name: name.clone(),
211+
// ip: public_ip,
212+
// id: Some(instance.instance_id.unwrap()),
213+
// provider: provisioner.clone(),
214+
// service_binding: vec![],
215+
// };
216+
let exit_node = ExitNodeStatus::new(
217+
provisioner.clone(),
218+
name.clone(),
219+
public_ip,
220+
// needless conversion?
221+
// todo: Clean this up, minor performance hit
222+
instance.instance_id.map(|id| id.to_string()).as_deref(),
223+
);
216224

217225
Ok(exit_node)
218226
}

src/cloud/digitalocean.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,12 @@ impl Provisioner for DigitalOceanProvisioner {
131131
}
132132
};
133133

134-
let exit_node = ExitNodeStatus {
135-
name: name.clone(),
136-
ip: droplet_ip.clone(),
137-
id: Some(droplet.id.to_string()),
138-
provider: provisioner.clone(),
139-
service_binding: vec![],
140-
};
134+
let exit_node = ExitNodeStatus::new(
135+
provisioner.clone(),
136+
name.clone(),
137+
droplet_ip.clone(),
138+
Some(&droplet_id),
139+
);
141140

142141
Ok(exit_node)
143142
}

src/cloud/linode.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,20 @@ impl Provisioner for LinodeProvisioner {
111111
}
112112
};
113113

114-
let status = ExitNodeStatus {
115-
ip: instance_ip,
116-
name: instance.label,
117-
provider: provisioner.to_string(),
118-
id: Some(instance.id.to_string()),
119-
service_binding: vec![],
120-
};
114+
// let status = ExitNodeStatus {
115+
// ip: instance_ip,
116+
// name: instance.label,
117+
// provider: provisioner.to_string(),
118+
// id: Some(instance.id.to_string()),
119+
// service_binding: vec![],
120+
// };
121+
122+
let status = ExitNodeStatus::new(
123+
instance_ip,
124+
instance.label,
125+
provisioner.to_string(),
126+
Some(&instance.id.to_string()),
127+
);
121128

122129
Ok(status)
123130
}

src/ops.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ impl ExitNodeStatus {
145145
.find(|svc| svc.namespace == namespace && svc.name == name)
146146
.cloned()
147147
}
148+
149+
pub fn new(provider: String, name: String, ip: String, id: Option<&str>) -> Self {
150+
Self {
151+
provider,
152+
name,
153+
ip,
154+
id: None,
155+
service_binding: vec![],
156+
}
157+
}
148158
}
149159

150160
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]

0 commit comments

Comments
 (0)