Commit fc791b35 authored by liugaoling's avatar liugaoling

authorization

parent a4816eaf
...@@ -19,18 +19,8 @@ func main() { ...@@ -19,18 +19,8 @@ func main() {
} }
// Only allowed to "Pull". If "Push" access needed, define the rules via static ACL // Only allowed to "Pull". If "Push" access needed, define the rules via static ACL
//if utils.ArrayContains(authReqInfo.Actions, PushKeyWord) { fmt.Println("The user " + authReqInfo.Account + " requesting \"push\" access for the Repo: " + authReqInfo.Name)
fmt.Println("The user " + authReqInfo.Account + " requesting \"push\" access for the Repo: " + authReqInfo.Name) isAuthorized := utils.HttpAuth(authReqInfo)
//os.Exit(utils.ErrorExitCode)
//}
//repo := authReqInfo.Name
//user := authReqInfo.Account
isAuthorized := false
//if repo == "hello-world" && user == "admin" {
isAuthorized = true
//}
if isAuthorized { if isAuthorized {
os.Exit(utils.SuccessExitCode) os.Exit(utils.SuccessExitCode)
......
...@@ -4,9 +4,12 @@ import ( ...@@ -4,9 +4,12 @@ import (
"bufio" "bufio"
"os" "os"
"strings" "strings"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"fmt" "fmt"
"github.com/cesanta/docker_auth/auth_server/authz"
"encoding/json"
"bytes"
) )
const SuccessExitCode = 0 const SuccessExitCode = 0
...@@ -34,9 +37,9 @@ func ArrayContains(array []string, key string) bool { ...@@ -34,9 +37,9 @@ func ArrayContains(array []string, key string) bool {
func HttpLogin(username string, password string) (bool, error) { func HttpLogin(username string, password string) (bool, error) {
client := &http.Client{} client := &http.Client{}
loginurl := "https://www.cloudam.cn/uaa/oauth/token?scope=ui&grant_type=password&username=" + username + "&password=" + password loginUrl := "https://www.cloudam.cn/uaa/oauth/token?scope=ui&grant_type=password&username=" + username + "&password=" + password
req, err := http.NewRequest("POST", loginurl, nil) req, err := http.NewRequest("POST", loginUrl, nil)
if err != nil { if err != nil {
// handle error // handle error
...@@ -59,3 +62,19 @@ func HttpLogin(username string, password string) (bool, error) { ...@@ -59,3 +62,19 @@ func HttpLogin(username string, password string) (bool, error) {
return true, nil return true, nil
} }
func HttpAuth(authReqInfo *authz.AuthRequestInfo) bool {
client := &http.Client{}
authUrl := "http://47.57.4.97/c3ce/dockerimage/authorization"
bytesData, _ := json.Marshal(authReqInfo)
req, _ := http.NewRequest("POST", authUrl, bytes.NewReader(bytesData))
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
if resp.StatusCode == 200 {
return true
}
fmt.Println(string(body))
return false
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment