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
c9ebf9bd
Commit
c9ebf9bd
authored
Apr 23, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Plain Diff
[Update] Merge
parents
3198cb2a
aa1c9a11
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
118 additions
and
73 deletions
+118
-73
client.go
pkg/common/client.go
+17
-24
assets.go
pkg/sdk/assets.go
+0
-16
client.go
pkg/sdk/client.go
+38
-0
init.go
pkg/sdk/init.go
+0
-16
urls.go
pkg/sdk/urls.go
+14
-14
users.go
pkg/sdk/users.go
+1
-3
assets.go
pkg/service/assets.go
+13
-0
terminal.go
pkg/service/terminal.go
+25
-0
users.go
pkg/service/users.go
+10
-0
No files found.
pkg/common/client.go
View file @
c9ebf9bd
...
...
@@ -14,14 +14,17 @@ import (
"time"
)
type
ClientAuth
interface
{
Sign
()
string
}
type
Client
struct
{
Timeout
time
.
Duration
Headers
map
[
string
]
string
basicAuth
[]
string
authorization
string
cookie
map
[
string
]
string
http
*
http
.
Client
UrlParsers
[]
UrlParser
Timeout
time
.
Duration
Headers
map
[
string
]
string
Auth
ClientAuth
cookie
map
[
string
]
string
http
*
http
.
Client
UrlParsers
[]
UrlParser
}
type
UrlParser
interface
{
...
...
@@ -40,19 +43,14 @@ func NewClient(timeout time.Duration) *Client {
}
}
func
(
c
*
Client
)
SetBasicAuth
(
username
,
password
string
)
{
c
.
basicAuth
=
append
(
c
.
basicAuth
,
username
)
c
.
basicAuth
=
append
(
c
.
basicAuth
,
password
)
}
func
(
c
*
Client
)
SetAuth
(
authorization
string
)
{
c
.
authorization
=
authorization
}
func
(
c
*
Client
)
SetCookie
(
k
,
v
string
)
{
c
.
cookie
[
k
]
=
v
}
func
(
c
*
Client
)
SetAuth
(
auth
ClientAuth
)
{
c
.
Auth
=
auth
}
func
(
c
*
Client
)
marshalData
(
data
interface
{})
(
reader
io
.
Reader
,
error
error
)
{
dataRaw
,
err
:=
json
.
Marshal
(
data
)
if
err
!=
nil
{
...
...
@@ -81,14 +79,6 @@ func (c *Client) ParseUrl(url string) string {
}
func
(
c
*
Client
)
SetAuthHeader
(
r
*
http
.
Request
,
params
...
map
[
string
]
string
)
{
if
len
(
c
.
basicAuth
)
==
2
{
r
.
SetBasicAuth
(
c
.
basicAuth
[
0
],
c
.
basicAuth
[
1
])
return
}
if
c
.
authorization
!=
""
{
r
.
Header
.
Add
(
"Authorization"
,
c
.
authorization
)
return
}
if
len
(
c
.
cookie
)
!=
0
{
cookie
:=
make
([]
string
,
0
)
for
k
,
v
:=
range
c
.
cookie
{
...
...
@@ -96,6 +86,9 @@ func (c *Client) SetAuthHeader(r *http.Request, params ...map[string]string) {
}
r
.
Header
.
Add
(
"Cookie"
,
strings
.
Join
(
cookie
,
";"
))
}
if
c
.
Auth
!=
nil
{
r
.
Header
.
Set
(
"Authorization"
,
c
.
Auth
.
Sign
())
}
}
func
(
c
*
Client
)
SetReqHeaders
(
req
*
http
.
Request
,
params
...
map
[
string
]
string
)
{
...
...
pkg/sdk/assets.go
View file @
c9ebf9bd
package
sdk
import
(
"cocogo/pkg/logger"
"cocogo/pkg/model"
"fmt"
)
//
//func GetSystemUserAssetAuthInfo(systemUserID, assetID string) (authInfo model.SystemUserAuthInfo, err error) {
//
...
...
@@ -19,13 +13,3 @@ import (
//
//}
//
func
GetSystemUserAssetAuthInfo
(
systemUserID
,
assetID
string
)
(
info
model
.
SystemUserAuthInfo
,
err
error
)
{
var
authInfo
model
.
SystemUserAuthInfo
systemUrl
:=
fmt
.
Sprintf
(
urls
[
"SystemUserAuthInfo"
],
systemUserID
)
err
=
Client
.
Get
(
systemUrl
,
&
authInfo
,
true
)
if
err
!=
nil
{
logger
.
Info
(
"get User Assets Groups err:"
,
err
)
return
}
return
}
pkg/sdk/client.go
View file @
c9ebf9bd
...
...
@@ -44,7 +44,45 @@ func (c *WrapperClient) CheckAuth() error {
func
(
c
*
WrapperClient
)
Get
(
url
string
,
res
interface
{},
needAuth
bool
)
error
{
if
needAuth
{
c
.
Http
.
SetAuth
(
c
.
Auth
.
Sign
())
}
else
{
c
.
Http
.
SetAuth
(
""
)
}
return
c
.
Http
.
Get
(
c
.
BaseHost
+
url
,
res
)
}
func
(
c
*
WrapperClient
)
Post
(
url
string
,
data
interface
{},
res
interface
{},
needAuth
bool
)
error
{
if
needAuth
{
c
.
Http
.
SetAuth
(
c
.
Auth
.
Sign
())
}
else
{
c
.
Http
.
SetAuth
(
""
)
}
return
c
.
Http
.
Post
(
url
,
data
,
res
)
}
func
(
c
*
WrapperClient
)
Delete
(
url
string
,
res
interface
{},
needAuth
bool
)
error
{
if
needAuth
{
c
.
Http
.
SetAuth
(
c
.
Auth
.
Sign
())
}
else
{
c
.
Http
.
SetAuth
(
""
)
}
return
c
.
Http
.
Delete
(
url
,
res
)
}
func
(
c
*
WrapperClient
)
Put
(
url
string
,
data
interface
{},
res
interface
{},
needAuth
bool
)
error
{
if
needAuth
{
c
.
Http
.
SetAuth
(
c
.
Auth
.
Sign
())
}
else
{
c
.
Http
.
SetAuth
(
""
)
}
return
c
.
Http
.
Put
(
url
,
data
,
res
)
}
func
(
c
*
WrapperClient
)
Patch
(
url
string
,
data
interface
{},
res
interface
{},
needAuth
bool
)
error
{
if
needAuth
{
c
.
Http
.
SetAuth
(
c
.
Auth
.
Sign
())
}
else
{
c
.
Http
.
SetAuth
(
""
)
}
return
c
.
Http
.
Patch
(
url
,
data
,
res
)
}
pkg/sdk/init.go
deleted
100644 → 0
View file @
3198cb2a
package
sdk
var
Client
=
WrapperClient
{}
func
init
()
{
//err := Client.LoadAuth()
//if err != nil {
// logger.Error("Load client access key error: %s", err)
// os.Exit(10)
//}
//err = Client.CheckAuth()
//if err != nil {
// logger.Error("Check client auth error: %s", err)
// os.Exit(11)
//}
}
pkg/sdk/urls.go
View file @
c9ebf9bd
package
sdk
var
urls
=
map
[
string
]
string
{
"UserAuthUrl"
:
"/api/users/v1/auth/"
,
// post 验证用户登陆
"UserProfileUrl"
:
"/api/users/v1/profile/"
,
// 获取当前用户的基本信息
const
(
UserAuthURL
=
"/api/users/v1/auth/"
// post 验证用户登陆
UserProfileURL
=
"/api/users/v1/profile/"
// 获取当前用户的基本信息
"SystemUserAssetAuthUrl"
:
"/api/assets/v1/system-user/%s/asset/%s/auth-info/"
,
// 该系统用户对某资产的授权
"SystemUserAuthInfo"
:
"/api/assets/v1/system-user/%s/auth-info/"
,
// 该系统用户的授权
SystemUserAssetAuthURL
=
"/api/assets/v1/system-user/%s/asset/%s/auth-info/"
// 该系统用户对某资产的授权
SystemUserAuthInfoURL
=
"/api/assets/v1/system-user/%s/auth-info/"
// 该系统用户的授权
"TerminalRegisterUrl"
:
"/api/terminal/v2/terminal-registrations/"
,
// 注册当前coco
"TerminalConfigUrl"
:
"/api/terminal/v1/terminal/config/"
,
// 从jumpserver获取coco的配置
"SessionList"
:
"/api/terminal/v1/sessions/"
,
//上传创建的资产会话session id
"SessionDetail"
:
"/api/terminal/v1/sessions/%s/"
,
// finish session的时候发送
"SessionReplay"
:
"/api/terminal/v1/sessions/%s/replay/"
,
//上传录像
TerminalRegisterURL
=
"/api/terminal/v2/terminal-registrations/"
// 注册当前coco
TerminalConfigURL
=
"/api/terminal/v1/terminal/config/"
// 从jumpserver获取coco的配置
SessionListURL
=
"/api/terminal/v1/sessions/"
//上传创建的资产会话session id
SessionDetailURL
=
"/api/terminal/v1/sessions/%s/"
// finish session的时候发送
SessionReplayURL
=
"/api/terminal/v1/sessions/%s/replay/"
//上传录像
"UserAssetsUrl"
:
"/api/perms/v1/user/%s/assets/"
,
//获取用户授权的所有资产
"UserNodesAssetsUrl"
:
"/api/perms/v1/user/%s/nodes-assets/"
,
// 获取用户授权的所有节点信息 节点分组
"ValidateUserAssetPermission"
:
"/api/perms/v1/asset-permission/user/validate/"
,
//0不使用缓存 1 使用缓存 2 刷新缓存
}
UserAssetsURL
=
"/api/perms/v1/user/%s/assets/"
//获取用户授权的所有资产
UserNodesAssetsURL
=
"/api/perms/v1/user/%s/nodes-assets/"
// 获取用户授权的所有节点信息 节点分组
ValidateUserAssetPermissionURL
=
"/api/perms/v1/asset-permission/user/validate/"
//0不使用缓存 1 使用缓存 2 刷新缓存
)
pkg/sdk/users.go
View file @
c9ebf9bd
package
sdk
import
"cocogo/pkg/model"
func
CheckAuth
(
username
,
password
,
publicKey
,
remoteAddr
,
loginType
string
)
(
user
model
.
User
,
err
error
)
{
func
CheckAuth
(
username
,
password
,
publicKey
,
remoteAddr
,
loginType
string
)
(
user
User
,
err
error
)
{
return
user
,
nil
}
...
...
pkg/service/assets.go
0 → 100644
View file @
c9ebf9bd
package
service
import
(
"cocogo/pkg/sdk"
)
func
GetSystemUserAssetAuthInfo
(
systemUserID
,
assetID
string
)
(
info
sdk
.
SystemUserAuthInfo
)
{
return
}
func
GetSystemUserAuthInfo
(
systemUserID
string
)
(
info
sdk
.
SystemUserAuthInfo
)
{
return
}
pkg/service/terminal.go
0 → 100644
View file @
c9ebf9bd
package
service
func
registerTerminal
(
name
string
)
{
}
func
CreateServiceAccount
()
{
}
func
CreateSession
()
{
}
func
FinishSession
()
{
}
func
PushSessionReplay
(
sessionID
,
gZipFile
string
)
{
}
func
FinishReply
()
{
}
pkg/service/users.go
View file @
c9ebf9bd
package
service
import
"cocogo/pkg/sdk"
func
Authenticate
(
username
,
password
,
public_key
,
remote_addr
,
login_type
string
)
{
return
}
func
GetUserProfile
(
userId
string
)
(
user
sdk
.
User
)
{
return
}
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