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
89a10490
Commit
89a10490
authored
Apr 23, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Plain Diff
[Update] Merge
parents
747900d3
cd41446b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
37 deletions
+21
-37
client.go
pkg/common/client.go
+1
-1
accesskey.go
pkg/service/accesskey.go
+1
-1
assets.go
pkg/service/assets.go
+3
-1
client.go
pkg/service/client.go
+15
-33
urls.go
pkg/service/urls.go
+1
-1
No files found.
pkg/common/client.go
View file @
89a10490
...
@@ -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 @
89a10490
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 @
89a10490
...
@@ -3,6 +3,7 @@ package service
...
@@ -3,6 +3,7 @@ package service
import
(
import
(
"cocogo/pkg/logger"
"cocogo/pkg/logger"
"cocogo/pkg/model"
"cocogo/pkg/model"
"fmt"
)
)
//
//
...
@@ -20,7 +21,8 @@ import (
...
@@ -20,7 +21,8 @@ import (
//
//
func
GetSystemUserAssetAuthInfo
(
systemUserID
,
assetID
string
)
(
info
model
.
SystemUserAuthInfo
,
err
error
)
{
func
GetSystemUserAssetAuthInfo
(
systemUserID
,
assetID
string
)
(
info
model
.
SystemUserAuthInfo
,
err
error
)
{
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
...
...
pkg/service/client.go
View file @
89a10490
package
service
package
service
import
(
import
(
"net/http"
"path"
"path"
"path/filepath"
"path/filepath"
"strings"
"cocogo/pkg/common"
"cocogo/pkg/common"
"cocogo/pkg/config"
"cocogo/pkg/config"
"cocogo/pkg/model"
)
)
type
ClientAuth
interface
{
type
ClientAuth
interface
{
...
@@ -15,36 +14,11 @@ type ClientAuth interface {
...
@@ -15,36 +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
{
return
""
}
func
(
c
*
WrapperClient
)
ParseUrl
(
url
string
,
params
...
map
[
string
]
string
)
string
{
var
newUrl
=
""
if
url
,
ok
:=
urls
[
url
];
ok
{
newUrl
=
url
}
if
c
.
BaseHost
!=
""
{
newUrl
=
strings
.
TrimRight
(
c
.
BaseHost
,
"/"
)
+
newUrl
}
if
len
(
params
)
==
1
{
url
=
c
.
ParseUrlQuery
(
url
,
params
[
0
])
}
return
newUrl
}
func
(
c
*
WrapperClient
)
LoadAuth
()
error
{
func
(
c
*
WrapperClient
)
LoadAuth
()
error
{
keyPath
:=
config
.
Conf
.
AccessKeyFile
keyPath
:=
config
.
Conf
.
AccessKeyFile
if
!
path
.
IsAbs
(
config
.
Conf
.
AccessKeyFile
)
{
if
!
path
.
IsAbs
(
config
.
Conf
.
AccessKeyFile
)
{
...
@@ -60,10 +34,18 @@ func (c *WrapperClient) LoadAuth() error {
...
@@ -60,10 +34,18 @@ 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 @
89a10490
...
@@ -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