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

Fixed linting issues #28

Merged
merged 5 commits into from
Nov 3, 2022
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
29 changes: 29 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.go]
indent_style = tab
indent_size = 4
ij_continuation_indent_size = 4
ij_go_GROUP_CURRENT_PROJECT_IMPORTS = true
ij_go_add_parentheses_for_single_import = true
ij_go_group_stdlib_imports = true
ij_go_import_sorting = gofmt
ij_go_local_group_mode = project
ij_go_move_all_imports_in_one_declaration = true
ij_go_move_all_stdlib_imports_in_one_group = true

[go.mod]
indent_style = tab
indent_size = 4

[Makefile]
indent_style = tab
indent_size = 4
10 changes: 10 additions & 0 deletions .github/linters/.jscpd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"threshold": 5,
"reporters": [
"consoleFull"
],
"ignore": [
"**/*_test.go"
],
"absolute": true
}
59 changes: 59 additions & 0 deletions .github/linters/.yaml-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
###########################################
# These are the rules used for #
# linting all the yaml files in the stack #
# NOTE: #
# You can disable line with: #
# # yamllint disable-line #
###########################################
rules:
braces:
level: warning
min-spaces-inside: 0
max-spaces-inside: 1
min-spaces-inside-empty: 1
max-spaces-inside-empty: 5
brackets:
level: warning
min-spaces-inside: 0
max-spaces-inside: 1
min-spaces-inside-empty: 1
max-spaces-inside-empty: 5
colons:
level: warning
max-spaces-before: 0
max-spaces-after: 1
commas:
level: warning
max-spaces-before: 0
min-spaces-after: 1
max-spaces-after: 1
comments: disable
comments-indentation: disable
document-end: disable
document-start:
level: warning
present: true
empty-lines:
level: warning
max: 2
max-start: 0
max-end: 0
hyphens:
level: warning
max-spaces-after: 1
indentation:
level: warning
spaces: consistent
indent-sequences: true
check-multi-line-strings: false
key-duplicates: enable
line-length:
level: warning
max: 120
allow-non-breakable-words: true
allow-non-breakable-inline-mappings: true
new-line-at-end-of-file: disable
new-lines:
type: unix
trailing-spaces: disable
3 changes: 2 additions & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: "CodeQL"

on:
Expand All @@ -19,7 +20,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: "PR: Lint"
---
name: "Lint"

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
Expand All @@ -18,7 +19,7 @@ jobs:

steps:
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Testing

on:
Expand Down Expand Up @@ -30,7 +31,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
- name: Check out code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Run tests
if: success()
run: go test -timeout 60s -cover ./... -coverprofile=coverage.txt -covermode=atomic
Expand Down
49 changes: 24 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,53 @@
## Install

Storage major version matches [OAuth 2.0](https://github.com/go-oauth2/oauth2) major version,
so use corresponding version (go modules compliant)
so use corresponding version (go modules compliant)

For `github.com/go-oauth2/oauth2/v4`:

```bash
$ go get -u github.com/vgarvardt/go-oauth2-pg/v4
go get -u github.com/vgarvardt/go-oauth2-pg/v4
```

For `gopkg.in/oauth2.v3` see [v3 branch](https://github.com/vgarvardt/go-oauth2-pg/tree/v3).

## PostgreSQL drivers

The store accepts an adapter interface that interacts with the DB.
Adapter and implementations extracted to separate package [`github.com/vgarvardt/go-pg-adapter`](https://github.com/vgarvardt/go-pg-adapter) for easier maintenance.
Adapter and implementations extracted to separate
package [`github.com/vgarvardt/go-pg-adapter`](https://github.com/vgarvardt/go-pg-adapter) for easier maintenance.

## Usage example

```go
package main

import (
"context"
"os"
"time"

"github.com/go-oauth2/oauth2/v4/manage"
"github.com/jackc/pgx/v4"
pg "github.com/vgarvardt/go-oauth2-pg/v4"
"github.com/vgarvardt/go-pg-adapter/pgx4adapter"
"context"
"os"
"time"

"github.com/go-oauth2/oauth2/v4/manage"
"github.com/jackc/pgx/v4"
pg "github.com/vgarvardt/go-oauth2-pg/v4"
"github.com/vgarvardt/go-pg-adapter/pgx4adapter"
)

func main() {
pgxConn, _ := pgx.Connect(context.TODO(), os.Getenv("DB_URI"))
pgxConn, _ := pgx.Connect(context.TODO(), os.Getenv("DB_URI"))

manager := manage.NewDefaultManager()
manager := manage.NewDefaultManager()

// use PostgreSQL token store with pgx.Connection adapter
adapter := pgx4adapter.NewConn(pgxConn)
tokenStore, _ := pg.NewTokenStore(adapter, pg.WithTokenStoreGCInterval(time.Minute))
defer tokenStore.Close()

clientStore, _ := pg.NewClientStore(adapter)
// use PostgreSQL token store with pgx.Connection adapter
adapter := pgx4adapter.NewConn(pgxConn)
tokenStore, _ := pg.NewTokenStore(adapter, pg.WithTokenStoreGCInterval(time.Minute))
defer tokenStore.Close()

manager.MapTokenStorage(tokenStore)
manager.MapClientStorage(clientStore)
// ...
clientStore, _ := pg.NewClientStore(adapter)

manager.MapTokenStorage(tokenStore)
manager.MapClientStorage(clientStore)
// ...
}
```

Expand All @@ -70,6 +71,4 @@ if they are not started yet and runs go tests with coverage.

## MIT License

```
Copyright (c) 2020 Vladimir Garvardt
```
> Copyright (c) 2020 Vladimir Garvardt
10 changes: 5 additions & 5 deletions client_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func NewClientStore(adapter pgAdapter.Adapter, options ...ClientStoreOption) (*C
func (s *ClientStore) initTable() error {
return s.adapter.Exec(context.Background(), fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %[1]s (
id TEXT NOT NULL,
secret TEXT NOT NULL,
domain TEXT NOT NULL,
data JSONB NOT NULL,
CONSTRAINT %[1]s_pkey PRIMARY KEY (id)
id TEXT NOT NULL,
secret TEXT NOT NULL,
domain TEXT NOT NULL,
data JSONB NOT NULL,
CONSTRAINT %[1]s_pkey PRIMARY KEY (id)
);
`, s.tableName))
}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
version: "3"

services:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ require (
github.com/go-oauth2/oauth2/v4 v4.4.3
github.com/jackc/pgx/v4 v4.17.2
github.com/jmoiron/sqlx v1.3.5
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.1
github.com/vgarvardt/go-pg-adapter v1.0.0
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,19 @@ github.com/spf13/pflag v1.0.1-0.20171106142849-4c012f6dcd95/go.mod h1:DYY7MBk1bd
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tidwall/btree v0.0.0-20191029221954-400434d76274/go.mod h1:huei1BkDWJ3/sLXmO+bsCNELL+Bp2Kks9OLyQFkzvA8=
github.com/tidwall/buntdb v1.1.2/go.mod h1:xAzi36Hir4FarpSHyfuZ6JzPJdjRZ8QlLZSntE2mqlI=
github.com/tidwall/gjson v1.3.4/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
Expand Down
16 changes: 8 additions & 8 deletions token_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ func (s *TokenStore) gc() {
func (s *TokenStore) initTable() error {
return s.adapter.Exec(context.Background(), fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %[1]s (
id BIGSERIAL NOT NULL,
created_at TIMESTAMPTZ NOT NULL,
expires_at TIMESTAMPTZ NOT NULL,
code TEXT NOT NULL,
access TEXT NOT NULL,
refresh TEXT NOT NULL,
data JSONB NOT NULL,
CONSTRAINT %[1]s_pkey PRIMARY KEY (id)
id BIGSERIAL NOT NULL,
created_at TIMESTAMPTZ NOT NULL,
expires_at TIMESTAMPTZ NOT NULL,
code TEXT NOT NULL,
access TEXT NOT NULL,
refresh TEXT NOT NULL,
data JSONB NOT NULL,
CONSTRAINT %[1]s_pkey PRIMARY KEY (id)
);

CREATE INDEX IF NOT EXISTS idx_%[1]s_expires_at ON %[1]s (expires_at);
Expand Down