Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add keyscan knowhosts #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (f *Git) Create(c *gin.Context) {
return
}
// create git to k8s
err = f.k8sc.CreateGitSSH(ginheader.MutateContext(c), r.KnownHosts, r.SSH)
err = f.k8sc.CreateGitSSH(ginheader.MutateContext(c), r.KnownHosts, r.KeyScanKnownHosts, r.SSH)
if err != nil {
resp.Format(res, err).Context(c)
return
Expand Down
3 changes: 1 addition & 2 deletions api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
mysql2 "github.com/quanxiang-cloud/cabin/tailormade/db/mysql"
redis2 "github.com/quanxiang-cloud/cabin/tailormade/db/redis"

"github.com/quanxiang-cloud/faas/pkg/basic/define/consts"
"github.com/quanxiang-cloud/faas/pkg/basic/event"
"github.com/quanxiang-cloud/faas/pkg/basic/k8s"

Expand Down Expand Up @@ -45,7 +44,7 @@ func NewRouter(ctx context.Context, c *config.Config, log logger.AdaptedLogger)
if err != nil {
return nil, err
}
k8sClient := k8s.NewClient(c, consts.BuildNamespace)
k8sClient := k8s.NewClient(c)

engine, err := newRouter(c)
if err != nil {
Expand Down
142 changes: 70 additions & 72 deletions configs/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ mysql:
log: true

docker:
namespace: faas
builder: builder
serving: serving



# ---------- redis ----------
Expand All @@ -59,82 +61,78 @@ graph:
- build-trusted
- push
steps:
-
- start
-
- clone
-
- prepare
- - start
- - clone
- - prepare
- create
-
- push
- - push

build-images:
go1.16: qxcr.xyz/faas/build-go:v1alpha1

templates:
- full_name: handle.go
branch: master
commit: init repo
content: |
package handle

import (
"fmt"
"net/http"

"github.com/quanxiang-cloud/faas-lowcode-interface/lowcode"
)

type Request struct {
Foo string
}

type Response struct {
Bar string
}

// Handler function as a server handler
// @tags handler
// @Summary TODO: write your function name
// @Description handler description
// @Produce json
// @Param request body Request true "request"
// @Success 200 {object} Response
// @Router / [post]
func Handle(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
_, ok := ctx.Value(lowcode.LOWCODE).(lowcode.Lowcode)
if !ok {
return
templates:
- full_name: handle.go
branch: master
commit: init repo
content: |
package handle

import (
"fmt"
"net/http"

"github.com/quanxiang-cloud/faas-lowcode-interface/lowcode"
)

type Request struct {
Foo string
}

type Response struct {
Bar string
}

// Handler function as a server handler
// @tags handler
// @Summary TODO: write your function name
// @Description handler description
// @Produce json
// @Param request body Request true "request"
// @Success 200 {object} Response
// @Router / [post]
func Handle(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
_, ok := ctx.Value(lowcode.LOWCODE).(lowcode.Lowcode)
if !ok {
return
}

// code there
w.Write([]byte("hello faas!"))
}

// code there
w.Write([]byte("hello faas!"))
}

- full_name: go.mod
branch: master
commit: init repo
content: |
module quanxiang.lowcode/faas

go 1.16

require github.com/quanxiang-cloud/faas-lowcode-interface v0.0.0-20220505034554-fae42a4892ad

- full_name: go.sum
branch: master
commit: init repo
content: |
github.com/quanxiang-cloud/faas-lowcode-interface v0.0.0-20220505034554-fae42a4892ad h1:ynmSpZkZf8oGV6EhEXfiQY5Wy9lrTJxBw/g6WH8KlZw=
github.com/quanxiang-cloud/faas-lowcode-interface v0.0.0-20220505034554-fae42a4892ad/go.mod h1:rwhMXhcV96F1l+frwbgqazzepMTwRC1f0HaFEPNHscQ=

- full_name: info.faas
branch: master
commit: init repo
content: |
projectName: demo
language: go
version: 1.16
- full_name: go.mod
branch: master
commit: init repo
content: |
module quanxiang.lowcode/faas

go 1.16

require github.com/quanxiang-cloud/faas-lowcode-interface v0.0.0-20220505034554-fae42a4892ad

- full_name: go.sum
branch: master
commit: init repo
content: |
github.com/quanxiang-cloud/faas-lowcode-interface v0.0.0-20220505034554-fae42a4892ad h1:ynmSpZkZf8oGV6EhEXfiQY5Wy9lrTJxBw/g6WH8KlZw=
github.com/quanxiang-cloud/faas-lowcode-interface v0.0.0-20220505034554-fae42a4892ad/go.mod h1:rwhMXhcV96F1l+frwbgqazzepMTwRC1f0HaFEPNHscQ=

- full_name: info.faas
branch: master
commit: init repo
content: |
projectName: demo
language: go
version: 1.16

44 changes: 29 additions & 15 deletions internal/logic/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ func NewGit(c context.Context, db *gorm.DB) Git {
}

type CreateGitRequest struct {
Host string `json:"host"`
KnownHosts string `json:"knownHosts"`
Token string `json:"token"`
SSH string `json:"ssh"`
Host string `json:"host"`
KnownHosts string `json:"knownHosts"`
KeyScanKnownHosts string `json:"keyScanKnownHosts"`
Token string `json:"token"`
SSH string `json:"ssh"`
}
type CreateGitResponse struct {
}
Expand All @@ -52,16 +53,20 @@ func (g *git) Create(c context.Context, r *CreateGitRequest) (*CreateGitResponse
data.Token = r.Token
data.SSH = r.SSH
data.KnownHosts = r.KnownHosts
data.KeyScanKnownHosts = r.KeyScanKnownHosts
unix := time.NowUnix()
data.CreatedAt = unix
data.UpdatedAt = unix
return &CreateGitResponse{}, g.gitRepo.Insert(c, g.db, data)
}

type UpdateGitRequest struct {
ID string `json:"id"`
Host string `json:"host"`
Token string `json:"token"`
ID string `json:"id"`
Host string `json:"host"`
Token string `json:"token"`
SSH string `json:"ssh"`
KnownHosts string `json:"knownHosts"`
KeyScanKnownHosts string `json:"keyScanKnownHosts"`
}
type UpdateGitResponse struct {
}
Expand All @@ -73,6 +78,9 @@ func (g *git) Update(c context.Context, r *UpdateGitRequest) (*UpdateGitResponse
}
data.Host = r.Host
data.Token = r.Token
data.SSH = r.SSH
data.KnownHosts = r.KnownHosts
data.KeyScanKnownHosts = r.KeyScanKnownHosts
unix := time.NowUnix()
data.UpdatedAt = unix
return &UpdateGitResponse{}, g.gitRepo.Update(c, g.db, data)
Expand All @@ -95,10 +103,13 @@ func (g *git) Delete(c context.Context, r *DeleteGitRequest) (*DeleteGitResponse
type GetGitRequest struct {
}
type GetGitResponse struct {
ID string `json:"id"`
Host string `json:"host"`
Token string `json:"token"`
UpdatedAt int64 `json:"updatedAt"`
ID string `json:"id"`
Host string `json:"host"`
Token string `json:"token"`
UpdatedAt int64 `json:"updatedAt"`
SSH string `json:"ssh"`
KnownHosts string `json:"knownHosts"`
KeyScanKnownHosts string `json:"keyScanKnownHosts"`
}

func (g *git) Get(c context.Context, r *GetGitRequest) (*GetGitResponse, error) {
Expand All @@ -107,10 +118,13 @@ func (g *git) Get(c context.Context, r *GetGitRequest) (*GetGitResponse, error)
return nil, nil
}
res := &GetGitResponse{
ID: data.ID,
Host: data.Host,
Token: data.Token,
UpdatedAt: data.UpdatedAt,
ID: data.ID,
Host: data.Host,
Token: data.Token,
UpdatedAt: data.UpdatedAt,
SSH: data.SSH,
KnownHosts: data.KnownHosts,
KeyScanKnownHosts: data.KeyScanKnownHosts,
}
return res, nil

Expand Down
3 changes: 1 addition & 2 deletions internal/logic/serving.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/quanxiang-cloud/faas/internal/models"
"github.com/quanxiang-cloud/faas/internal/models/mysql"
"github.com/quanxiang-cloud/faas/pkg/basic/define/code"
"github.com/quanxiang-cloud/faas/pkg/basic/define/consts"
"github.com/quanxiang-cloud/faas/pkg/basic/k8s"
"github.com/quanxiang-cloud/faas/pkg/config"
"gorm.io/gorm"
Expand Down Expand Up @@ -40,7 +39,7 @@ func NewServing(db *gorm.DB, log logger.AdaptedLogger, conf *config.Config) Serv
dockerRepo: mysql.NewDockerRepo(),
projectRepo: mysql.NewProjectRepo(),
groupRepo: mysql.NewGroupRepo(),
k8sc: k8s.NewClient(conf, consts.ServingNamespace),
k8sc: k8s.NewClient(conf),
log: log,
}
}
Expand Down
13 changes: 7 additions & 6 deletions internal/models/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
)

type Git struct {
ID string `gorm:"column:id;type:varchar(64);PRIMARY_KEY" json:"id"`
Host string `gorm:"column:host;type:varchar(200);" json:"host"`
KnownHosts string `gorm:"column:known_hosts;type:text;" json:"knownHosts"`
SSH string `gorm:"column:ssh;type:text;" json:"ssh"`
Token string `gorm:"column:token;type:text;" json:"token"`
Name string `gorm:"column:name;type:varchar(200);" json:"name"`
ID string `gorm:"column:id;type:varchar(64);PRIMARY_KEY" json:"id"`
Host string `gorm:"column:host;type:varchar(200);" json:"host"`
KnownHosts string `gorm:"column:known_hosts;type:text;" json:"knownHosts"`
KeyScanKnownHosts string `gorm:"column:key_scan_known_hosts;type:text;" json:"keyScanKnownHosts"`
SSH string `gorm:"column:ssh;type:text;" json:"ssh"`
Token string `gorm:"column:token;type:text;" json:"token"`
Name string `gorm:"column:name;type:varchar(200);" json:"name"`

CreatedAt int64 `gorm:"column:created_at;type:bigint; " json:"createdAt,omitempty" `
UpdatedAt int64 `gorm:"column:updated_at;type:bigint; " json:"updatedAt,omitempty" `
Expand Down
Loading