Skip to content

Commit

Permalink
Merge pull request #2 from closetool/master
Browse files Browse the repository at this point in the history
feat: add implementation of Adapter
  • Loading branch information
hsluoyz authored May 11, 2021
2 parents 302dcc6 + 002bae7 commit ae395b1
Show file tree
Hide file tree
Showing 32 changed files with 6,357 additions and 1 deletion.
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Go

on: [push, pull_request]

jobs:

test:
runs-on: ubuntu-latest

services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: casbin
ports:
- 3306:3306
postgres:
image: postgres:10.16
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: casbin
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14

- uses: actions/checkout@v2
- name: Run Unit tests
run: go test -v -coverprofile=./profile.cov ./...

semantic-release:
needs: [test]
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v2

- name: Run semantic-release
if: github.repository == 'casbin/ent-adapter' && github.event_name == 'push'
run: |
npm install --save-dev [email protected]
npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
.idea/
.vscode/

# Dependency directories (remove the comment below to include it)
# vendor/
16 changes: 16 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"debug": true,
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"master",
{
"name": "beta",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/github"
]
}
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
# ent-adapter
Ent-Adapter
===
[![Go Report Card](https://goreportcard.com/badge/github.com/casbin/gorm-adapter)](https://goreportcard.com/report/github.com/casbin/ent-adapter)
[![Go](https://github.com/casbin/ent-adapter/actions/workflows/ci.yml/badge.svg)](https://github.com/casbin/ent-adapter/actions/workflows/ci.yml)
[![Coverage Status](https://coveralls.io/repos/github/casbin/ent-adapter/badge.svg?branch=master)](https://coveralls.io/github/casbin/ent-adapter?branch=master)

Ent Adapter is the [ent](https://github.com/ent/ent) adapter for [Casbin](https://github.com/casbin/casbin). With this library, Casbin can load policy from PostgresSQL/Mysql or save policy to it.

## Installation

go get github.com/casbin/ent-adapter


## Usage

```go
a, err := NewAdapter("mysql", "root:@tcp(127.0.0.1:3306)/casbin")
//a, err := NewAdapter("postgres", "user=postgres password=postgres host=127.0.0.1 port=5432 dbname=casbin")
if err != nil {
panic(err)
}
e, err := casbin.NewEnforcer("/path/to/model",a)
```

## Notification

The database used in adapter(like casbin) should be created manually before NewAdapter calling.

## Getting Help

- [Casbin](https://github.com/casbin/casbin)

## License

This project is under Apache 2.0 License. See the [LICENSE](LICENSE) file for the full license text.
Loading

0 comments on commit ae395b1

Please sign in to comment.