[agent-go] [Bastion] - basic accomplished !
This commit is contained in:
49
agent-go/a_init/bastion_init/123.txt
Normal file
49
agent-go/a_init/bastion_init/123.txt
Normal file
@@ -0,0 +1,49 @@
|
||||
hostname: HarborHostName
|
||||
|
||||
http:
|
||||
port: 8033
|
||||
|
||||
harbor_admin_password: HarborAdminPas
|
||||
|
||||
database:
|
||||
password: HarborAdminPas
|
||||
max_idle_conns: 50
|
||||
max_open_conns: 1000
|
||||
conn_max_lifetime: 3600
|
||||
conn_max_idle_time: 3600
|
||||
|
||||
data_volume: /var/lib/docker/harbor-data
|
||||
|
||||
jobservice:
|
||||
max_job_workers: 10
|
||||
job_loggers:
|
||||
- STD_OUTPUT
|
||||
- FILE
|
||||
logger_sweeper_duration: 3
|
||||
|
||||
notification:
|
||||
webhook_job_max_retry: 10
|
||||
webhook_job_http_client_timeout: 10
|
||||
|
||||
|
||||
log:
|
||||
level: warning
|
||||
local:
|
||||
rotate_count: 50
|
||||
rotate_size: 200M
|
||||
location: /var/log/harbor
|
||||
|
||||
cache:
|
||||
enabled: false
|
||||
expire_hours: 24
|
||||
|
||||
_version: 2.9.0
|
||||
|
||||
proxy:
|
||||
http_proxy:
|
||||
https_proxy:
|
||||
no_proxy:
|
||||
components:
|
||||
- core
|
||||
- jobservice
|
||||
- trivy
|
||||
14
agent-go/a_init/bastion_init/BastionHelp.go
Normal file
14
agent-go/a_init/bastion_init/BastionHelp.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package bastion_init
|
||||
|
||||
import "fmt"
|
||||
|
||||
var BastionFunctionList []string
|
||||
|
||||
func PrintBastionHelp() {
|
||||
fmt.Println()
|
||||
fmt.Println("Bastion Mode Supported Commands:")
|
||||
for i, s := range BastionFunctionList {
|
||||
fmt.Printf("\t%d. %s\n", i+1, s)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package bastion_init
|
||||
@@ -1,91 +0,0 @@
|
||||
package bastion_init
|
||||
|
||||
import "strings"
|
||||
|
||||
// 假设我们的预定义字符串列表存储在这个map中,键为字符串索引,值为字符串本身
|
||||
var dictionary = map[string]struct{}{
|
||||
"apple": {},
|
||||
"apply": {},
|
||||
"apron": {},
|
||||
"docker": {},
|
||||
"docker-compose": {},
|
||||
"harbor": {},
|
||||
// ...其他词汇
|
||||
}
|
||||
|
||||
// normalize 将字符串转换为小写并去除特殊符号
|
||||
func normalize(s string) string {
|
||||
return strings.ToLower(strings.ReplaceAll(s, "\\W", ""))
|
||||
}
|
||||
|
||||
// findBestMatch 在字典中找到最合适的单词
|
||||
func findBestMatch(query string) string {
|
||||
normQuery := normalize(query)
|
||||
|
||||
// 将查询字符串排序,以便二分查找
|
||||
sortedQuery := []rune(normQuery)
|
||||
|
||||
var bestMatch string
|
||||
minDistance := len(dictionary) + 1 // 最初假设没有匹配项
|
||||
|
||||
// 遍历字典中的所有单词
|
||||
for word, _ := range dictionary {
|
||||
normWord := normalize(word)
|
||||
distance := levenshteinDistance(sortedQuery, []rune(normWord)) // 计算编辑距离
|
||||
|
||||
// 如果当前单词的编辑距离小于等于最佳匹配的距离,并且它是第一个匹配项(或者距离相同但字典序更低)
|
||||
if distance <= minDistance || (distance == minDistance && strings.ToLower(word) < normQuery) {
|
||||
minDistance = distance
|
||||
bestMatch = word
|
||||
}
|
||||
}
|
||||
|
||||
return bestMatch
|
||||
}
|
||||
|
||||
// levenshteinDistance 计算两个字符串之间的编辑距离(插入、删除或替换一个字符的次数)
|
||||
func levenshteinDistance(a, b []rune) int {
|
||||
lenA := len(a)
|
||||
lenB := len(b)
|
||||
|
||||
dist := make([][]int, lenA+1)
|
||||
for i := range dist {
|
||||
dist[i] = make([]int, lenB+1)
|
||||
}
|
||||
|
||||
for i := 0; i <= lenA; i++ {
|
||||
dist[i][0] = i
|
||||
}
|
||||
for j := 0; j <= lenB; j++ {
|
||||
dist[0][j] = j
|
||||
}
|
||||
|
||||
for i := 1; i <= lenA; i++ {
|
||||
for j := 1; j <= lenB; j++ {
|
||||
cost := int(a[i-1] - b[j-1])
|
||||
dist[i][j] = minInt(dist[i-1][j]+1, dist[i][j-1]+1, dist[i-1][j-1]+cost)
|
||||
}
|
||||
}
|
||||
|
||||
return dist[lenA][lenB]
|
||||
}
|
||||
|
||||
// minInt 找到三个整数中的最小值
|
||||
func minInt(a, b, c int) int {
|
||||
if a < b {
|
||||
if a < c {
|
||||
return a
|
||||
}
|
||||
return c
|
||||
}
|
||||
if b < c {
|
||||
return b
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func main() {
|
||||
query := "app!"
|
||||
bestMatch := findBestMatch(query)
|
||||
println("The best match for", query, "is:", bestMatch)
|
||||
}
|
||||
@@ -33,7 +33,10 @@ func (tn *TrieNode) Insert(word string) {
|
||||
}
|
||||
|
||||
func (t *Trie) Insert(word string) {
|
||||
// insert word into trie
|
||||
t.root.Insert(word)
|
||||
// insert to AllFunction List
|
||||
BastionFunctionList = append(BastionFunctionList, word)
|
||||
}
|
||||
func (t *Trie) InsertAll(words []string) {
|
||||
for _, word := range words {
|
||||
|
||||
@@ -2,7 +2,6 @@ package bastion_init
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -22,37 +21,5 @@ func TestNewTrie(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDp(t *testing.T) {
|
||||
// 获取netlink接口(用于网络控制的内核机制)
|
||||
nl := syscall.NewLk(syscall.AT_FDCWD, "netlink")
|
||||
if nl == nil {
|
||||
fmt.Println("Unable to open netlink")
|
||||
return
|
||||
}
|
||||
defer nl.Close()
|
||||
|
||||
// 设置对netlink的访问权限
|
||||
if err := syscall.Setpgid(0, syscall.Getpid()); err != nil {
|
||||
fmt.Println("Unable to set pgid", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 设置netlink接口为非阻塞模式
|
||||
if err := nl.Control(syscall.SET_NONBLOCK, 1); err != nil {
|
||||
fmt.Println("Unable to set netlink nonblocking", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取IPv4路由转发设置的值
|
||||
var value syscall.SysctlValInt
|
||||
if err := syscall.Sysctl(nl, "net/ipv4/ip_forward", &value); err != nil {
|
||||
fmt.Println("Unable to get ip_forward value:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// 打印IPv4路由转发的状态
|
||||
if value == 1 {
|
||||
fmt.Println("IPv4 routing forwarding is enabled")
|
||||
} else {
|
||||
fmt.Println("IPv4 routing forwarding is disabled")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package bastion_init
|
||||
|
||||
func PrintBastionHelp() {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user