-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add configuration file + modifiers
Co-Authored-By: Sebastián Vargas <[email protected]>
- Loading branch information
1 parent
b887b70
commit 5a33383
Showing
9 changed files
with
204 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2024. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package api | ||
|
||
import "regexp" | ||
|
||
type DoorkeeperConfigT struct { | ||
Auth AuthorizationConfigT `yaml:"authorization"` | ||
Hmac HmacConfigT `yaml:"hmac"` | ||
Modifiers []ModifierConfigT `yaml:"modifiers"` | ||
} | ||
|
||
type AuthorizationConfigT struct { | ||
Type string `yaml:"type"` | ||
Param AuthParamConfigT `yaml:"param"` | ||
} | ||
|
||
type AuthParamConfigT struct { | ||
Type string `yaml:"type"` | ||
Name string `yaml:"name"` | ||
} | ||
|
||
type HmacConfigT struct { | ||
Type string `yaml:"type"` | ||
EncryptionKey string `yaml:"encryptionKey"` | ||
EncryptionAlgorithm string `yaml:"encryptionAlgorithm"` | ||
} | ||
|
||
type ModifierConfigT struct { | ||
Type string `yaml:"type"` | ||
Path ModifierPathConfigT `yaml:"path"` | ||
} | ||
|
||
type ModifierPathConfigT struct { | ||
Pattern string `yaml:"pattern"` | ||
Replace string `yaml:"replace"` | ||
|
||
// Carry stuff | ||
CompiledRegex *regexp.Regexp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
authorization: | ||
type: hmac # hmac | ||
param: | ||
type: query # header|query | ||
name: token | ||
|
||
hmac: | ||
type: url | ||
encryptionKey: "${SECRETITO}" | ||
encryptionAlgorithm: "sha256" | ||
|
||
modifiers: | ||
#- type: header # headers|host|path | ||
# header: | ||
# # TODO | ||
|
||
- type: path | ||
path: | ||
pattern: ^(/[a-zA-Z0-9\-_]/) | ||
replace: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package config | ||
|
||
import ( | ||
"doorkeeper/api" | ||
"os" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
// Marshal TODO | ||
func Marshal(config api.DoorkeeperConfigT) (bytes []byte, err error) { | ||
bytes, err = yaml.Marshal(config) | ||
return bytes, err | ||
} | ||
|
||
// Unmarshal TODO | ||
func Unmarshal(bytes []byte) (config api.DoorkeeperConfigT, err error) { | ||
err = yaml.Unmarshal(bytes, &config) | ||
return config, err | ||
} | ||
|
||
// ReadFile TODO | ||
func ReadFile(filepath string) (config api.DoorkeeperConfigT, err error) { | ||
var fileBytes []byte | ||
fileBytes, err = os.ReadFile(filepath) | ||
if err != nil { | ||
return config, err | ||
} | ||
|
||
fileBytes = []byte(os.ExpandEnv(string(fileBytes))) | ||
|
||
config, err = Unmarshal(fileBytes) | ||
|
||
return config, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.