Skip to content

Commit

Permalink
Runtime: Add "sensitive" param to GetInstance (#4803)
Browse files Browse the repository at this point in the history
  • Loading branch information
begelundmuller authored May 2, 2024
1 parent b870a86 commit 3af894e
Show file tree
Hide file tree
Showing 14 changed files with 909 additions and 843 deletions.
5 changes: 4 additions & 1 deletion admin/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ func (s *Service) UpdateDeployment(ctx context.Context, depl *database.Deploymen
}
defer rt.Close()

res, err := rt.GetInstance(ctx, &runtimev1.GetInstanceRequest{InstanceId: depl.RuntimeInstanceID})
res, err := rt.GetInstance(ctx, &runtimev1.GetInstanceRequest{
InstanceId: depl.RuntimeInstanceID,
Sensitive: true,
})
if err != nil {
return err
}
Expand Down
1,642 changes: 826 additions & 816 deletions proto/gen/rill/runtime/v1/api.pb.go

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions proto/gen/rill/runtime/v1/api.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions proto/gen/rill/runtime/v1/api.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions proto/gen/rill/runtime/v1/runtime.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ paths:
in: path
required: true
type: string
- name: sensitive
in: query
required: false
type: boolean
tags:
- RuntimeService
post:
Expand Down
1 change: 1 addition & 0 deletions proto/rill/runtime/v1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ message ListInstancesResponse {
// Request message for RuntimeService.GetInstance
message GetInstanceRequest {
string instance_id = 1 [(validate.rules).string = {pattern: "^[_\\-a-zA-Z0-9]+$"}];
bool sensitive = 2;
}

// Response message for RuntimeService.GetInstance
Expand Down
6 changes: 5 additions & 1 deletion runtime/server/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (s *Server) GetInstance(ctx context.Context, req *runtimev1.GetInstanceRequ
}
}

if req.Sensitive && !sensitiveAccess {
return nil, status.Error(codes.PermissionDenied, "does not have permission to request sensitive instance information")
}

inst, err := s.runtime.Instance(ctx, req.InstanceId)
if err != nil {
if errors.Is(err, drivers.ErrNotFound) {
Expand All @@ -62,7 +66,7 @@ func (s *Server) GetInstance(ctx context.Context, req *runtimev1.GetInstanceRequ
}

return &runtimev1.GetInstanceResponse{
Instance: instanceToPB(inst, sensitiveAccess),
Instance: instanceToPB(inst, req.Sensitive),
}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import { addSourceModal } from "../sources/modal/add-source-visibility";
let steps: OnboardingStep[];
$: instance = createRuntimeServiceGetInstance($runtime.instanceId);
$: instance = createRuntimeServiceGetInstance($runtime.instanceId, {
sensitive: true,
});
$: olapConnector = $instance.data?.instance?.olapConnector;
$: if (olapConnector) {
steps = olapConnector === "duckdb" ? duckDbSteps : nonDuckDbSteps;
Expand Down
4 changes: 3 additions & 1 deletion web-common/src/features/tables/TableExplorer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
let showTables = true;
let sectionHeight = startingHeight;
$: instance = createRuntimeServiceGetInstance($runtime.instanceId);
$: instance = createRuntimeServiceGetInstance($runtime.instanceId, {
sensitive: true,
});
$: connectorInstanceId = $instance.data?.instance?.instanceId;
$: olapConnector = $instance.data?.instance?.olapConnector;
Expand Down
16 changes: 10 additions & 6 deletions web-common/src/features/tables/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import {
import { OLAP_DRIVERS_WITHOUT_MODELING } from "./olap-config";

export function useIsModelingSupportedForCurrentOlapDriver(instanceId: string) {
return createRuntimeServiceGetInstance(instanceId, {
query: {
select: (data) => {
const olapConnector = data.instance?.olapConnector as string;
return !OLAP_DRIVERS_WITHOUT_MODELING.includes(olapConnector);
return createRuntimeServiceGetInstance(
instanceId,
{ sensitive: true },
{
query: {
select: (data) => {
const olapConnector = data.instance?.olapConnector as string;
return !OLAP_DRIVERS_WITHOUT_MODELING.includes(olapConnector);
},
},
},
});
);
}

export function useTables(
Expand Down
4 changes: 3 additions & 1 deletion web-common/src/features/welcome/WelcomePageRedirect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
async function handleUninitializedProject() {
// If the project is not initialized, determine what page to route to dependent on the OLAP connector
const instance = await runtimeServiceGetInstance($runtime.instanceId);
const instance = await runtimeServiceGetInstance($runtime.instanceId, {
sensitive: true,
});
const olapConnector = instance.instance?.olapConnector;
if (!olapConnector) {
throw new Error("OLAP connector is not defined");
Expand Down
6 changes: 6 additions & 0 deletions web-common/src/proto/gen/rill/runtime/v1/api_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ export class GetInstanceRequest extends Message<GetInstanceRequest> {
*/
instanceId = "";

/**
* @generated from field: bool sensitive = 2;
*/
sensitive = false;

constructor(data?: PartialMessage<GetInstanceRequest>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -486,6 +491,7 @@ export class GetInstanceRequest extends Message<GetInstanceRequest> {
static readonly typeName = "rill.runtime.v1.GetInstanceRequest";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "instance_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "sensitive", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): GetInstanceRequest {
Expand Down
24 changes: 13 additions & 11 deletions web-common/src/runtime-client/gen/index.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ export type QueryServiceColumnCardinalityParams = {
priority?: number;
};

export type RuntimeServiceWatchLogs200 = {
result?: V1WatchLogsResponse;
error?: RpcStatus;
};

export type RuntimeServiceWatchLogsLevel =
(typeof RuntimeServiceWatchLogsLevel)[keyof typeof RuntimeServiceWatchLogsLevel];

Expand Down Expand Up @@ -430,6 +435,8 @@ export type RuntimeServiceEditInstanceBody = {

export type RuntimeServiceDeleteInstanceBody = { [key: string]: any };

export type RuntimeServiceGetInstanceParams = { sensitive?: boolean };

export type RuntimeServiceListInstancesParams = {
pageSize?: number;
pageToken?: string;
Expand Down Expand Up @@ -498,11 +505,6 @@ export interface V1WatchLogsResponse {
log?: V1Log;
}

export type RuntimeServiceWatchLogs200 = {
result?: V1WatchLogsResponse;
error?: RpcStatus;
};

export interface V1WatchFilesResponse {
event?: V1FileEvent;
path?: string;
Expand All @@ -529,12 +531,6 @@ export interface V1TimeSeriesValue {
records?: V1TimeSeriesValueRecords;
}

export interface V1TimeSeriesTimeRange {
start?: string;
end?: string;
interval?: V1TimeGrain;
}

export interface V1TimeSeriesResponse {
results?: V1TimeSeriesValue[];
spark?: V1TimeSeriesValue[];
Expand Down Expand Up @@ -563,6 +559,12 @@ export const V1TimeGrain = {
TIME_GRAIN_YEAR: "TIME_GRAIN_YEAR",
} as const;

export interface V1TimeSeriesTimeRange {
start?: string;
end?: string;
interval?: V1TimeGrain;
}

export interface V1TimeRange {
start?: string;
end?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
V1CreateInstanceResponse,
V1CreateInstanceRequest,
V1GetInstanceResponse,
RuntimeServiceGetInstanceParams,
V1DeleteInstanceResponse,
RuntimeServiceDeleteInstanceBody,
V1EditInstanceResponse,
Expand Down Expand Up @@ -351,18 +352,21 @@ export const createRuntimeServiceCreateInstance = <
*/
export const runtimeServiceGetInstance = (
instanceId: string,
params?: RuntimeServiceGetInstanceParams,
signal?: AbortSignal,
) => {
return httpClient<V1GetInstanceResponse>({
url: `/v1/instances/${instanceId}`,
method: "get",
params,
signal,
});
};

export const getRuntimeServiceGetInstanceQueryKey = (instanceId: string) => [
`/v1/instances/${instanceId}`,
];
export const getRuntimeServiceGetInstanceQueryKey = (
instanceId: string,
params?: RuntimeServiceGetInstanceParams,
) => [`/v1/instances/${instanceId}`, ...(params ? [params] : [])];

export type RuntimeServiceGetInstanceQueryResult = NonNullable<
Awaited<ReturnType<typeof runtimeServiceGetInstance>>
Expand All @@ -374,6 +378,7 @@ export const createRuntimeServiceGetInstance = <
TError = ErrorType<RpcStatus>,
>(
instanceId: string,
params?: RuntimeServiceGetInstanceParams,
options?: {
query?: CreateQueryOptions<
Awaited<ReturnType<typeof runtimeServiceGetInstance>>,
Expand All @@ -385,11 +390,12 @@ export const createRuntimeServiceGetInstance = <
const { query: queryOptions } = options ?? {};

const queryKey =
queryOptions?.queryKey ?? getRuntimeServiceGetInstanceQueryKey(instanceId);
queryOptions?.queryKey ??
getRuntimeServiceGetInstanceQueryKey(instanceId, params);

const queryFn: QueryFunction<
Awaited<ReturnType<typeof runtimeServiceGetInstance>>
> = ({ signal }) => runtimeServiceGetInstance(instanceId, signal);
> = ({ signal }) => runtimeServiceGetInstance(instanceId, params, signal);

const query = createQuery<
Awaited<ReturnType<typeof runtimeServiceGetInstance>>,
Expand Down

1 comment on commit 3af894e

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.