security_client_rs/fleet/
packages.rs1use serde::{Deserialize, Serialize};
3use serde_json::{Map, Value, json};
4
5use super::{Fleet, Item, Items};
6use crate::{Scope, http::Method, request::endpoint};
7
8#[derive(Clone, Debug, Deserialize, Serialize)]
9#[non_exhaustive]
10pub struct Package {
11 pub name: String,
12 pub version: String,
13 #[serde(default)]
14 pub title: Option<String>,
15 #[serde(default)]
16 pub description: Option<String>,
17 #[serde(default)]
19 pub status: Option<String>,
20 #[serde(flatten)]
21 pub extra: Map<String, Value>,
22}
23
24impl<'a> Fleet<'a> {
25 pub fn list_packages(&self) -> ListPackages<'a> {
27 ListPackages(self.0.request(
28 Method::GET,
29 Scope::Space,
30 &["api", "fleet", "epm", "packages"],
31 ))
32 }
33
34 pub fn get_package(&self, name: &str, version: &str) -> GetPackage<'a> {
35 GetPackage(self.0.request(
36 Method::GET,
37 Scope::Space,
38 &["api", "fleet", "epm", "packages", name, version],
39 ))
40 }
41
42 pub fn install_package(&self, name: &str, version: &str) -> InstallPackage<'a> {
44 InstallPackage(
45 self.0
46 .request(
47 Method::POST,
48 Scope::Space,
49 &["api", "fleet", "epm", "packages", name, version],
50 )
51 .json(&json!({})),
52 )
53 }
54
55 pub fn uninstall_package(&self, name: &str, version: &str) -> UninstallPackage<'a> {
56 UninstallPackage(self.0.request(
57 Method::DELETE,
58 Scope::Space,
59 &["api", "fleet", "epm", "packages", name, version],
60 ))
61 }
62}
63
64endpoint! {
65 ListPackages => Items<Package>
67}
68
69impl ListPackages<'_> {
70 pub fn category(self, category: &str) -> Self {
71 Self(self.0.param("category", category))
72 }
73
74 pub fn prerelease(self, include: bool) -> Self {
75 Self(self.0.param("prerelease", include))
76 }
77}
78
79endpoint! {
80 GetPackage => Item<Package>
82}
83
84endpoint! {
85 InstallPackage => Value
87}
88
89impl InstallPackage<'_> {
90 pub fn force(self, force: bool) -> Self {
92 Self(self.0.field("force", force))
93 }
94
95 pub fn ignore_constraints(self, ignore: bool) -> Self {
96 Self(self.0.field("ignore_constraints", ignore))
97 }
98}
99
100endpoint! {
101 UninstallPackage => Value
103}
104
105impl UninstallPackage<'_> {
106 pub fn force(self, force: bool) -> Self {
108 Self(self.0.param("force", force))
109 }
110}