Skip to content

Commit

Permalink
fix(climc): enable build windows climc (#20120)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioito authored Apr 24, 2024
1 parent d8ae463 commit 974f884
Show file tree
Hide file tree
Showing 19 changed files with 309 additions and 135 deletions.
43 changes: 39 additions & 4 deletions cmd/climc/shell/compute/sshkeypairs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ import (
"fmt"
"os"
"path"
"strings"

"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"

"yunion.io/x/onecloud/pkg/hostman/guestfs/fsdriver"
deployapi "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
"yunion.io/x/onecloud/pkg/mcclient"
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
"yunion.io/x/onecloud/pkg/util/procutils"
Expand Down Expand Up @@ -101,8 +100,44 @@ func init() {
}
oldKeys = string(output)
}
pubKeys := &deployapi.SSHKeys{AdminPublicKey: pubKey}
newKeys := fsdriver.MergeAuthorizedKeys(oldKeys, pubKeys, true)
var MergeAuthorizedKeys = func(oldKeys string, pubKey string) string {
const sshKeySignature = "@yunioncloudpods"
var allkeys = make(map[string]string)
if len(oldKeys) > 0 {
for _, line := range strings.Split(oldKeys, "\n") {
line = strings.TrimSpace(line)
dat := strings.Split(line, " ")
if len(dat) > 1 {
if len(dat) > 2 && dat[2] == sshKeySignature {
// skip ssh keys with signature
continue
}
if _, ok := allkeys[dat[1]]; !ok {
allkeys[dat[1]] = line
}
}
}
}
candiateKeys := []string{pubKey}
for _, k := range candiateKeys {
if len(k) > 0 {
k = strings.TrimSpace(k)
dat := strings.Split(k, " ")
if len(dat) > 1 {
if _, ok := allkeys[dat[1]]; !ok {
allkeys[dat[1]] = strings.Join([]string{dat[0], dat[1], sshKeySignature}, " ")
}
}
}
}
var keys = make([]string, 0)
for _, val := range allkeys {
keys = append(keys, val)
}
return strings.Join(keys, "\n") + "\n"
}

newKeys := MergeAuthorizedKeys(oldKeys, pubKey)
if output, err := procutils.NewCommand(
"sh", "-c", fmt.Sprintf("echo '%s' > %s", newKeys, authFile)).Output(); err != nil {
return errors.Wrapf(err, "write public keys: %s", output)
Expand Down
4 changes: 2 additions & 2 deletions cmd/climc/shell/misc/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import (

"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/netutils"
"yunion.io/x/pkg/util/signalutils"

"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/util/netutils2"
"yunion.io/x/onecloud/pkg/util/procutils"
)

Expand Down Expand Up @@ -125,7 +125,7 @@ func init() {
} {
pType := kind
R(&TraceOptions{}, fmt.Sprintf("pprof-%s", pType), fmt.Sprintf("pprof %s of backend service", pType), func(s *mcclient.ClientSession, args *TraceOptions) error {
port, err := netutils2.GetFreePort()
port, err := netutils.GetFreePort()
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ require (
github.com/tjfoc/gmsm v1.4.1
github.com/tredoe/osutil/v2 v2.0.0-rc.16
github.com/vishvananda/netlink v1.1.0
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74
github.com/vishvananda/netns v0.0.5-0.20240412164733-9469873f4601
github.com/vmihailenco/msgpack v4.0.4+incompatible
github.com/xuri/excelize/v2 v2.7.1
github.com/zexi/influxql-to-metricsql v0.0.6
Expand Down Expand Up @@ -98,7 +98,7 @@ require (
yunion.io/x/jsonutils v1.0.1-0.20240203102553-4096f103b401
yunion.io/x/log v1.0.1-0.20240305175729-7cf2d6cd5a91
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900
yunion.io/x/pkg v1.10.1-0.20240416041628-5e17b8728132
yunion.io/x/pkg v1.10.1-0.20240424071144-ff6b95d2046d
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e
yunion.io/x/sqlchemy v1.1.3-0.20240417115142-4f4271cd8305
yunion.io/x/structarg v0.0.0-20231017124457-df4d5009457c
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,8 @@ github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLY
github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0=
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 h1:gga7acRE695APm9hlsSMoOoE65U4/TcqNj90mc69Rlg=
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/vishvananda/netns v0.0.5-0.20240412164733-9469873f4601 h1:eELqkILRCR0kkoFujWv/hGyn+KfpGjHY01Rl1p42CBg=
github.com/vishvananda/netns v0.0.5-0.20240412164733-9469873f4601/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmware/govmomi v0.20.1 h1:7b/SeTUB3tER8ZLGLLLH3xcnB2xeuLULXmfPFqPSRZA=
Expand Down Expand Up @@ -938,7 +938,6 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -1237,8 +1236,8 @@ yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900 h1:Hu/4ERvoWaN6aiFs4h4/yvVB
yunion.io/x/ovsdb v0.0.0-20230306173834-f164f413a900/go.mod h1:0vLkNEhlmA64HViPBAnSTUMrx5QP1CLsxXmxDKQ80tc=
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v1.10.1-0.20240416041628-5e17b8728132 h1:+7rO5MAfU4BNvYPim0MhgN1/zO6KTyUk37HC4pYcqPE=
yunion.io/x/pkg v1.10.1-0.20240416041628-5e17b8728132/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk=
yunion.io/x/pkg v1.10.1-0.20240424071144-ff6b95d2046d h1:kl78atYnRcYjVeo/TjMXNMJL5F5N9rnqVHwpQXrG/yc=
yunion.io/x/pkg v1.10.1-0.20240424071144-ff6b95d2046d/go.mod h1:ksCJVQ+DwKrJ5QBEoU8pzrDFfDaZVAFH/iJ6yQCYxJk=
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e h1:v+EzIadodSwkdZ/7bremd7J8J50Cise/HCylsOJngmo=
yunion.io/x/s3cli v0.0.0-20190917004522-13ac36d8687e/go.mod h1:0iFKpOs1y4lbCxeOmq3Xx/0AcQoewVPwj62eRluioEo=
yunion.io/x/sqlchemy v1.1.3-0.20240417115142-4f4271cd8305 h1:TIXzc634+YSAs2+3A+TyPmKAGd6HtAYU3M4cKwzUuo0=
Expand Down
4 changes: 2 additions & 2 deletions pkg/mcclient/aksk.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (

"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/netutils"
"yunion.io/x/pkg/util/s3auth"

api "yunion.io/x/onecloud/pkg/apis/identity"
"yunion.io/x/onecloud/pkg/util/netutils2"
)

type SAkskTokenCredential struct {
Expand Down Expand Up @@ -59,7 +59,7 @@ func (this *Client) _verifyKeySecret(aksk s3auth.IAccessKeySecretRequest, aCtx S
}

func (this *Client) VerifyRequest(req http.Request, aksk s3auth.IAccessKeySecretRequest, virtualHost bool) (*SAkskTokenCredential, error) {
cliIp := netutils2.GetHttpRequestIp(&req)
cliIp := netutils.GetHttpRequestIp(&req)
aCtx := SAuthContext{
Source: AuthSourceSrv,
Ip: cliIp,
Expand Down
21 changes: 3 additions & 18 deletions pkg/util/netutils2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,10 @@ package netutils2

import (
"net/http"
"strings"

"yunion.io/x/pkg/util/netutils"
)

func GetHttpRequestIp(r *http.Request) string {
ipStr := r.Header.Get("X-Forwarded-For")
if len(ipStr) > 0 {
ipList := strings.Split(ipStr, ",")
if len(ipList) > 0 {
return ipList[0]
}
}
ipStr = r.Header.Get("X-Real-Ip")
if len(ipStr) > 0 {
return ipStr
}
ipStr = r.RemoteAddr
colonPos := strings.Index(ipStr, ":")
if colonPos > 0 {
ipStr = ipStr[:colonPos]
}
return ipStr
return netutils.GetHttpRequestIp(r)
}
File renamed without changes.
30 changes: 30 additions & 0 deletions pkg/util/procutils/cmdsetenv_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build windows
// +build windows

package procutils

import (
"os/exec"

"yunion.io/x/executor/client"
)

func cmdSetEnv(cmd *exec.Cmd) {
}

func remoteCmdSetEnv(cmd *client.Cmd) {
}
26 changes: 26 additions & 0 deletions vendor/github.com/vishvananda/netns/.golangci.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions vendor/github.com/vishvananda/netns/.yamllint.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions vendor/github.com/vishvananda/netns/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions vendor/github.com/vishvananda/netns/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 974f884

Please sign in to comment.