Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Policy Protobufs #268

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@ format license-check lint test: ci

doc:
cd lib && npm run doc

toolcheck:
@echo "Checking for required tools..."
@which buf > /dev/null || (echo "buf not found, please install it from https://docs.buf.build/installation" && exit 1)
@which protoc-gen-grpc-gateway-ts > /dev/null || (echo "protoc-gen-grpc-gateway-ts not found, run 'go install github.com/grpc-ecosystem/[email protected]'" && exit 1)
@golangci-lint --version | grep "version v\?1.5[67]" > /dev/null || (echo "golangci-lint version must be v1.55 [$$(golangci-lint --version)]" && exit 1)

proto-generate:
rm -rf lib/proto
buf generate https://github.com/opentdf/platform.git\#branch\=main,subdir\=service

7 changes: 7 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: v1
managed:
enabled: false
plugins:
- plugin: grpc-gateway-ts
out: lib/proto
strategy: all
1 change: 1 addition & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ overrides:
- '*.spec.ts'
rules:
'@typescript-eslint/ban-ts-comment': 'off'
ignores: ['lib/proto/**/*.ts']
parserOptions:
project: ['**/tsconfig.json']
root: true
93 changes: 93 additions & 0 deletions lib/proto/authorization/authorization.pb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* eslint-disable */
// @ts-nocheck
/*
* This file is a generated Typescript file for GRPC Gateway, DO NOT MODIFY
*/

import * as fm from "../fetch.pb"
import * as GoogleProtobufAny from "../google/protobuf/any.pb"
import * as PolicyObjects from "../policy/objects.pb"

type Absent<T, K extends keyof T> = { [k in Exclude<keyof T, K>]?: undefined };
type OneOf<T> =
| { [k in keyof T]?: undefined }
| (
keyof T extends infer K ?
(K extends string & keyof T ? { [k in K]: T[K] } & Absent<T, K>
: never)
: never);

export enum DecisionResponseDecision {
DECISION_UNSPECIFIED = "DECISION_UNSPECIFIED",
DECISION_DENY = "DECISION_DENY",
DECISION_PERMIT = "DECISION_PERMIT",
}


type BaseEntity = {
id?: string
}

export type Entity = BaseEntity
& OneOf<{ emailAddress: string; userName: string; remoteClaimsUrl: string; jwt: string; claims: GoogleProtobufAny.Any; custom: EntityCustom; clientId: string }>

export type EntityCustom = {
extension?: GoogleProtobufAny.Any
}

export type EntityChain = {
id?: string
entities?: Entity[]
}

export type DecisionRequest = {
actions?: PolicyObjects.Action[]
entityChains?: EntityChain[]
resourceAttributes?: ResourceAttribute[]
}

export type DecisionResponse = {
entityChainId?: string
resourceAttributesId?: string
action?: PolicyObjects.Action
decision?: DecisionResponseDecision
obligations?: string[]
}

export type GetDecisionsRequest = {
decisionRequests?: DecisionRequest[]
}

export type GetDecisionsResponse = {
decisionResponses?: DecisionResponse[]
}


type BaseGetEntitlementsRequest = {
entities?: Entity[]
}

export type GetEntitlementsRequest = BaseGetEntitlementsRequest
& OneOf<{ scope: ResourceAttribute }>

export type EntityEntitlements = {
entityId?: string
Copy link
Author

Choose a reason for hiding this comment

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

Unfortunately, it seems that this package marks every field as optional when generating code.

There is a very old / stale issue on this which doesn't appear to have any progress in the last two years: grpc-ecosystem/protoc-gen-grpc-gateway-ts#26

Is this a dealbreaker for us using protoc-gen-grpc-gateway-ts @strantalis?

Copy link
Author

Choose a reason for hiding this comment

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

Also getting the following error message when building the protos:

Warning: plugin "grpc-gateway-ts" does not support required features.
  Feature "proto3 optional" is required by 1 file(s):
    authorization/authorization.proto

Pretty new to all this protobuf stuff so wondering if this is something that's easily fixed by adding another plugin? Or is it more complicated than that

Copy link
Member

Choose a reason for hiding this comment

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

I'm kinda surprised optional is a feature of proto3. I've been outta the loop. https://stackoverflow.com/a/62566052/23894185

attributeValueFqns?: string[]
}

export type ResourceAttribute = {
attributeValueFqns?: string[]
}

export type GetEntitlementsResponse = {
entitlements?: EntityEntitlements[]
}

export class AuthorizationService {
static GetDecisions(req: GetDecisionsRequest, initReq?: fm.InitReq): Promise<GetDecisionsResponse> {
return fm.fetchReq<GetDecisionsRequest, GetDecisionsResponse>(`/v1/authorization`, {...initReq, method: "POST"})
}
static GetEntitlements(req: GetEntitlementsRequest, initReq?: fm.InitReq): Promise<GetEntitlementsResponse> {
return fm.fetchReq<GetEntitlementsRequest, GetEntitlementsResponse>(`/v1/entitlements`, {...initReq, method: "POST"})
}
}
32 changes: 32 additions & 0 deletions lib/proto/authorization/idp_plugin.pb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable */
// @ts-nocheck
/*
* This file is a generated Typescript file for GRPC Gateway, DO NOT MODIFY
*/

import * as GoogleProtobufAny from "../google/protobuf/any.pb"
import * as GoogleProtobufStruct from "../google/protobuf/struct.pb"
import * as AuthorizationAuthorization from "./authorization.pb"
export type IdpConfig = {
config?: GoogleProtobufStruct.Struct
}

export type IdpPluginRequest = {
entities?: AuthorizationAuthorization.Entity[]
}

export type IdpEntityRepresentation = {
additionalProps?: GoogleProtobufStruct.Struct[]
originalId?: string
}

export type IdpPluginResponse = {
entityRepresentations?: IdpEntityRepresentation[]
}

export type EntityNotFoundError = {
code?: number
message?: string
details?: GoogleProtobufAny.Any[]
entity?: string
}
30 changes: 30 additions & 0 deletions lib/proto/common/common.pb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint-disable */
// @ts-nocheck
/*
* This file is a generated Typescript file for GRPC Gateway, DO NOT MODIFY
*/

import * as GoogleProtobufTimestamp from "../google/protobuf/timestamp.pb"

export enum MetadataUpdateEnum {
METADATA_UPDATE_ENUM_UNSPECIFIED = "METADATA_UPDATE_ENUM_UNSPECIFIED",
METADATA_UPDATE_ENUM_EXTEND = "METADATA_UPDATE_ENUM_EXTEND",
METADATA_UPDATE_ENUM_REPLACE = "METADATA_UPDATE_ENUM_REPLACE",
}

export enum ActiveStateEnum {
ACTIVE_STATE_ENUM_UNSPECIFIED = "ACTIVE_STATE_ENUM_UNSPECIFIED",
ACTIVE_STATE_ENUM_ACTIVE = "ACTIVE_STATE_ENUM_ACTIVE",
ACTIVE_STATE_ENUM_INACTIVE = "ACTIVE_STATE_ENUM_INACTIVE",
ACTIVE_STATE_ENUM_ANY = "ACTIVE_STATE_ENUM_ANY",
}

export type Metadata = {
createdAt?: GoogleProtobufTimestamp.Timestamp
updatedAt?: GoogleProtobufTimestamp.Timestamp
labels?: {[key: string]: string}
}

export type MetadataMutable = {
labels?: {[key: string]: string}
}
Loading
Loading