Skip to content

Commit 61014a3

Browse files
cockpit: use upstream cockpit types
Since we've made our typescript checks stricter, we can rely on the cockpit types from upstream. This will prevent drift between the types. The one downside to this is that we may have to keep the cockpit `pkg/lib` directory in the repository.
1 parent 21629f6 commit 61014a3

File tree

6 files changed

+43
-35
lines changed

6 files changed

+43
-35
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ VERSION := $(shell (cd "$(SRCDIR)" && grep "^Version:" cockpit/$(PACKAGE_NAME).s
77
COMMIT = $(shell (cd "$(SRCDIR)" && git rev-parse HEAD))
88

99
# TODO: figure out a strategy for keeping this updated
10-
COCKPIT_REPO_COMMIT = a70142a7a6f9c4e78e71f3c4ec738b6db2fbb04f
10+
COCKPIT_REPO_COMMIT = 0ee23c07488e343e04ec766a891d1fceea781d10
1111
COCKPIT_REPO_URL = https://github.com/cockpit-project/cockpit.git
1212
COCKPIT_REPO_TREE = '$(strip $(COCKPIT_REPO_COMMIT))^{tree}'
1313

src/Utilities/useIsCockpitAdmin.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const useIsCockpitAdmin = () => {
66
const [isAdmin, setIsAdmin] = useState(false);
77

88
useEffect(() => {
9+
// @ts-expect-error cockpit hasn't created a type for this upstream
910
const permission = cockpit.permission({ admin: true });
1011

1112
const onChangeListener = () => {

src/store/cockpit/baseQuery.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,23 @@ export const baseQuery =
3131
const cloudApi = cockpit.http('/run/cloudapi/api.socket', {
3232
superuser: 'try',
3333
});
34+
35+
let body: string;
36+
try {
37+
body = JSON.stringify(options.body);
38+
} catch {
39+
body = '';
40+
}
41+
3442
return cloudApi
3543
.request({
3644
path: baseUrl + options.url,
37-
body: options.body ?? '',
45+
body: body ?? '',
3846
method: options.method ?? 'GET',
39-
params: options.params,
40-
headers: options.headers,
47+
params: options.params ?? {},
48+
headers: options.headers ?? {},
4149
})
42-
.then((result) => {
50+
.then((result: string) => {
4351
resolve({ data: JSON.parse(result) });
4452
})
4553
.catch(

src/store/cockpit/cockpitApi.ts

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export const cockpitApi = contentSourcesApi.injectEndpoints({
127127
...parsed,
128128
id,
129129
version: version,
130-
last_modified_at: new Date(bpInfo!.mtime * 1000).toString(),
130+
last_modified_at: new Date(bpInfo!.mtime! * 1000).toString(),
131131
// linting is not supported on prem
132132
lint: {
133133
errors: [],
@@ -517,37 +517,36 @@ export const cockpitApi = contentSourcesApi.injectEndpoints({
517517
try {
518518
const workerConfig = cockpit.file(
519519
'/etc/osbuild-worker/osbuild-worker.toml',
520-
{
521-
superuser: 'required',
522-
},
523520
);
524521

525-
const contents = await workerConfig.modify((prev: string) => {
526-
if (!updateWorkerConfigRequest) {
527-
return prev;
528-
}
529-
530-
const merged = {
531-
...TOML.parse(prev),
532-
...updateWorkerConfigRequest,
533-
} as WorkerConfigFile;
534-
535-
const contents: WorkerConfigFile = {};
536-
Object.keys(merged).forEach((key: string) => {
537-
// this check helps prevent saving empty objects
538-
// into the osbuild-worker.toml config file.
539-
if (merged[key] !== undefined) {
540-
contents[key] = Section({
541-
...merged[key],
542-
});
522+
const contents = await workerConfig.modify(
523+
(prev: string | null) => {
524+
if (!updateWorkerConfigRequest) {
525+
return prev;
543526
}
544-
});
545527

546-
return TOML.stringify(contents, {
547-
newline: '\n',
548-
newlineAround: 'document',
549-
});
550-
});
528+
const merged = {
529+
...TOML.parse(prev ?? ''),
530+
...updateWorkerConfigRequest,
531+
} as WorkerConfigFile;
532+
533+
const contents: WorkerConfigFile = {};
534+
Object.keys(merged).forEach((key: string) => {
535+
// this check helps prevent saving empty objects
536+
// into the osbuild-worker.toml config file.
537+
if (merged[key] !== undefined) {
538+
contents[key] = Section({
539+
...merged[key],
540+
});
541+
}
542+
});
543+
544+
return TOML.stringify(contents, {
545+
newline: '\n',
546+
newlineAround: 'document',
547+
});
548+
},
549+
);
551550

552551
const systemServices = [
553552
'osbuild-composer.socket',

src/store/cockpit/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const readComposes = async (bpID: string) => {
6565
{
6666
id: entry[0],
6767
request: JSON.parse(composeReq),
68-
created_at: new Date(entry[1]!.mtime * 1000).toString(),
68+
created_at: new Date(entry[1]!.mtime! * 1000).toString(),
6969
blueprint_id: bpID,
7070
},
7171
];

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
// Needed so we can resolve `cockpit` & `cockpit/fsinfo`
2525
// types. We have stubbed those functions out for the
2626
// as this is the tsconfig file for the service.
27-
"./src/test/mocks/*"
27+
"./pkg/lib/*"
2828
]
2929
}
3030
},

0 commit comments

Comments
 (0)