This commit is contained in:
dal 2025-09-26 15:04:45 -06:00
parent 6d0a8962b5
commit 310c7362e7
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
8 changed files with 37 additions and 20 deletions

View File

@ -101,7 +101,9 @@ export function Auth({ apiKey, host, local, cloud, clear, noSave, show }: AuthPr
} else if (!isTTY) {
// Non-TTY environment - require API key from flags or env
console.error('❌ Non-interactive environment detected.');
console.error(' Please provide API key via --api-key flag or BUSTER_API_KEY environment variable.');
console.error(
' Please provide API key via --api-key flag or BUSTER_API_KEY environment variable.'
);
exit();
} else if (initialHost || host) {
// If we only have host, set it and prompt for API key

View File

@ -75,7 +75,9 @@ program
// In CI environments, we need to handle auth differently
if (isCIEnvironment && !options.apiKey && !process.env.BUSTER_API_KEY) {
console.error('❌ Non-interactive environment detected.');
console.error(' Please provide API key via --api-key flag or BUSTER_API_KEY environment variable.');
console.error(
' Please provide API key via --api-key flag or BUSTER_API_KEY environment variable.'
);
console.error(' Example: buster auth --api-key YOUR_API_KEY');
console.error(' Or set: export BUSTER_API_KEY=YOUR_API_KEY');
process.exit(1);
@ -87,7 +89,13 @@ program
const { saveCredentials } = await import('./utils/credentials');
const apiKey = options.apiKey || process.env.BUSTER_API_KEY;
const host = options.host || (options.local ? 'http://localhost:3001' : (options.cloud ? 'https://api2.buster.so' : 'https://api2.buster.so'));
const host =
options.host ||
(options.local
? 'http://localhost:3001'
: options.cloud
? 'https://api2.buster.so'
: 'https://api2.buster.so');
const normalizedHost = host.startsWith('http') ? host : `https://${host}`;
try {
@ -105,7 +113,9 @@ program
await saveCredentials({ apiKey, apiUrl: normalizedHost });
console.log('✅ Authentication successful and credentials saved.');
} else {
console.log('✅ Authentication successful (credentials not saved due to --no-save flag).');
console.log(
'✅ Authentication successful (credentials not saved due to --no-save flag).'
);
}
process.exit(0);
} else {

View File

@ -17,9 +17,9 @@ import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { HTTPException } from 'hono/http-exception';
import yaml from 'js-yaml';
import { throwUnauthorizedError } from '../../../../shared-helpers/asset-public-access';
import { getPubliclyEnabledByUser } from '../../../../shared-helpers/get-publicly-enabled-by-user';
import { getMetricsInAncestorAssetFromMetricIds } from '../../../../shared-helpers/metric-helpers';
import { throwUnauthorizedError } from '../../../../shared-helpers/asset-public-access';
interface GetDashboardHandlerParams {
dashboardId: string;

View File

@ -8,9 +8,9 @@ import {
import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { HTTPException } from 'hono/http-exception';
import { throwUnauthorizedError } from '../../../../shared-helpers/asset-public-access';
import { getMetricsInAncestorAssetFromMetricIds } from '../../../../shared-helpers/metric-helpers';
import { standardErrorHandler } from '../../../../utils/response';
import { throwUnauthorizedError } from '../../../../shared-helpers/asset-public-access';
export async function getReportHandler(
reportId: string,

View File

@ -59,7 +59,6 @@ export const ThrowUnauthorizedErrorSchema = z.object({
export type ThrowUnauthorizedErrorParams = z.infer<typeof ThrowUnauthorizedErrorSchema>;
// Decides the appropriate error to throw based on the public access settings
export function throwUnauthorizedError(params: ThrowUnauthorizedErrorParams): never {
const { publiclyAccessible, publicExpiryDate, publicPassword, userSuppliedPassword } = params;

View File

@ -19,8 +19,8 @@ import type { AssetPermissionRole, VerificationStatus } from '@buster/server-sha
import { HTTPException } from 'hono/http-exception';
import yaml from 'js-yaml';
import { z } from 'zod';
import { getPubliclyEnabledByUser } from './get-publicly-enabled-by-user';
import { throwUnauthorizedError } from './asset-public-access';
import { getPubliclyEnabledByUser } from './get-publicly-enabled-by-user';
export const MetricAccessOptionsSchema = z.object({
/** If public access has been verified by a parent resource set to true */

View File

@ -48,7 +48,13 @@ export async function checkPermission(check: AssetPermissionCheck): Promise<Asse
} = check;
// Check cache first (only for single role checks)
const cached = getCachedPermission(userId, assetId, assetType, requiredRole, userSuppliedPassword);
const cached = getCachedPermission(
userId,
assetId,
assetType,
requiredRole,
userSuppliedPassword
);
if (cached !== undefined) {
return cached;
}