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

refactoring #70

Merged
merged 26 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1f20b2a
fix: the name (req => resp)
akakou May 31, 2024
df43915
feat: add some type of result for the packages
akakou May 31, 2024
250eeb9
refactor: devide into acceptance check and auth
akakou May 31, 2024
95b01f6
fix: ignoring stay
akakou May 31, 2024
7a26e52
refactor: name `Stay` => `Keep`
akakou May 31, 2024
444fd0d
refactor: rename acceptance list check to skip auth
akakou May 31, 2024
bd8fa3a
refactor: rename white list to skip auth
akakou May 31, 2024
dfa1293
feat: force auth director
akakou May 31, 2024
2bfc460
Merge branch 'develop' into feature/force-auth
akakou May 31, 2024
ca1f063
Merge pull request #68 from ochanoco/feature/force-auth
akakou May 31, 2024
fe81b29
refactor: divide folders
akakou May 31, 2024
ad20280
refactor: divide director files
akakou May 31, 2024
b9ade7e
refactor: remove director or modify response from not them
akakou May 31, 2024
bee8abd
rafactor: move file and update logflow
akakou May 31, 2024
4e8ce71
refactor: make flow log a tools
akakou May 31, 2024
7fa3e9b
fix: extension logger bugs
akakou May 31, 2024
0316aa2
fix: skip director missing
akakou May 31, 2024
7de4e72
test: force auth list
akakou May 31, 2024
2dcaa43
Merge pull request #69 from ochanoco/refactor/6-1
akakou May 31, 2024
5a1a51d
chore: remove binary
akakou May 31, 2024
b4282f2
fix: force auth director missing
akakou May 31, 2024
d4a4b41
fix: force auth director missing
akakou May 31, 2024
8e2de09
fix: package name and function name for main package
akakou May 31, 2024
caf4162
fix: docker file to appy previous changes
akakou May 31, 2024
19b33ae
fix: no go file error
akakou May 31, 2024
9e97990
feat: remove force auth list
akakou May 31, 2024
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ dist
.pnp.*

torima
proxy
sqlite3.db
test.sqlite3
secret.env
Expand All @@ -157,7 +156,8 @@ private.der
.gitignore
cert.der

example/main
serv/serv
*.db
tmp


2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ default_origin: app:5000 # your front-end server
protection_scope:
- api:5001 # your API servers

white_list_path:
skip_auth_list:
- /favicon.ico

scheme: http
Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
port: 8080

white_list_path:
skip_auth_list:
- /favicon.ico

# default_origin: 127.0.0.1:8080
Expand Down
37 changes: 2 additions & 35 deletions core/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package core

import (
"fmt"
"log"
"os"

"github.com/creasty/defaults"
Expand All @@ -14,12 +12,12 @@ type TorimaConfig struct {
Host string `yaml:"host" default:"http://127.0.0.1:8080"`
Port int `yaml:"port" default:"8080" `
Scheme string `yaml:"scheme" default:"http"`
WhiteListPath []string `yaml:"white_list_path" default:"[]"`
SkipAuthList []string `yaml:"skip_auth_list" default:"[]"`
ProtectionScope []string `yaml:"protection_scope" default:"[]"`
WebRoot string `yaml:"web_root" default:"/torima"`
}

func readConfig() (*TorimaConfig, error) {
func ReadConfig() (*TorimaConfig, error) {
var m TorimaConfig
var def TorimaConfig // default config

Expand All @@ -44,34 +42,3 @@ func readConfig() (*TorimaConfig, error) {

return &m, err
}

func printConfig(config *TorimaConfig) {
fmt.Println("default_origin:", config.DefaultOrigin)
fmt.Println("host:", config.Host)
fmt.Println("port:", config.Port)
fmt.Println("scheme:", config.Scheme)
fmt.Println("white_list_path:", config.WhiteListPath)
fmt.Println("protection_scope:", config.ProtectionScope)
fmt.Println("web_root:", config.WebRoot)
}

func readEnv(name, def string) string {
value := os.Getenv(name)

if value == "" {
fmt.Printf("environment variable '%v' is not found so that proxy use '%v'\n", name, def)
value = def
}

return value
}

func readEnvOrPanic(name string) string {
value := os.Getenv(name)

if value == "" {
log.Fatalf("environment variable '%v' is not found", name)
}

return value
}
37 changes: 31 additions & 6 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,38 @@ import (
"github.com/gin-gonic/gin"
)

type TorimaDirector = func(proxy *TorimaProxy, req *http.Request, c *gin.Context) (bool, error)
type TorimaModifyResponse = func(proxy *TorimaProxy, req *http.Response, c *gin.Context) (bool, error)
type TorimaPackageStatus = int

const (
AuthNeeded TorimaPackageStatus = iota
Authed
NoAuthNeeded
ForceStop
Keep
)

type TorimaPackageTarget interface{ *http.Request | *http.Response }

type TorimaPackageContext[T TorimaPackageTarget] struct {
Proxy *TorimaProxy
Target T
GinContext *gin.Context
PackageStatus TorimaPackageStatus
}

type TorimaDirectorPackageContext = TorimaPackageContext[*http.Request]
type TorimaModifyResponsePackageContext = TorimaPackageContext[*http.Response]

type TorimaDirector func(*TorimaDirectorPackageContext) (TorimaPackageStatus, error)
type TorimaModifyResponse func(*TorimaModifyResponsePackageContext) (TorimaPackageStatus, error)
type TorimaDirectors []func(*TorimaDirectorPackageContext) (TorimaPackageStatus, error)
type TorimaModifyResponses []func(*TorimaModifyResponsePackageContext) (TorimaPackageStatus, error)

type TorimaProxyWebPage = func(proxy *TorimaProxy, c *gin.RouterGroup)

type TorimaProxy struct {
Directors []TorimaDirector
ModifyResponses []TorimaModifyResponse
Directors TorimaDirectors
ModifyResponses TorimaModifyResponses
ProxyWebPages []TorimaProxyWebPage
Engine *gin.Engine
Database *Database
Expand All @@ -24,8 +49,8 @@ type TorimaProxy struct {

func NewOchancoProxy(
r *gin.Engine,
directors []TorimaDirector,
modifyResponses []TorimaModifyResponse,
directors TorimaDirectors,
modifyResponses TorimaModifyResponses,
proxyWebPages []TorimaProxyWebPage,
config *TorimaConfig,
database *Database,
Expand Down
149 changes: 0 additions & 149 deletions core/director.go

This file was deleted.

Loading
Loading