Skip to content

Commit

Permalink
run pre-commit hooks
Browse files Browse the repository at this point in the history
Signed-off-by: Sarah Funkhouser <[email protected]>
  • Loading branch information
golanglemonade committed Jan 4, 2025
1 parent 7d5b328 commit ee79b4e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 34 deletions.
7 changes: 3 additions & 4 deletions docs/docs/docs/developers/ent/ent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar_position: 1
# Schema Driven Development with Ent

[Ent](https://entgo.io/docs/getting-started) is a powerful, Go-based entity framework that emphasizes schema-driven development.
This approach allows developers to define the structure and relationships of their data in a centralized schema,
This approach allows developers to define the structure and relationships of their data in a centralized schema,
written in Go code, which then generates all the necessary boilerplate for database interactions.

## Key Features
Expand All @@ -29,7 +29,7 @@ Workflow of generating a new schema and related CRUD resolvers
The file will be located in `internal/ent/schema/`, the file name matching the schema name
1. Add [Fields](https://entgo.io/docs/schema-fields) to the schema
1. Add [Edges](https://entgo.io/docs/schema-edges) to the schema for 1:1, 1:m, or m:m relationships with other objects
1. Add [Indexes](https://entgo.io/docs/schema-indexes) to the schema. A common use in our codebase is to add an index to allow soft-deleted names to be reused even when the name is required to be unique.
1. Add [Indexes](https://entgo.io/docs/schema-indexes) to the schema. A common use in our codebase is to add an index to allow soft-deleted names to be reused even when the name is required to be unique.
```go
index.Fields("name").
Unique().Annotations(entsql.IndexWhere("deleted_at is NULL")),
Expand All @@ -49,7 +49,7 @@ Workflow of generating a new schema and related CRUD resolvers
1. **gqlgen** - graphapi resolvers and basic query generation
1. **gqlgenc** - golang api client based on queries

### Generate the Migrations
### Generate the Migrations
This will generate the goose and atlas migrations based on the ent schema changes
```bash
task db:create
Expand All @@ -59,4 +59,3 @@ Workflow of generating a new schema and related CRUD resolvers
task cli:generate
```
The cli flags for create and update, along with field output (in `root.go`) will need to be manually updated

4 changes: 2 additions & 2 deletions docs/docs/docs/developers/structure/helpers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ csv file upload input.
### SearchGen

Creates search resolvers to search on fields within the ent schema. Fields in the schema
that should be searchable by non-admins should include the annotation:
that should be searchable by non-admins should include the annotation:

```go
Annotations(
Expand All @@ -59,7 +59,7 @@ A helper package for working with [ent](https://entgo.io/), which includes the f
- Soft-delete extension with cascade delete functionality added in
- enthistory extension for generating history tables using ent - the plugin will add-on to your existing `entc` usage and enumerate over your current schemas to create new "history" schemas containing an inventory of the changes related to the existing tables.

## iam
## iam

:::note[Repository]
https://github.com/theopenlane/iam
Expand Down
56 changes: 28 additions & 28 deletions docs/docs/docs/developers/structure/structure.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ sidebar_position: 1

# Project Structure - Core

[Core](https://github.com/theopenlane/core) is the main server for Openlane and where the majority of the backend code and business logic is
located for the API.
[Core](https://github.com/theopenlane/core) is the main server for Openlane and where the majority of the backend code and business logic is
located for the API.

## cmd

Expand All @@ -22,20 +22,20 @@ the `serve` command is what is being used

### cli

Located in `cmd/cli/cmd` this directory includes all the CRUD operations for the openlane cli. As these follow a pretty similar pattern throughout
all objects, there is a template that allows these files to be generated and only requires the input and output fields to be updated.
Located in `cmd/cli/cmd` this directory includes all the CRUD operations for the openlane cli. As these follow a pretty similar pattern throughout
all objects, there is a template that allows these files to be generated and only requires the input and output fields to be updated.

## config

Located in `config/` this directory contains the generated config and example settings powered by [koanf](https://github.com/knadh/koanf).
Located in `config/` this directory contains the generated config and example settings powered by [koanf](https://github.com/knadh/koanf).

## internal
## internal

The meat of the repo, if you are looking for something, it's probably in this directory somewhere. Everything in the `internal` directory is intended to only be used by packages within this repository, outside usage will be blocked by the go-compiler.

### ent

Located in `internal/ent` this directory contains all the code related to the schemas.
Located in `internal/ent` this directory contains all the code related to the schemas.

```
├── internal
Expand All @@ -50,9 +50,9 @@ Located in `internal/ent` this directory contains all the code related to the sc
│   │   └── validator
```

#### generated
#### generated

All code generated by `entc` is in this directory and should not be edited manually as changes will be overwritten on the next run of `task generate`.
All code generated by `entc` is in this directory and should not be edited manually as changes will be overwritten on the next run of `task generate`.

#### hooks

Expand Down Expand Up @@ -82,17 +82,17 @@ For more information, refer to the upstream [docs](https://entgo.io/docs/hooks/)

#### interceptors

This contains all `interceptors` written to change the behavior of a query. These are similar to hooks, but instead of acting on a mutation, it acts on a query.
This contains all `interceptors` written to change the behavior of a query. These are similar to hooks, but instead of acting on a mutation, it acts on a query.

`Traverse` functions occur before the query is executed
`Interceptor` functions occur after the query is executed
`Interceptor` functions occur after the query is executed

We commonly use these to filter data the user has access to, or log information such as query timing
We commonly use these to filter data the user has access to, or log information such as query timing

For more information, refer to the upstream [docs](https://entgo.io/docs/interceptors)


#### privacy
#### privacy

This includes privacy policies, this is used in conjunction with our FGA implementation

Expand All @@ -105,15 +105,15 @@ This include all schemas for the database. When generating a new schema, refer t
#### mixin

Mixins are common fields and functions that are used on multiple schemas, for example, the `SoftDeleteMixin` is used on all schemas as we want to use soft-deletes
across all our database tables.
across all our database tables.

:::note
not **all** mixins are here. Due to import cycles, some are located within the `schema` directory. Others, because they are not unique to this repository are located within the [entx](https://github.com/theopenlane/entx/tree/main/mixin) repository
:::
:::

### graphapi
### graphapi

Located in `internal/graphapi` this directory contains all the code related to graphapi resolvers. The `*.resolvers.go` files contain the business logic of the
Located in `internal/graphapi` this directory contains all the code related to graphapi resolvers. The `*.resolvers.go` files contain the business logic of the
resolvers. These are generated based on the schema and a template, but the generated should be reviewed and updated as needed depending on the use case.

All graphapi resolvers require authentication, this is handled by the auth middleware and requires no updates to the resolvers themselves.
Expand All @@ -136,8 +136,8 @@ The `internal/graphapi/query` directory contains queries and mutations used to g

### httpserve

Located in `internal/httpserve` this directory contains the main http server and configuration as well as the `REST` api handlers and routes. Although the
majority of the openlane API is a graphapi, there are several `REST` routes such as `login`, `password-reset`, etc.
Located in `internal/httpserve` this directory contains the main http server and configuration as well as the `REST` api handlers and routes. Although the
majority of the openlane API is a graphapi, there are several `REST` routes such as `login`, `password-reset`, etc.

```
├── internal
Expand All @@ -153,7 +153,7 @@ majority of the openlane API is a graphapi, there are several `REST` routes such
### handlers

This directory contains the `REST` api handlers. The general use-case should not require a REST endpoint, however, there are several cases where REST handlers have
been implemented such as for `login`. Handlers should all follow the same pattern of created a Handler and a BindHandler, for openAPI specs.
been implemented such as for `login`. Handlers should all follow the same pattern of created a Handler and a BindHandler, for openAPI specs.

```go
func (h *Handler) ExampleHandler(ctx echo.Context) error {
Expand All @@ -168,11 +168,11 @@ func (h *Handler) ExampleHandler(ctx echo.Context) error {
return h.InvalidInput(ctx, err)
}

//
//
// ... do some stuff ...
//
//



// return the response
out := models.ExampleReply{
Reply: rout.Reply{Success: true},
Expand Down Expand Up @@ -235,8 +235,8 @@ The default middleware (`mw`) is an unauthenticated route. If the REST endpoint

### middleware

The `pkg/middleware` contains many commonly used `middleware` used in this repository. These may move to internal if they are dependent on the schema,
or to another repo at some point in the future.
The `pkg/middleware` contains many commonly used `middleware` used in this repository. These may move to internal if they are dependent on the schema,
or to another repo at some point in the future.

```
├── pkg
Expand All @@ -255,9 +255,9 @@ or to another repo at some point in the future.

### models

Located in `pkg/models` this includes all the model information for the `REST` api input and output. This is used to generate our openAPI specs.
Located in `pkg/models` this includes all the model information for the `REST` api input and output. This is used to generate our openAPI specs.

### openlaneclient

Located in `pkg/openlaneclient` this includes the generated golang API client used to interact with the API. The queries added to `internal/graphapi/query`
are used as input to `gqlgenc` for the graphclient. The restclient is manually maintained.
Located in `pkg/openlaneclient` this includes the generated golang API client used to interact with the API. The queries added to `internal/graphapi/query`
are used as input to `gqlgenc` for the graphclient. The restclient is manually maintained.

0 comments on commit ee79b4e

Please sign in to comment.