Skip to content

Commit 5ed614c

Browse files
authored
refactor: Replace xdg with directories (#95)
* Replace `xdg` with `directories` This enables us to build stackablectl for Windows as `xdg` didn't support Windows. * Rename `XDG_*` to `USER_DIR_*` * Remove unused struct * Add MPL-2.0 to allowed licenses
1 parent ea25f42 commit 5ed614c

File tree

7 files changed

+80
-49
lines changed

7 files changed

+80
-49
lines changed

Cargo.lock

Lines changed: 29 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ bcrypt = "0.15"
1515
clap = { version = "4.2.1", features = ["derive", "env"] }
1616
clap_complete = "4.2"
1717
comfy-table = { version = "7.0", features = ["custom_styling"] }
18+
directories = "5.0"
1819
dotenvy = "0.15"
1920
futures = "0.3"
2021
gobuild = "0.1.0-alpha.2"
@@ -45,7 +46,6 @@ utoipa = { version = "3.3", features = ["indexmap"] }
4546
utoipa-swagger-ui = { version = "3.1", features = ["axum"] }
4647
uuid = { version = "1.4.0", features = ["v4"] }
4748
which = "4.4"
48-
xdg = "2.4"
4949

5050
[patch."https://github.com/stackabletech/operator-rs.git"]
5151
# TODO: Switch to released version

deny.toml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,20 @@ allow = [
3131
"LicenseRef-webpki",
3232
"MIT",
3333
"Unicode-DFS-2016",
34-
"Zlib"
34+
"Zlib",
35+
"MPL-2.0",
3536
]
3637
private = { ignore = true }
3738

3839
[[licenses.clarify]]
3940
name = "ring"
4041
expression = "LicenseRef-ring"
41-
license-files = [
42-
{ path = "LICENSE", hash = 0xbd0eed23 },
43-
]
42+
license-files = [{ path = "LICENSE", hash = 0xbd0eed23 }]
4443

4544
[[licenses.clarify]]
4645
name = "webpki"
4746
expression = "LicenseRef-webpki"
48-
license-files = [
49-
{ path = "LICENSE", hash = 0x001c7e6c },
50-
]
47+
license-files = [{ path = "LICENSE", hash = 0x001c7e6c }]
5148

5249
[sources]
5350
unknown-registry = "deny"

rust/stackablectl/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ stackable-cockpit = { path = "../stackable-cockpit", features = ["openapi"] }
1414
clap_complete.workspace = true
1515
clap.workspace = true
1616
comfy-table.workspace = true
17+
directories.workspace = true
1718
dotenvy.workspace = true
1819
indexmap.workspace = true
1920
lazy_static.workspace = true
@@ -27,4 +28,3 @@ snafu.workspace = true
2728
tokio.workspace = true
2829
tracing-subscriber.workspace = true
2930
tracing.workspace = true
30-
xdg.workspace = true

rust/stackablectl/src/cli/mod.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::env;
22

33
use clap::{Parser, Subcommand, ValueEnum};
4-
use snafu::{ResultExt, Snafu};
4+
use directories::ProjectDirs;
5+
use snafu::Snafu;
56
use tracing::{debug, instrument, Level};
67

78
use stackable_cockpit::{
@@ -21,8 +22,9 @@ use crate::{
2122
release::ReleaseArgs, stack::StackArgs, stacklets::StackletsArgs,
2223
},
2324
constants::{
24-
CACHE_HOME_PATH, ENV_KEY_DEMO_FILES, ENV_KEY_RELEASE_FILES, ENV_KEY_STACK_FILES,
25-
REMOTE_DEMO_FILE, REMOTE_RELEASE_FILE, REMOTE_STACK_FILE,
25+
ENV_KEY_DEMO_FILES, ENV_KEY_RELEASE_FILES, ENV_KEY_STACK_FILES, REMOTE_DEMO_FILE,
26+
REMOTE_RELEASE_FILE, REMOTE_STACK_FILE, USER_DIR_APPLICATION_NAME,
27+
USER_DIR_ORGANIZATION_NAME, USER_DIR_QUALIFIER,
2628
},
2729
};
2830

@@ -123,9 +125,14 @@ impl Cli {
123125
if self.no_cache {
124126
Ok(CacheSettings::disabled())
125127
} else {
126-
let xdg = xdg::BaseDirectories::with_prefix(CACHE_HOME_PATH)
127-
.context(cache_settings_error::XdgSnafu)?;
128-
Ok(CacheSettings::disk(xdg.get_cache_home()))
128+
let project_dir = ProjectDirs::from(
129+
USER_DIR_QUALIFIER,
130+
USER_DIR_ORGANIZATION_NAME,
131+
USER_DIR_APPLICATION_NAME,
132+
)
133+
.ok_or(CacheSettingsError::UserDir)?;
134+
135+
Ok(CacheSettings::disk(project_dir.cache_dir()))
129136
}
130137
}
131138
}
@@ -184,12 +191,10 @@ pub enum OutputType {
184191
#[derive(Debug, Snafu)]
185192
#[snafu(module)]
186193
pub enum CacheSettingsError {
187-
#[snafu(display("unable to resolve XDG directories"))]
188-
Xdg { source: xdg::BaseDirectoriesError },
194+
#[snafu(display("unable to resolve user directories"))]
195+
UserDir,
189196
}
190197

191-
pub struct InheritStackDemoArgs {}
192-
193198
/// Returns a list of paths or urls based on the default (remote) file and
194199
/// files provided via the env variable.
195200
fn get_files(default_file: &str, env_key: &str) -> Result<Vec<PathOrUrl>, PathOrUrlParseError> {

rust/stackablectl/src/constants.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ pub const HELM_REPO_URL_STABLE: &str = "https://repo.stackable.tech/repository/h
1515
pub const HELM_REPO_URL_TEST: &str = "https://repo.stackable.tech/repository/helm-test/";
1616
pub const HELM_REPO_URL_DEV: &str = "https://repo.stackable.tech/repository/helm-dev/";
1717

18-
pub const CACHE_HOME_PATH: &str = "stackablectl";
18+
pub const USER_DIR_APPLICATION_NAME: &str = "stackablectl";
19+
pub const USER_DIR_ORGANIZATION_NAME: &str = "Stackable";
20+
pub const USER_DIR_QUALIFIER: &str = "tech";

web/src/api/schema.d.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ type OneOf<T extends any[]> = T extends [infer Only] ? Only : T extends [infer A
1212
export interface paths {
1313
"/demos": {
1414
/**
15-
* Retrieves all demos.
15+
* Retrieves all demos.
1616
* @description Retrieves all demos.
1717
*/
1818
get: operations["get_demos"];
1919
};
2020
"/demos/{name}": {
2121
/**
22-
* Retrieves one demo identified by `name`.
22+
* Retrieves one demo identified by `name`.
2323
* @description Retrieves one demo identified by `name`.
2424
*/
2525
get: operations["get_demo"];
@@ -32,21 +32,21 @@ export interface paths {
3232
};
3333
"/releases": {
3434
/**
35-
* Retrieves all releases.
35+
* Retrieves all releases.
3636
* @description Retrieves all releases.
3737
*/
3838
get: operations["get_releases"];
3939
};
4040
"/releases/{name}": {
4141
/**
42-
* Retrieves one release identified by `name`.
42+
* Retrieves one release identified by `name`.
4343
* @description Retrieves one release identified by `name`.
4444
*/
4545
get: operations["get_release"];
4646
};
4747
"/stacklets": {
4848
/**
49-
* Retrieves all stacklets.
49+
* Retrieves all stacklets.
5050
* @description Retrieves all stacklets.
5151
*/
5252
get: operations["get_stacklets"];
@@ -64,18 +64,18 @@ export interface components {
6464
/** @description An optional link to a documentation page */
6565
documentation?: string | null;
6666
/** @description A variable number of labels (tags) */
67-
labels?: (string)[];
67+
labels?: string[];
6868
/** @description A variable number of Helm or YAML manifests */
69-
manifests?: (components["schemas"]["ManifestSpec"])[];
69+
manifests?: components["schemas"]["ManifestSpec"][];
7070
/** @description A variable number of supported parameters */
71-
parameters?: (components["schemas"]["Parameter"])[];
71+
parameters?: components["schemas"]["Parameter"][];
7272
/** @description The name of the underlying stack */
7373
stackableStack: string;
7474
/**
7575
* @description Supported namespaces this demo can run in. An empty list indicates that
7676
* the demo can run in any namespace.
7777
*/
78-
supportedNamespaces?: (string)[];
78+
supportedNamespaces?: string[];
7979
};
8080
DisplayCondition: {
8181
condition: string;
@@ -116,7 +116,7 @@ export interface components {
116116
SessionToken: string;
117117
Stacklet: {
118118
/** @description Multiple cluster conditions. */
119-
conditions: (components["schemas"]["DisplayCondition"])[];
119+
conditions: components["schemas"]["DisplayCondition"][];
120120
/**
121121
* @description Endpoint addresses the product is reachable at.
122122
* The key is the service name (e.g. `web-ui`), the value is the URL.
@@ -144,23 +144,25 @@ export type external = Record<string, never>;
144144
export interface operations {
145145

146146
/**
147-
* Retrieves all demos.
147+
* Retrieves all demos.
148148
* @description Retrieves all demos.
149149
*/
150150
get_demos: {
151151
responses: {
152152
/** @description Retrieving a list of demos succeeded */
153153
200: {
154154
content: {
155-
"application/json": (components["schemas"]["DemoSpecV2"])[];
155+
"application/json": components["schemas"]["DemoSpecV2"][];
156156
};
157157
};
158158
/** @description Retrieving a list of demos failed */
159-
404: never;
159+
404: {
160+
content: never;
161+
};
160162
};
161163
};
162164
/**
163-
* Retrieves one demo identified by `name`.
165+
* Retrieves one demo identified by `name`.
164166
* @description Retrieves one demo identified by `name`.
165167
*/
166168
get_demo: {
@@ -172,7 +174,9 @@ export interface operations {
172174
};
173175
};
174176
/** @description Retrieving the demo with 'name' failed */
175-
404: never;
177+
404: {
178+
content: never;
179+
};
176180
};
177181
};
178182
log_in: {
@@ -199,38 +203,40 @@ export interface operations {
199203
};
200204
};
201205
/**
202-
* Retrieves all releases.
206+
* Retrieves all releases.
203207
* @description Retrieves all releases.
204208
*/
205209
get_releases: {
206210
responses: {
207211
/** @description Retrieving a list of releases succeeded */
208212
200: {
209213
content: {
210-
"application/json": (components["schemas"]["ReleaseSpec"])[];
214+
"application/json": components["schemas"]["ReleaseSpec"][];
211215
};
212216
};
213217
/** @description Retrieving a list of releases failed */
214-
404: never;
218+
404: {
219+
content: never;
220+
};
215221
};
216222
};
217223
/**
218-
* Retrieves one release identified by `name`.
224+
* Retrieves one release identified by `name`.
219225
* @description Retrieves one release identified by `name`.
220226
*/
221227
get_release: {
222228
responses: {
223229
};
224230
};
225231
/**
226-
* Retrieves all stacklets.
232+
* Retrieves all stacklets.
227233
* @description Retrieves all stacklets.
228234
*/
229235
get_stacklets: {
230236
responses: {
231237
200: {
232238
content: {
233-
"application/json": (components["schemas"]["Stacklet"])[];
239+
"application/json": components["schemas"]["Stacklet"][];
234240
};
235241
};
236242
};

0 commit comments

Comments
 (0)