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

Refactor domain, entity, and action shared types #113

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion .env.default

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/authz_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
shell: bash
run: |
make authz/copy-default-env
make authz/db/generate-types

- name: Test types
shell: bash
Expand Down
34 changes: 0 additions & 34 deletions apps/authz/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ authz/start/dev:
authz/setup:
make authz/copy-default-env
make authz/rego/compile
make authz/db/setup
make authz/test/db/setup

authz/copy-default-env:
cp ${AUTHZ_PROJECT_DIR}/.env.default ${AUTHZ_PROJECT_DIR}/.env
Expand All @@ -33,41 +31,9 @@ authz/format/check:
authz/lint/check:
npx nx lint ${AUTHZ_PROJECT_NAME}

# === Database ===

authz/db/generate-types:
npx prisma generate \
--schema ${AUTHZ_DATABASE_SCHEMA}

authz/db/migrate:
npx dotenv -e ${AUTHZ_PROJECT_DIR}/.env -- \
prisma migrate dev \
--schema ${AUTHZ_DATABASE_SCHEMA}

authz/db/setup:
@echo ""
@echo "${TERM_GREEN}🛠️ Setting up Authz development database${TERM_NO_COLOR}"
@echo ""
npx dotenv -e ${AUTHZ_PROJECT_DIR}/.env -- \
prisma migrate reset \
--schema ${AUTHZ_DATABASE_SCHEMA} \
--force

@echo ""
@echo "${TERM_GREEN}🛠️ Setting up Authz test database${TERM_NO_COLOR}"
@echo ""
make authz/test/db/setup

authz/db/create-migration:
npx dotenv -e ${AUTHZ_PROJECT_DIR}/.env -- \
prisma migrate dev \
--schema ${AUTHZ_DATABASE_SCHEMA} \
--name ${NAME}

# === Testing ===

authz/test/type:
make authz/db/generate-types
npx tsc \
--project ${AUTHZ_PROJECT_DIR}/tsconfig.app.json \
--noEmit
Expand Down
2 changes: 0 additions & 2 deletions apps/authz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ TBD
## Getting started

```bash
# Boot PostgreSQL and Redis
make docker/up
make authz/setup
```

Expand Down
4 changes: 1 addition & 3 deletions apps/authz/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { HttpModule } from '@nestjs/axios'
import { Module, ValidationPipe } from '@nestjs/common'
import { ConfigModule } from '@nestjs/config'
import { APP_PIPE } from '@nestjs/core'
import { PersistenceModule } from '../shared/module/persistence/persistence.module'
import { load } from './app.config'
import { AppController } from './app.controller'
import { AppService } from './app.service'
Expand All @@ -17,8 +16,7 @@ import { EntityRepository } from './persistence/repository/entity.repository'
load: [load],
isGlobal: true
}),
HttpModule,
PersistenceModule
HttpModule
],
controllers: [AppController, AdminController],
providers: [
Expand Down
10 changes: 5 additions & 5 deletions apps/authz/src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
Action,
Alg,
AuthCredential,
CredentialEntity,
Decision,
EvaluationRequest,
EvaluationResponse,
Expand Down Expand Up @@ -70,7 +70,7 @@ export const finalizeDecision = (response: OpaResult[]) => {
export class AppService {
constructor(private opaService: OpaService, private entityRepository: EntityRepository) {}

async #verifySignature(requestSignature: Signature, verificationMessage: string): Promise<AuthCredential> {
async #verifySignature(requestSignature: Signature, verificationMessage: string): Promise<CredentialEntity> {
const { pubKey, alg, sig } = requestSignature
const credential = this.entityRepository.getCredentialForPubKey(pubKey)

Expand Down Expand Up @@ -103,7 +103,7 @@ export class AppService {
async #populateApprovals(
approvals: Signature[] | undefined,
verificationMessage: string
): Promise<AuthCredential[] | null> {
): Promise<CredentialEntity[] | null> {
if (!approvals) return null
const approvalSigs = await Promise.all(
approvals.map(async ({ sig, alg, pubKey }) => {
Expand All @@ -121,9 +121,9 @@ export class AppService {
intent,
transfers
}: {
principal: AuthCredential
principal: CredentialEntity
request: Request
approvals: AuthCredential[] | null
approvals: CredentialEntity[] | null
intent?: Intent
transfers?: HistoricalTransfer[]
}): RegoInput {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AuthCredential, Entities } from '@narval/authz-shared'
import { CredentialEntity, Entities } from '@narval/authz-shared'
import { HttpService } from '@nestjs/axios'
import { Injectable, Logger, OnApplicationBootstrap } from '@nestjs/common'
import { ORGANIZATION } from 'packages/authz-shared/src/lib/dev.fixture'
Expand Down Expand Up @@ -31,7 +31,7 @@ export class EntityRepository implements OnApplicationBootstrap {
)
}

getCredentialForPubKey(pubKey: string): AuthCredential | null {
getCredentialForPubKey(pubKey: string): CredentialEntity | null {
if (this.entities) {
return this.entities.credentials.find((cred) => cred.pubKey === pubKey) || null
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

98 changes: 0 additions & 98 deletions apps/authz/src/shared/module/persistence/schema/schema.prisma

This file was deleted.

This file was deleted.

Loading
Loading