Skip to content

Commit

Permalink
by default fill in uid and gid
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Drage <[email protected]>
  • Loading branch information
cdrage committed Aug 6, 2024
1 parent 4807e5b commit 0fd1a0c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/backend/src/api-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { History } from './history';
import * as containerUtils from './container-utils';
import { Messages } from '/@shared/src/messages/Messages';
import { telemetryLogger } from './extension';
import { checkPrereqs, isLinux } from './machine-utils';
import { checkPrereqs, isLinux, getUidGid } from './machine-utils';

export class BootcApiImpl implements BootcApi {
private history: History;
Expand Down Expand Up @@ -244,6 +244,10 @@ export class BootcApiImpl implements BootcApi {
return isLinux();
}

async getUidGid(): Promise<string> {
return getUidGid();
}

// The API does not allow callbacks through the RPC, so instead
// we send "notify" messages to the frontend to trigger a refresh
// this method is internal and meant to be used by the API implementation
Expand Down
9 changes: 9 additions & 0 deletions packages/backend/src/machine-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,12 @@ const linux = os.platform() === 'linux';
export function isLinux(): boolean {
return linux;
}

// Get the GID and UID of the current user and return in the format gid:uid
// in order for this to work, we must get this information from process.exec
// since there is no native way via node
export async function getUidGid(): Promise<string> {
const { stdout: uidOutput } = await extensionApi.process.exec('id', ['-u']);
const { stdout: gidOutput } = await extensionApi.process.exec('id', ['-g']);
return `${uidOutput.trim()}:${gidOutput.trim()}`;
}
20 changes: 18 additions & 2 deletions packages/frontend/src/Build.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ async function fillArchitectures(historyInfo: BootcBuildInfo[]) {
}
}
// This will fill the chown function by getting the user and group ID from the OS
// and filling in the information in the chown input field.
async function fillChownOption() {
try {
const gidUid = await bootcClient.getUidGid();
buildChown = gidUid;
} catch (error) {
console.error('Error getting UID and GID:', error);
}
}
async function validate() {
let prereqs = await bootcClient.checkPrereqs();
if (prereqs) {
Expand Down Expand Up @@ -293,6 +304,10 @@ onMount(async () => {
await fillBuildOptions(historyInfo);
await fillArchitectures(historyInfo);
if (isLinux) {
await fillChownOption();
}
validate();
});
Expand Down Expand Up @@ -701,12 +716,13 @@ export function goToHomePage(): void {
name="chown"
id="chown"
bind:value={buildChown}
placeholder="GID and UID parameters (ex. 1000:1000)"
placeholder="UID and GID parameters (ex. 1000:1000)"
class="w-full"
aria-label="chown-select" />
</div>
<p class="text-sm text-[var(--pd-content-text)] pt-2">
This option allows you to change the owner and group of the files in the output directory.
Linux only. By default the UID and GID of the current user is used. This option allows you to
change the owner and group of the files in the output directory.
</p>
</div>
{/if}
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/BootcAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export abstract class BootcApi {
abstract generateUniqueBuildID(name: string): Promise<string>;
abstract openLink(link: string): Promise<void>;
abstract isLinux(): Promise<boolean>;
abstract getUidGid(): Promise<string>;
abstract telemetryLogUsage(eventName: string, data?: Record<string, unknown> | undefined): Promise<void>;
abstract telemetryLogError(eventName: string, data?: Record<string, unknown> | undefined): Promise<void>;
}

0 comments on commit 0fd1a0c

Please sign in to comment.