-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add doge driver * doc: 补充readme文档 * fix: 对齐meta信息 * fix: 调整结构体名字,与driver保持一致 * perf: merge to s3 * Rename goge.go to doge.go --------- Co-authored-by: Andy Hsu <[email protected]>
- Loading branch information
Showing
10 changed files
with
141 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
root = "." | ||
testdata_dir = "testdata" | ||
tmp_dir = "tmp" | ||
|
||
[build] | ||
args_bin = ["server"] | ||
bin = "./tmp/main" | ||
cmd = "go build -o ./tmp/main ." | ||
delay = 0 | ||
exclude_dir = ["assets", "tmp", "vendor", "testdata"] | ||
exclude_file = [] | ||
exclude_regex = ["_test.go"] | ||
exclude_unchanged = false | ||
follow_symlink = false | ||
full_bin = "" | ||
include_dir = [] | ||
include_ext = ["go", "tpl", "tmpl", "html"] | ||
include_file = [] | ||
kill_delay = "0s" | ||
log = "build-errors.log" | ||
poll = false | ||
poll_interval = 0 | ||
rerun = false | ||
rerun_delay = 500 | ||
send_interrupt = false | ||
stop_on_error = false | ||
|
||
[color] | ||
app = "" | ||
build = "yellow" | ||
main = "magenta" | ||
runner = "green" | ||
watcher = "cyan" | ||
|
||
[log] | ||
main_only = false | ||
time = false | ||
|
||
[misc] | ||
clean_on_exit = false | ||
|
||
[screen] | ||
clear_on_rebuild = false | ||
keep_scroll = true |
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 |
---|---|---|
|
@@ -24,6 +24,7 @@ output/ | |
*.json | ||
/build | ||
/data/ | ||
/tmp/ | ||
/log/ | ||
/lang/ | ||
/daemon/ | ||
|
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
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,62 @@ | ||
package s3 | ||
|
||
import ( | ||
"crypto/hmac" | ||
"crypto/sha1" | ||
"encoding/hex" | ||
"encoding/json" | ||
"io" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
type TmpTokenResponse struct { | ||
Code int `json:"code"` | ||
Msg string `json:"msg"` | ||
Data TmpTokenResponseData `json:"data,omitempty"` | ||
} | ||
type TmpTokenResponseData struct { | ||
Credentials Credentials `json:"Credentials"` | ||
} | ||
type Credentials struct { | ||
AccessKeyId string `json:"accessKeyId,omitempty"` | ||
SecretAccessKey string `json:"secretAccessKey,omitempty"` | ||
SessionToken string `json:"sessionToken,omitempty"` | ||
} | ||
|
||
func getCredentials(AccessKey, SecretKey string) (rst Credentials, err error) { | ||
apiPath := "/auth/tmp_token.json" | ||
reqBody, err := json.Marshal(map[string]interface{}{"channel": "OSS_FULL", "scopes": []string{"*"}}) | ||
if err != nil { | ||
return rst, err | ||
} | ||
|
||
signStr := apiPath + "\n" + string(reqBody) | ||
hmacObj := hmac.New(sha1.New, []byte(SecretKey)) | ||
hmacObj.Write([]byte(signStr)) | ||
sign := hex.EncodeToString(hmacObj.Sum(nil)) | ||
Authorization := "TOKEN " + AccessKey + ":" + sign | ||
|
||
req, err := http.NewRequest("POST", "https://api.dogecloud.com"+apiPath, strings.NewReader(string(reqBody))) | ||
if err != nil { | ||
return rst, err | ||
} | ||
req.Header.Add("Content-Type", "application/json") | ||
req.Header.Add("Authorization", Authorization) | ||
client := http.Client{} | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
return rst, err | ||
} | ||
defer resp.Body.Close() | ||
ret, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return rst, err | ||
} | ||
var tmpTokenResp TmpTokenResponse | ||
err = json.Unmarshal(ret, &tmpTokenResp) | ||
if err != nil { | ||
return rst, err | ||
} | ||
return tmpTokenResp.Data.Credentials, nil | ||
} |
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
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