Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
koko
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
ops
koko
Commits
cd41446b
Commit
cd41446b
authored
Apr 23, 2019
by
Eric
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrapper http client
parent
17a481d4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
19 additions
and
23 deletions
+19
-23
coco.go
cmd/coco.go
+0
-2
client.go
pkg/common/client.go
+1
-1
accesskey.go
pkg/service/accesskey.go
+1
-1
assets.go
pkg/service/assets.go
+3
-4
client.go
pkg/service/client.go
+13
-14
urls.go
pkg/service/urls.go
+1
-1
No files found.
cmd/coco.go
View file @
cd41446b
package
main
package
main
import
(
import
(
"cocogo/pkg/auth"
"cocogo/pkg/config"
"cocogo/pkg/config"
"cocogo/pkg/sshd"
"cocogo/pkg/sshd"
)
)
func
init
()
{
func
init
()
{
config
.
Initial
()
config
.
Initial
()
auth
.
Initial
()
sshd
.
Initial
()
sshd
.
Initial
()
}
}
...
...
pkg/common/client.go
View file @
cd41446b
...
@@ -152,7 +152,7 @@ func (c *Client) Do(method, url string, data, res interface{}, params ...map[str
...
@@ -152,7 +152,7 @@ func (c *Client) Do(method, url string, data, res interface{}, params ...map[str
return
return
}
}
func
(
c
*
Client
)
Get
(
url
string
,
query
map
[
string
]
string
,
res
interface
{})
(
err
error
)
{
func
(
c
*
Client
)
Get
(
url
string
,
res
interface
{})
(
err
error
)
{
return
c
.
Do
(
"GET"
,
url
,
nil
,
res
)
return
c
.
Do
(
"GET"
,
url
,
nil
,
res
)
}
}
...
...
pkg/service/accesskey.go
View file @
cd41446b
package
service
package
service
import
(
import
(
"cocogo/pkg/logger"
"errors"
"errors"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
...
@@ -9,6 +8,7 @@ import (
...
@@ -9,6 +8,7 @@ import (
"strings"
"strings"
"cocogo/pkg/common"
"cocogo/pkg/common"
"cocogo/pkg/logger"
)
)
var
(
var
(
...
...
pkg/service/assets.go
View file @
cd41446b
package
service
package
service
import
(
import
(
"fmt"
"cocogo/pkg/logger"
"cocogo/pkg/logger"
"cocogo/pkg/model"
"cocogo/pkg/model"
"fmt"
)
)
//
//
...
@@ -22,10 +21,10 @@ import (
...
@@ -22,10 +21,10 @@ import (
//
//
func
GetSystemUserAuthInfo
(
systemUserID
string
)
{
func
GetSystemUserAuthInfo
(
systemUserID
string
)
{
var
authInfo
model
.
SystemUserAuthInfo
var
authInfo
model
.
SystemUserAuthInfo
err
:=
client
.
Get
(
"systemUserAuthInfo"
,
nil
,
&
authInfo
)
systemUrl
:=
fmt
.
Sprintf
(
urls
[
"SystemUserAuthInfo"
],
systemUserID
)
err
:=
client
.
Get
(
systemUrl
,
&
authInfo
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Info
(
"get User Assets Groups err:"
,
err
)
logger
.
Info
(
"get User Assets Groups err:"
,
err
)
return
return
}
}
fmt
.
Println
(
authInfo
)
}
}
pkg/service/client.go
View file @
cd41446b
package
service
package
service
import
(
import
(
"cocogo/pkg/common"
"cocogo/pkg/config"
"cocogo/pkg/model"
"cocogo/pkg/model"
"net/http"
"path"
"path"
"path/filepath"
"path/filepath"
"strings"
"strings"
"cocogo/pkg/common"
"cocogo/pkg/config"
)
)
type
ClientAuth
interface
{
type
ClientAuth
interface
{
...
@@ -16,18 +14,11 @@ type ClientAuth interface {
...
@@ -16,18 +14,11 @@ type ClientAuth interface {
}
}
type
WrapperClient
struct
{
type
WrapperClient
struct
{
*
common
.
Client
Http
*
common
.
Client
Auth
ClientAuth
Auth
ClientAuth
BaseHost
string
BaseHost
string
}
}
func
(
c
*
WrapperClient
)
SetAuthHeader
(
r
*
http
.
Request
)
{
if
c
.
Auth
!=
nil
{
signature
:=
c
.
Auth
.
Sign
()
r
.
Header
.
Add
(
"Authorization"
,
signature
)
}
}
func
(
c
*
WrapperClient
)
ExpandUrl
(
url
string
,
query
map
[
string
]
string
)
string
{
func
(
c
*
WrapperClient
)
ExpandUrl
(
url
string
,
query
map
[
string
]
string
)
string
{
return
""
return
""
}
}
...
@@ -41,7 +32,7 @@ func (c *WrapperClient) ParseUrl(url string, params ...map[string]string) string
...
@@ -41,7 +32,7 @@ func (c *WrapperClient) ParseUrl(url string, params ...map[string]string) string
newUrl
=
strings
.
TrimRight
(
c
.
BaseHost
,
"/"
)
+
newUrl
newUrl
=
strings
.
TrimRight
(
c
.
BaseHost
,
"/"
)
+
newUrl
}
}
if
len
(
params
)
==
1
{
if
len
(
params
)
==
1
{
url
=
c
.
ParseUrlQuery
(
url
,
params
[
0
])
url
=
c
.
Http
.
ParseUrlQuery
(
url
,
params
[
0
])
}
}
return
newUrl
return
newUrl
}
}
...
@@ -62,9 +53,17 @@ func (c *WrapperClient) LoadAuth() error {
...
@@ -62,9 +53,17 @@ func (c *WrapperClient) LoadAuth() error {
func
(
c
*
WrapperClient
)
CheckAuth
()
error
{
func
(
c
*
WrapperClient
)
CheckAuth
()
error
{
var
user
model
.
User
var
user
model
.
User
err
:=
c
.
Get
(
"UserProfileUrl"
,
&
user
)
err
:=
c
.
Http
.
Get
(
"UserProfileUrl"
,
&
user
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
return
nil
return
nil
}
}
func
(
c
*
WrapperClient
)
Get
(
url
string
,
res
interface
{},
needAuth
bool
)
error
{
if
needAuth
{
c
.
Http
.
SetAuth
(
c
.
Auth
.
Sign
())
}
return
c
.
Http
.
Get
(
c
.
BaseHost
+
url
,
res
)
}
pkg/service/urls.go
View file @
cd41446b
...
@@ -5,7 +5,7 @@ var urls = map[string]string{
...
@@ -5,7 +5,7 @@ var urls = map[string]string{
"UserProfileUrl"
:
"/api/users/v1/profile/"
,
// 获取当前用户的基本信息
"UserProfileUrl"
:
"/api/users/v1/profile/"
,
// 获取当前用户的基本信息
"SystemUserAssetAuthUrl"
:
"/api/assets/v1/system-user/%s/asset/%s/auth-info/"
,
// 该系统用户对某资产的授权
"SystemUserAssetAuthUrl"
:
"/api/assets/v1/system-user/%s/asset/%s/auth-info/"
,
// 该系统用户对某资产的授权
"SystemUserAuth
Url"
:
"/api/assets/v1/system-user/%s/auth-info/"
,
// 该系统用户的授权
"SystemUserAuth
Info"
:
"/api/assets/v1/system-user/%s/auth-info/"
,
// 该系统用户的授权
"TerminalRegisterUrl"
:
"/api/terminal/v2/terminal-registrations/"
,
// 注册当前coco
"TerminalRegisterUrl"
:
"/api/terminal/v2/terminal-registrations/"
,
// 注册当前coco
"TerminalConfigUrl"
:
"/api/terminal/v1/terminal/config/"
,
// 从jumpserver获取coco的配置
"TerminalConfigUrl"
:
"/api/terminal/v1/terminal/config/"
,
// 从jumpserver获取coco的配置
...
...
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