Skip to content

Commit ddf6d97

Browse files
committed
Fix groups import/export in on-premise environment
add support for both `customizations.groups` (hosted) and `customizations.group` (on-premise) formats. Updated mapper and export logic to handle format conversion between JSON and TOML blueprints.
1 parent 268f151 commit ddf6d97

File tree

1 file changed

+55
-11
lines changed

1 file changed

+55
-11
lines changed

src/Components/Blueprints/helpers/onPremToHostedBlueprintMapper.tsx

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,16 @@ export type CustomizationsOnPrem = {
7777
hostname?: string;
7878
kernel?: Kernel;
7979
user?: UserOnPrem[];
80+
/**
81+
* User groups with GIDs (plural form, used in Hosted environment).
82+
* Hosted blueprints use this field in JSON format.
83+
*/
8084
groups?: GroupOnPrem[];
85+
/**
86+
* User groups with GIDs (singular form, used in On-Prem environment).
87+
* On-Prem blueprints use this field in TOML format: [[customizations.group]]
88+
*/
89+
group?: GroupOnPrem[];
8190
timezone?: Timezone;
8291
locale?: Locale;
8392
firewall?: FirewallCustomization;
@@ -123,9 +132,11 @@ export const mapOnPremToHosted = async (
123132
blueprint.packages !== undefined
124133
? blueprint.packages.map((p) => p.name)
125134
: undefined;
126-
const groups =
127-
blueprint.customizations?.groups !== undefined
128-
? blueprint.customizations.groups.map((p) => `@${p.name}`)
135+
// Note: blueprint.groups refers to package groups (e.g., @development-tools),
136+
// not user groups. User groups are in customizations.groups (see below).
137+
const packageGroups =
138+
blueprint.groups !== undefined
139+
? blueprint.groups.map((p) => `@${p.name}`)
129140
: undefined;
130141
const distro = process.env.IS_ON_PREMISE
131142
? await getHostDistro()
@@ -144,14 +155,19 @@ export const mapOnPremToHosted = async (
144155
}),
145156
),
146157
packages:
147-
packages !== undefined || groups !== undefined
148-
? [...(packages ? packages : []), ...(groups ? groups : [])]
158+
packages !== undefined || packageGroups !== undefined
159+
? [
160+
...(packages ? packages : []),
161+
...(packageGroups ? packageGroups : []),
162+
]
149163
: undefined,
150164
users:
151165
users !== undefined || user_keys !== undefined
152166
? [...(users ? users : []), ...(user_keys ? user_keys : [])]
153167
: undefined,
154-
groups: blueprint.customizations?.groups,
168+
// Support both 'groups' (hosted/current) and 'group' (on-prem/legacy) formats
169+
groups:
170+
blueprint.customizations?.groups || blueprint.customizations?.group,
155171
filesystem: blueprint.customizations?.filesystem?.map(
156172
({ minsize, size, ...fs }) => ({
157173
min_size: minsize || size,
@@ -207,12 +223,36 @@ export const mapHostedToOnPrem = (
207223
};
208224

209225
if (blueprint.customizations.packages) {
210-
result.packages = blueprint.customizations.packages.map((pkg) => {
211-
return {
212-
name: pkg,
213-
version: '*',
214-
};
226+
// Separate regular packages from package groups (those starting with @)
227+
const regularPackages: string[] = [];
228+
const packageGroups: string[] = [];
229+
230+
blueprint.customizations.packages.forEach((pkg) => {
231+
if (pkg.startsWith('@')) {
232+
// Package group (e.g., @development-tools) - remove @ prefix and add to groups
233+
packageGroups.push(pkg.substring(1));
234+
} else {
235+
// Regular package
236+
regularPackages.push(pkg);
237+
}
215238
});
239+
240+
// Map regular packages to packages array
241+
if (regularPackages.length > 0) {
242+
result.packages = regularPackages.map((pkg) => {
243+
return {
244+
name: pkg,
245+
version: '*',
246+
};
247+
});
248+
}
249+
250+
// Map package groups to blueprint.groups array
251+
if (packageGroups.length > 0) {
252+
result.groups = packageGroups.map((groupName) => ({
253+
name: groupName,
254+
}));
255+
}
216256
}
217257

218258
if (blueprint.customizations.containers) {
@@ -242,6 +282,10 @@ export const mapHostedToOnPrem = (
242282
result.customizations!.disk = blueprint.customizations.disk;
243283
}
244284

285+
if (blueprint.customizations.groups) {
286+
result.customizations!.group = blueprint.customizations.groups;
287+
}
288+
245289
if (blueprint.customizations.users) {
246290
result.customizations!.user = blueprint.customizations.users.map((u) => {
247291
return {

0 commit comments

Comments
 (0)