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
ff668f96
Commit
ff668f96
authored
May 04, 2019
by
Eric
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[update] validate or register access key
parent
f1da5e13
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
7 deletions
+65
-7
coco.go
cmd/coco.go
+2
-0
terminal.go
pkg/model/terminal.go
+1
-1
accesskey.go
pkg/service/accesskey.go
+23
-1
init.go
pkg/service/init.go
+26
-2
terminal.go
pkg/service/terminal.go
+11
-1
session.go
pkg/sshd/handler/session.go
+2
-2
No files found.
cmd/coco.go
View file @
ff668f96
...
...
@@ -2,6 +2,7 @@ package main
import
(
"cocogo/pkg/config"
"cocogo/pkg/service"
"cocogo/pkg/sshd"
)
...
...
@@ -10,5 +11,6 @@ func init() {
}
func
main
()
{
service
.
Initial
()
sshd
.
StartServer
()
}
pkg/model/terminal.go
View file @
ff668f96
...
...
@@ -9,7 +9,7 @@ type Terminal struct {
AccessKey
struct
{
Id
string
`json:"id"`
Secret
string
`json:"secret"`
}
}
`json:"access_key"`
}
`json:"service_account"`
}
...
...
pkg/service/accesskey.go
View file @
ff668f96
...
...
@@ -8,6 +8,7 @@ import (
"strings"
"cocogo/pkg/common"
"cocogo/pkg/config"
"cocogo/pkg/logger"
)
...
...
@@ -60,10 +61,31 @@ func (ak *AccessKey) LoadAccessKeyFromFile(keyPath string) error {
}
func
(
ak
*
AccessKey
)
SaveToFile
()
error
{
return
nil
f
,
err
:=
os
.
Create
(
ak
.
Path
)
defer
f
.
Close
()
if
err
!=
nil
{
return
err
}
_
,
err
=
f
.
WriteString
(
fmt
.
Sprintf
(
"%s:%s"
,
ak
.
Id
,
ak
.
Secret
))
if
err
!=
nil
{
logger
.
Error
(
err
)
}
return
err
}
func
(
ak
*
AccessKey
)
Register
(
times
int
)
error
{
name
:=
config
.
Conf
.
Name
token
:=
config
.
Conf
.
BootstrapToken
comment
:=
"Coco"
res
:=
RegisterTerminal
(
name
,
token
,
comment
)
if
res
.
Name
!=
name
{
msg
:=
"register access key failed"
logger
.
Error
(
msg
)
os
.
Exit
(
1
)
}
ak
.
Id
=
res
.
ServiceAccount
.
AccessKey
.
Id
ak
.
Secret
=
res
.
ServiceAccount
.
AccessKey
.
Secret
return
nil
}
...
...
pkg/service/init.go
View file @
ff668f96
package
service
import
(
"cocogo/pkg/common"
"cocogo/pkg/config"
"os"
"path"
"path/filepath"
"time"
"cocogo/pkg/common"
"cocogo/pkg/config"
"cocogo/pkg/logger"
)
var
client
=
common
.
NewClient
(
30
,
""
)
...
...
@@ -21,4 +25,24 @@ func Initial() {
ak
:=
AccessKey
{
Value
:
config
.
Conf
.
AccessKey
,
Path
:
keyPath
}
_
=
ak
.
Load
()
authClient
.
Auth
=
ak
ValidateAccessAuth
()
}
func
ValidateAccessAuth
()
{
count
:=
0
for
count
<
100
{
user
:=
getTerminalProfile
()
if
user
.
Id
!=
""
{
break
}
msg
:=
`Connect server error or access key is invalid,
remove %s run again`
logger
.
Errorf
(
msg
,
config
.
Conf
.
AccessKeyFile
)
time
.
Sleep
(
3
*
time
.
Second
)
count
++
if
count
>=
3
{
os
.
Exit
(
1
)
}
}
}
pkg/service/terminal.go
View file @
ff668f96
...
...
@@ -13,8 +13,18 @@ func RegisterTerminal(name, token, comment string) (res model.Terminal) {
}
client
.
Headers
[
"Authorization"
]
=
fmt
.
Sprintf
(
"BootstrapToken %s"
,
token
)
data
:=
map
[
string
]
string
{
"name"
:
name
,
"comment"
:
comment
}
Url
:=
client
.
ParseUrlQuery
(
TerminalRegisterURL
,
nil
)
err
:=
client
.
Post
(
Url
,
data
,
&
res
)
if
err
!=
nil
{
logger
.
Error
(
err
)
}
return
}
func
getTerminalProfile
()
(
user
model
.
User
)
{
Url
:=
authClient
.
ParseUrlQuery
(
UserProfileURL
,
nil
)
err
:=
client
.
Post
(
TerminalRegisterURL
,
data
,
&
res
)
err
:=
authClient
.
Get
(
Url
,
&
user
)
if
err
!=
nil
{
logger
.
Error
(
err
)
}
...
...
pkg/sshd/handler/session.go
View file @
ff668f96
...
...
@@ -245,11 +245,11 @@ func (i *InteractiveHandler) refreshAssetsAndNodesData() {
}
func
(
i
*
InteractiveHandler
)
loadUserAssets
()
{
i
.
assets
=
service
.
GetUserAssets
(
i
.
user
.
Id
)
i
.
assets
=
service
.
GetUserAssets
(
i
.
user
.
Id
,
"1"
)
}
func
(
i
*
InteractiveHandler
)
loadUserAssetNodes
()
{
i
.
nodes
=
service
.
GetUserNodes
(
i
.
user
.
Id
)
i
.
nodes
=
service
.
GetUserNodes
(
i
.
user
.
Id
,
"1"
)
}
func
(
i
*
InteractiveHandler
)
changeLanguage
()
{
...
...
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