Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
docker-registry
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
docker-registry
Commits
fc791b35
Commit
fc791b35
authored
Oct 19, 2021
by
liugaoling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
authorization
parent
a4816eaf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
16 deletions
+25
-16
authorization.go
main/authorization.go
+2
-12
utils.go
utils/utils.go
+23
-4
No files found.
main/authorization.go
View file @
fc791b35
...
@@ -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
)
...
...
utils/utils.go
View file @
fc791b35
...
@@ -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
{}
login
u
rl
:=
"https://www.cloudam.cn/uaa/oauth/token?scope=ui&grant_type=password&username="
+
username
+
"&password="
+
password
login
U
rl
:=
"https://www.cloudam.cn/uaa/oauth/token?scope=ui&grant_type=password&username="
+
username
+
"&password="
+
password
req
,
err
:=
http
.
NewRequest
(
"POST"
,
login
u
rl
,
nil
)
req
,
err
:=
http
.
NewRequest
(
"POST"
,
login
U
rl
,
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment