diff --git a/api/client/lambda_api_client.go b/api/client/lambda_api_client.go index 0afe5bc..7498212 100755 --- a/api/client/lambda_api_client.go +++ b/api/client/lambda_api_client.go @@ -4,7 +4,6 @@ import ( "context" client "github.com/reddec/jsonrpc2/client" api "github.com/reddec/trusted-cgi/api" - application "github.com/reddec/trusted-cgi/application" stats "github.com/reddec/trusted-cgi/stats" types "github.com/reddec/trusted-cgi/types" "sync/atomic" @@ -56,13 +55,13 @@ func (impl *LambdaAPIClient) Files(ctx context.Context, token *api.Token, uid st } // Info about application -func (impl *LambdaAPIClient) Info(ctx context.Context, token *api.Token, uid string) (reply *application.App, err error) { +func (impl *LambdaAPIClient) Info(ctx context.Context, token *api.Token, uid string) (reply *types.App, err error) { err = client.CallHTTP(ctx, impl.BaseURL, "LambdaAPI.Info", atomic.AddUint64(&impl.sequence, 1), &reply, token, uid) return } // Update application manifest -func (impl *LambdaAPIClient) Update(ctx context.Context, token *api.Token, uid string, manifest types.Manifest) (reply *application.App, err error) { +func (impl *LambdaAPIClient) Update(ctx context.Context, token *api.Token, uid string, manifest types.Manifest) (reply *types.App, err error) { err = client.CallHTTP(ctx, impl.BaseURL, "LambdaAPI.Update", atomic.AddUint64(&impl.sequence, 1), &reply, token, uid, manifest) return } @@ -104,13 +103,13 @@ func (impl *LambdaAPIClient) Invoke(ctx context.Context, token *api.Token, uid s } // Make link/alias for app -func (impl *LambdaAPIClient) Link(ctx context.Context, token *api.Token, uid string, alias string) (reply *application.App, err error) { +func (impl *LambdaAPIClient) Link(ctx context.Context, token *api.Token, uid string, alias string) (reply *types.App, err error) { err = client.CallHTTP(ctx, impl.BaseURL, "LambdaAPI.Link", atomic.AddUint64(&impl.sequence, 1), &reply, token, uid, alias) return } // Remove link -func (impl *LambdaAPIClient) Unlink(ctx context.Context, token *api.Token, alias string) (reply *application.App, err error) { +func (impl *LambdaAPIClient) Unlink(ctx context.Context, token *api.Token, alias string) (reply *types.App, err error) { err = client.CallHTTP(ctx, impl.BaseURL, "LambdaAPI.Unlink", atomic.AddUint64(&impl.sequence, 1), &reply, token, alias) return } diff --git a/api/client/project_api_client.go b/api/client/project_api_client.go index d3abbf0..a17348e 100755 --- a/api/client/project_api_client.go +++ b/api/client/project_api_client.go @@ -4,8 +4,8 @@ import ( "context" client "github.com/reddec/jsonrpc2/client" api "github.com/reddec/trusted-cgi/api" - application "github.com/reddec/trusted-cgi/application" stats "github.com/reddec/trusted-cgi/stats" + types "github.com/reddec/trusted-cgi/types" "sync/atomic" ) @@ -43,7 +43,7 @@ func (impl *ProjectAPIClient) AllTemplates(ctx context.Context, token *api.Token } // List available apps (lambdas) in a project -func (impl *ProjectAPIClient) List(ctx context.Context, token *api.Token) (reply []*application.App, err error) { +func (impl *ProjectAPIClient) List(ctx context.Context, token *api.Token) (reply []*types.App, err error) { err = client.CallHTTP(ctx, impl.BaseURL, "ProjectAPI.List", atomic.AddUint64(&impl.sequence, 1), &reply, token) return } @@ -61,19 +61,19 @@ func (impl *ProjectAPIClient) Stats(ctx context.Context, token *api.Token, limit } // Create new app (lambda) -func (impl *ProjectAPIClient) Create(ctx context.Context, token *api.Token) (reply *application.App, err error) { +func (impl *ProjectAPIClient) Create(ctx context.Context, token *api.Token) (reply *types.App, err error) { err = client.CallHTTP(ctx, impl.BaseURL, "ProjectAPI.Create", atomic.AddUint64(&impl.sequence, 1), &reply, token) return } // Create new app/lambda/function using pre-defined template -func (impl *ProjectAPIClient) CreateFromTemplate(ctx context.Context, token *api.Token, templateName string) (reply *application.App, err error) { +func (impl *ProjectAPIClient) CreateFromTemplate(ctx context.Context, token *api.Token, templateName string) (reply *types.App, err error) { err = client.CallHTTP(ctx, impl.BaseURL, "ProjectAPI.CreateFromTemplate", atomic.AddUint64(&impl.sequence, 1), &reply, token, templateName) return } // Create new app/lambda/function using remote Git repo -func (impl *ProjectAPIClient) CreateFromGit(ctx context.Context, token *api.Token, repo string) (reply *application.App, err error) { +func (impl *ProjectAPIClient) CreateFromGit(ctx context.Context, token *api.Token, repo string) (reply *types.App, err error) { err = client.CallHTTP(ctx, impl.BaseURL, "ProjectAPI.CreateFromGit", atomic.AddUint64(&impl.sequence, 1), &reply, token, repo) return } diff --git a/api/interface.go b/api/interface.go index b0aefeb..b18a67b 100644 --- a/api/interface.go +++ b/api/interface.go @@ -3,7 +3,6 @@ package api import ( "context" "encoding/json" - "github.com/reddec/trusted-cgi/application" "github.com/reddec/trusted-cgi/stats" "github.com/reddec/trusted-cgi/types" ) @@ -63,9 +62,9 @@ type LambdaAPI interface { // Files in func dir Files(ctx context.Context, token *Token, uid string, dir string) ([]*File, error) // Info about application - Info(ctx context.Context, token *Token, uid string) (*application.App, error) + Info(ctx context.Context, token *Token, uid string) (*types.App, error) // Update application manifest - Update(ctx context.Context, token *Token, uid string, manifest types.Manifest) (*application.App, error) + Update(ctx context.Context, token *Token, uid string, manifest types.Manifest) (*types.App, error) // Create file or directory inside app CreateFile(ctx context.Context, token *Token, uid string, path string, dir bool) (bool, error) // Remove file or directory @@ -79,9 +78,9 @@ type LambdaAPI interface { // Invoke action in the app (if make installed) Invoke(ctx context.Context, token *Token, uid string, action string) (string, error) // Make link/alias for app - Link(ctx context.Context, token *Token, uid string, alias string) (*application.App, error) + Link(ctx context.Context, token *Token, uid string, alias string) (*types.App, error) // Remove link - Unlink(ctx context.Context, token *Token, alias string) (*application.App, error) + Unlink(ctx context.Context, token *Token, alias string) (*types.App, error) } // API for global project @@ -95,17 +94,17 @@ type ProjectAPI interface { // Get all templates without filtering AllTemplates(ctx context.Context, token *Token) ([]*TemplateStatus, error) // List available apps (lambdas) in a project - List(ctx context.Context, token *Token) ([]*application.App, error) + List(ctx context.Context, token *Token) ([]*types.App, error) // Templates with filter by availability including embedded Templates(ctx context.Context, token *Token) ([]*Template, error) // Global last records Stats(ctx context.Context, token *Token, limit int) ([]stats.Record, error) // Create new app (lambda) - Create(ctx context.Context, token *Token) (*application.App, error) + Create(ctx context.Context, token *Token) (*types.App, error) // Create new app/lambda/function using pre-defined template - CreateFromTemplate(ctx context.Context, token *Token, templateName string) (*application.App, error) + CreateFromTemplate(ctx context.Context, token *Token, templateName string) (*types.App, error) // Create new app/lambda/function using remote Git repo - CreateFromGit(ctx context.Context, token *Token, repo string) (*application.App, error) + CreateFromGit(ctx context.Context, token *Token, repo string) (*types.App, error) } // User/admin profile API diff --git a/api/services/lambda_srv.go b/api/services/lambda_srv.go index d0d7a1f..ed437af 100644 --- a/api/services/lambda_srv.go +++ b/api/services/lambda_srv.go @@ -85,15 +85,15 @@ func (srv *lambdaSrv) Files(ctx context.Context, token *api.Token, uid string, d return ans, nil } -func (srv *lambdaSrv) Info(ctx context.Context, token *api.Token, uid string) (*application.App, error) { +func (srv *lambdaSrv) Info(ctx context.Context, token *api.Token, uid string) (*types.App, error) { app := srv.project.FindApp(uid) if app == nil { return nil, fmt.Errorf("unknown app") } - return app, nil + return &app.App, nil } -func (srv *lambdaSrv) Update(ctx context.Context, token *api.Token, uid string, manifest types.Manifest) (*application.App, error) { +func (srv *lambdaSrv) Update(ctx context.Context, token *api.Token, uid string, manifest types.Manifest) (*types.App, error) { app := srv.project.FindApp(uid) if app == nil { return nil, fmt.Errorf("unknown app") @@ -102,7 +102,7 @@ func (srv *lambdaSrv) Update(ctx context.Context, token *api.Token, uid string, return nil, err } app.Manifest = manifest - return app, app.Manifest.SaveAs(app.ManifestFile()) + return &app.App, app.Manifest.SaveAs(app.ManifestFile()) } func (srv *lambdaSrv) CreateFile(ctx context.Context, token *api.Token, uid string, path string, dir bool) (bool, error) { @@ -164,10 +164,18 @@ func (srv *lambdaSrv) Invoke(ctx context.Context, token *api.Token, uid string, return app.InvokeAction(ctx, action, 0, srv.project.GlobalEnvironment()) } -func (srv *lambdaSrv) Link(ctx context.Context, token *api.Token, uid string, alias string) (*application.App, error) { - return srv.project.Link(uid, alias) +func (srv *lambdaSrv) Link(ctx context.Context, token *api.Token, uid string, alias string) (*types.App, error) { + app, err := srv.project.Link(uid, alias) + if err != nil { + return nil, err + } + return &app.App, nil } -func (srv *lambdaSrv) Unlink(ctx context.Context, token *api.Token, alias string) (*application.App, error) { - return srv.project.Unlink(alias) +func (srv *lambdaSrv) Unlink(ctx context.Context, token *api.Token, alias string) (*types.App, error) { + app, err := srv.project.Unlink(alias) + if err != nil { + return nil, err + } + return &app.App, nil } diff --git a/api/services/project_srv.go b/api/services/project_srv.go index 266fd18..562659b 100644 --- a/api/services/project_srv.go +++ b/api/services/project_srv.go @@ -7,6 +7,7 @@ import ( "github.com/reddec/trusted-cgi/application" "github.com/reddec/trusted-cgi/stats" "github.com/reddec/trusted-cgi/templates" + "github.com/reddec/trusted-cgi/types" ) func NewProjectSrv(project *application.Project, tracker stats.Reader, templatesDir string) *projectSrv { @@ -23,15 +24,23 @@ type projectSrv struct { templatesDir string } -func (srv *projectSrv) Create(ctx context.Context, token *api.Token) (*application.App, error) { - return srv.project.Create(ctx) +func (srv *projectSrv) Create(ctx context.Context, token *api.Token) (*types.App, error) { + app, err := srv.project.Create(ctx) + if err != nil { + return nil, err + } + return &app.App, nil } -func (srv *projectSrv) CreateFromGit(ctx context.Context, token *api.Token, repo string) (*application.App, error) { - return srv.project.CreateFromGit(ctx, repo) +func (srv *projectSrv) CreateFromGit(ctx context.Context, token *api.Token, repo string) (*types.App, error) { + app, err := srv.project.CreateFromGit(ctx, repo) + if err != nil { + return nil, err + } + return &app.App, nil } -func (srv *projectSrv) CreateFromTemplate(ctx context.Context, token *api.Token, templateName string) (*application.App, error) { +func (srv *projectSrv) CreateFromTemplate(ctx context.Context, token *api.Token, templateName string) (*types.App, error) { possible, err := templates.List(srv.templatesDir) if err != nil { return nil, err @@ -43,7 +52,11 @@ func (srv *projectSrv) CreateFromTemplate(ctx context.Context, token *api.Token, if !tpl.IsAvailable(ctx) { return nil, fmt.Errorf("template %s is not supported", templateName) } - return srv.project.CreateFromTemplate(ctx, tpl) + app, err := srv.project.CreateFromTemplate(ctx, tpl) + if err != nil { + return nil, err + } + return &app.App, nil } func (srv *projectSrv) Config(ctx context.Context, token *api.Token) (*api.Settings, error) { @@ -87,8 +100,13 @@ func (srv *projectSrv) AllTemplates(ctx context.Context, token *api.Token) ([]*a return ans, nil } -func (srv *projectSrv) List(ctx context.Context, token *api.Token) ([]*application.App, error) { - return srv.project.List(), nil +func (srv *projectSrv) List(ctx context.Context, token *api.Token) ([]*types.App, error) { + list := srv.project.List() + var ans = make([]*types.App, len(list)) + for i, v := range list { + ans[i] = &v.App + } + return ans, nil } func (srv *projectSrv) Templates(ctx context.Context, token *api.Token) ([]*api.Template, error) { diff --git a/application/actions.go b/application/actions.go index 475b238..0351b21 100644 --- a/application/actions.go +++ b/application/actions.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "context" + "github.com/reddec/trusted-cgi/internal" "os" "os/exec" "path/filepath" @@ -59,10 +60,9 @@ func (app *App) InvokeAction(ctx context.Context, name string, timeLimit time.Du cmd.Stdout = &out cmd.Stderr = &out cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGINT, - Setpgid: true, Credential: app.creds, } + internal.SetFlags(cmd) cmd.Env = environments err := cmd.Run() diff --git a/application/application.go b/application/application.go index 96403ec..cf4633b 100644 --- a/application/application.go +++ b/application/application.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "github.com/reddec/trusted-cgi/internal" "github.com/reddec/trusted-cgi/types" "io/ioutil" "os" @@ -13,13 +14,11 @@ import ( "syscall" ) -const ( - ManifestFile = "manifest.json" -) - func OpenApp(location string, creds *syscall.Credential) (*App, error) { var app = &App{ - UID: filepath.Base(location), + App: types.App{ + UID: filepath.Base(location), + }, creds: creds, location: location, } @@ -31,8 +30,10 @@ func OpenApp(location string, creds *syscall.Credential) (*App, error) { func CreateApp(location string, creds *syscall.Credential, manifest types.Manifest) (*App, error) { var app = &App{ - UID: filepath.Base(location), - Manifest: manifest, + App: types.App{ + UID: filepath.Base(location), + Manifest: manifest, + }, creds: creds, location: location, } @@ -50,10 +51,9 @@ func CreateApp(location string, creds *syscall.Credential, manifest types.Manife func CreateAppGit(ctx context.Context, location, repo, privateKey string, creds *syscall.Credential) (*App, error) { cmd := exec.CommandContext(ctx, "git", "clone", "--depth", "1", repo, location) cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGINT, - Setpgid: true, Credential: creds, } + internal.SetFlags(cmd) var buffer bytes.Buffer cmd.Stderr = &buffer cmd.Stdout = os.Stdout @@ -67,15 +67,13 @@ func CreateAppGit(ctx context.Context, location, repo, privateKey string, creds } type App struct { - UID string `json:"uid"` - Manifest types.Manifest `json:"manifest"` - IsGit bool `json:"git"` + types.App creds *syscall.Credential `json:"-"` location string `json:"-"` } func (app *App) ManifestFile() string { - return filepath.Join(app.location, ManifestFile) + return filepath.Join(app.location, internal.ManifestFile) } func (app *App) ApplyOwner() error { diff --git a/application/handler.go b/application/handler.go index 9b868fa..0294ebe 100644 --- a/application/handler.go +++ b/application/handler.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "github.com/reddec/trusted-cgi/internal" "github.com/reddec/trusted-cgi/stats" "io" "io/ioutil" @@ -144,11 +145,9 @@ func (app *App) Run(ctx context.Context, cmd.Stdout = &result cmd.Stderr = os.Stderr cmd.SysProcAttr = &syscall.SysProcAttr{ - Pdeathsig: syscall.SIGINT, - Setpgid: true, Credential: app.creds, } - + internal.SetFlags(cmd) var environments = os.Environ() for header, mapped := range env { environments = append(environments, header+"="+mapped) diff --git a/application/project.go b/application/project.go index a87388f..f48a54e 100644 --- a/application/project.go +++ b/application/project.go @@ -9,6 +9,7 @@ import ( "encoding/pem" "fmt" "github.com/google/uuid" + "github.com/reddec/trusted-cgi/internal" "github.com/reddec/trusted-cgi/templates" "github.com/reddec/trusted-cgi/types" "golang.org/x/crypto/ssh" @@ -25,12 +26,6 @@ import ( "time" ) -const ( - ProjectManifest = "project.json" - CGIIgnore = ".cgiignore" - SSHKeySize = 3072 -) - func OpenProject(location string, defaultConfig ProjectConfig) (*Project, error) { rootDir, err := filepath.Abs(location) if err != nil { @@ -40,7 +35,7 @@ func OpenProject(location string, defaultConfig ProjectConfig) (*Project, error) if err != nil { return nil, err } - return defaultConfig.LoadOrCreate(filepath.Join(rootDir, ProjectManifest)) + return defaultConfig.LoadOrCreate(filepath.Join(rootDir, internal.ProjectManifest)) } type ProjectConfig struct { @@ -359,8 +354,8 @@ func (project *Project) Download(ctx context.Context, uid string, tarGzBall io.W return fmt.Errorf("no such app") } args := project.config.TarCommand() - if _, err := os.Stat(filepath.Join(app.location, CGIIgnore)); err == nil { - args = append(args, "--exclude-from", CGIIgnore) + if _, err := os.Stat(filepath.Join(app.location, internal.CGIIgnore)); err == nil { + args = append(args, "--exclude-from", internal.CGIIgnore) } args = append(args, ".") cmd := exec.CommandContext(ctx, args[0], args[1:]...) @@ -464,7 +459,7 @@ func (project *Project) SetupSSHKey(file string) error { func (project *Project) generateSSHKeys(file string) (*rsa.PrivateKey, error) { log.Println("generating ssh key to", file) - privateKey, err := rsa.GenerateKey(rand.Reader, SSHKeySize) + privateKey, err := rsa.GenerateKey(rand.Reader, internal.SSHKeySize) if err != nil { return nil, err } diff --git a/cmd/cgi-ctl/cmd_clone.go b/cmd/cgi-ctl/cmd_clone.go index 72ac511..e7e60c0 100644 --- a/cmd/cgi-ctl/cmd_clone.go +++ b/cmd/cgi-ctl/cmd_clone.go @@ -4,8 +4,8 @@ import ( "bytes" "fmt" "github.com/alecthomas/units" - "github.com/reddec/trusted-cgi/application" "github.com/reddec/trusted-cgi/cmd/internal" + internal_app "github.com/reddec/trusted-cgi/internal" "log" "os" "os/exec" @@ -64,7 +64,7 @@ func (cmd *clone) Execute(args []string) error { return fmt.Errorf("save control file: %w", err) } - err = appendIfNoLineFile(application.CGIIgnore, controlFilename) + err = appendIfNoLineFile(internal_app.CGIIgnore, controlFilename) if err != nil { return fmt.Errorf("update cgiignore file: %w", err) } diff --git a/cmd/cgi-ctl/cmd_upload.go b/cmd/cgi-ctl/cmd_upload.go index 8f10bd5..1946c7a 100644 --- a/cmd/cgi-ctl/cmd_upload.go +++ b/cmd/cgi-ctl/cmd_upload.go @@ -4,8 +4,8 @@ import ( "bytes" "fmt" "github.com/alecthomas/units" - "github.com/reddec/trusted-cgi/application" "github.com/reddec/trusted-cgi/cmd/internal" + internal_app "github.com/reddec/trusted-cgi/internal" "log" "os" "os/exec" @@ -39,8 +39,8 @@ func (cmd *upload) Execute([]string) error { log.SetOutput(os.Stderr) log.Println("archiving...") var args = []string{"zcf", "-"} - if _, err := os.Stat(application.CGIIgnore); err == nil { - args = append(args, "--exclude-from", application.CGIIgnore) + if _, err := os.Stat(internal_app.CGIIgnore); err == nil { + args = append(args, "--exclude-from", internal_app.CGIIgnore) } args = append(args, ".") run := exec.CommandContext(ctx, "tar", args...) diff --git a/cmd/cgi-ctl/internal.go b/cmd/cgi-ctl/internal.go index 757a080..cec2c69 100644 --- a/cmd/cgi-ctl/internal.go +++ b/cmd/cgi-ctl/internal.go @@ -7,14 +7,12 @@ import ( "fmt" "github.com/reddec/trusted-cgi/api" "github.com/reddec/trusted-cgi/api/client" - "golang.org/x/crypto/ssh/terminal" "io" "log" "net/url" "os" "path/filepath" "strings" - "syscall" ) const ( @@ -59,7 +57,7 @@ func (rl *remoteLink) Token(ctx context.Context) (*api.Token, error) { } if rl.AskPass { _, _ = fmt.Fprintf(os.Stderr, "Enter Password: ") - bytePassword, err := terminal.ReadPassword(syscall.Stdin) + bytePassword, err := AskPass() if err != nil { return nil, err } diff --git a/cmd/cgi-ctl/main.go b/cmd/cgi-ctl/main.go index 9aa6311..5c91f58 100644 --- a/cmd/cgi-ctl/main.go +++ b/cmd/cgi-ctl/main.go @@ -2,8 +2,8 @@ package main import ( "github.com/jessevdk/go-flags" - "github.com/reddec/trusted-cgi/application" "github.com/reddec/trusted-cgi/cmd/internal" + internal_app "github.com/reddec/trusted-cgi/internal" "github.com/reddec/trusted-cgi/types" "io/ioutil" "log" @@ -62,7 +62,7 @@ func (b Bare) Execute(args []string) error { Public: !b.Private, } - err = def.SaveAs("manifest.json") + err = def.SaveAs(internal_app.ManifestFile) if err != nil { return err } @@ -77,7 +77,7 @@ func (b Bare) Execute(args []string) error { return err } - err = ioutil.WriteFile(application.CGIIgnore, []byte(""), 0755) + err = ioutil.WriteFile(internal_app.CGIIgnore, []byte(""), 0755) if err != nil { return err } diff --git a/cmd/cgi-ctl/utils_posix.go b/cmd/cgi-ctl/utils_posix.go new file mode 100644 index 0000000..46edc38 --- /dev/null +++ b/cmd/cgi-ctl/utils_posix.go @@ -0,0 +1,12 @@ +// +build !windows + +package main + +import ( + "golang.org/x/crypto/ssh/terminal" + "syscall" +) + +func AskPass() ([]byte, error) { + return terminal.ReadPassword(syscall.Stdin) +} diff --git a/cmd/cgi-ctl/utils_windows.go b/cmd/cgi-ctl/utils_windows.go new file mode 100644 index 0000000..526ba70 --- /dev/null +++ b/cmd/cgi-ctl/utils_windows.go @@ -0,0 +1,11 @@ +package main + +import ( + "fmt" +) + +func AskPass() ([]byte, error) { + var input string + _, err := fmt.Scanln(&input) + return []byte(input), err +} diff --git a/docs/api/lambda_api.md b/docs/api/lambda_api.md index 955711d..d5b7729 100755 --- a/docs/api/lambda_api.md +++ b/docs/api/lambda_api.md @@ -226,7 +226,7 @@ Signed JWT Info about application * Method: `LambdaAPI.Info` -* Returns: `*application.App` +* Returns: `*types.App` * Arguments: @@ -252,7 +252,7 @@ EOF | Json | Type | Comment | |------|------|---------| | uid | `string` | | -| manifest | `types.Manifest` | | +| manifest | `Manifest` | | | git | `bool` | | ### Token @@ -265,7 +265,7 @@ Signed JWT Update application manifest * Method: `LambdaAPI.Update` -* Returns: `*application.App` +* Returns: `*types.App` * Arguments: @@ -292,7 +292,7 @@ EOF | Json | Type | Comment | |------|------|---------| | uid | `string` | | -| manifest | `types.Manifest` | | +| manifest | `Manifest` | | | git | `bool` | | ### Manifest @@ -535,7 +535,7 @@ Signed JWT Make link/alias for app * Method: `LambdaAPI.Link` -* Returns: `*application.App` +* Returns: `*types.App` * Arguments: @@ -562,7 +562,7 @@ EOF | Json | Type | Comment | |------|------|---------| | uid | `string` | | -| manifest | `types.Manifest` | | +| manifest | `Manifest` | | | git | `bool` | | ### Token @@ -575,7 +575,7 @@ Signed JWT Remove link * Method: `LambdaAPI.Unlink` -* Returns: `*application.App` +* Returns: `*types.App` * Arguments: @@ -601,7 +601,7 @@ EOF | Json | Type | Comment | |------|------|---------| | uid | `string` | | -| manifest | `types.Manifest` | | +| manifest | `Manifest` | | | git | `bool` | | ### Token diff --git a/docs/api/project_api.md b/docs/api/project_api.md index d50d887..bbb491f 100755 --- a/docs/api/project_api.md +++ b/docs/api/project_api.md @@ -188,7 +188,7 @@ Signed JWT List available apps (lambdas) in a project * Method: `ProjectAPI.List` -* Returns: `[]*application.App` +* Returns: `[]*types.App` * Arguments: @@ -213,7 +213,7 @@ EOF | Json | Type | Comment | |------|------|---------| | uid | `string` | | -| manifest | `types.Manifest` | | +| manifest | `Manifest` | | | git | `bool` | | ### Token @@ -311,7 +311,7 @@ Signed JWT Create new app (lambda) * Method: `ProjectAPI.Create` -* Returns: `*application.App` +* Returns: `*types.App` * Arguments: @@ -336,7 +336,7 @@ EOF | Json | Type | Comment | |------|------|---------| | uid | `string` | | -| manifest | `types.Manifest` | | +| manifest | `Manifest` | | | git | `bool` | | ### Token @@ -349,7 +349,7 @@ Signed JWT Create new app/lambda/function using pre-defined template * Method: `ProjectAPI.CreateFromTemplate` -* Returns: `*application.App` +* Returns: `*types.App` * Arguments: @@ -375,7 +375,7 @@ EOF | Json | Type | Comment | |------|------|---------| | uid | `string` | | -| manifest | `types.Manifest` | | +| manifest | `Manifest` | | | git | `bool` | | ### Token @@ -388,7 +388,7 @@ Signed JWT Create new app/lambda/function using remote Git repo * Method: `ProjectAPI.CreateFromGit` -* Returns: `*application.App` +* Returns: `*types.App` * Arguments: @@ -414,7 +414,7 @@ EOF | Json | Type | Comment | |------|------|---------| | uid | `string` | | -| manifest | `types.Manifest` | | +| manifest | `Manifest` | | | git | `bool` | | ### Token diff --git a/docs/development.md b/docs/development.md index 141b286..aa8264b 100644 --- a/docs/development.md +++ b/docs/development.md @@ -5,7 +5,8 @@ nav_order: 999 --- # Development -The project has Linux-specific features and aimed to be run in Linux ecosystem. +The project has Linux-specific features and aimed to be run in Linux ecosystem, however +client control utility (cgi-ctl) shall work on most platform. Requirements for backend diff --git a/internal/const.go b/internal/const.go new file mode 100644 index 0000000..c6b8991 --- /dev/null +++ b/internal/const.go @@ -0,0 +1,8 @@ +package internal + +const ( + ProjectManifest = "project.json" // project manifest file (configuration for the platform) + CGIIgnore = ".cgiignore" // file with tar --exclude-from patterns for upload/download filter + ManifestFile = "manifest.json" // lambda configuration + SSHKeySize = 3072 // generated SSH size for git client +) diff --git a/internal/flags_default.go b/internal/flags_default.go new file mode 100644 index 0000000..c28fc82 --- /dev/null +++ b/internal/flags_default.go @@ -0,0 +1,7 @@ +//+build !linux + +package internal + +import "os/exec" + +func SetFlags(cmd *exec.Cmd) {} diff --git a/internal/flags_linux.go b/internal/flags_linux.go new file mode 100644 index 0000000..3c4eda2 --- /dev/null +++ b/internal/flags_linux.go @@ -0,0 +1,15 @@ +package internal + +import ( + "os/exec" + "syscall" +) + +// Set parent ground and death signal to be sure that nested processes will be closed +func SetFlags(cmd *exec.Cmd) { + if cmd.SysProcAttr == nil { + cmd.SysProcAttr = &syscall.SysProcAttr{} + } + cmd.SysProcAttr.Setpgid = true + cmd.SysProcAttr.Pdeathsig = syscall.SIGINT +} diff --git a/templates/template.go b/templates/template.go index 8f0db6d..6b549a8 100644 --- a/templates/template.go +++ b/templates/template.go @@ -3,13 +3,13 @@ package templates import ( "context" "encoding/json" + "github.com/reddec/trusted-cgi/internal" "github.com/reddec/trusted-cgi/types" "io/ioutil" "os" "os/exec" "path/filepath" "strings" - "syscall" "time" ) @@ -35,10 +35,7 @@ type Template struct { func (t *Template) IsAvailable(ctx context.Context) bool { for _, check := range t.Check { cmd := exec.CommandContext(ctx, check[0], check[1:]...) - cmd.SysProcAttr = &syscall.SysProcAttr{ - Setpgid: true, - Pdeathsig: syscall.SIGINT, - } + internal.SetFlags(cmd) if cmd.Run() != nil { return false } diff --git a/types/app.go b/types/app.go new file mode 100644 index 0000000..9a9241a --- /dev/null +++ b/types/app.go @@ -0,0 +1,7 @@ +package types + +type App struct { + UID string `json:"uid"` + Manifest Manifest `json:"manifest"` + IsGit bool `json:"git"` +} diff --git a/ui b/ui index 772d692..7cf3728 160000 --- a/ui +++ b/ui @@ -1 +1 @@ -Subproject commit 772d692fa7c4f1135af1078a6779d9d90481a6d5 +Subproject commit 7cf3728f7da12bd9f4f4d7ea7753b4da5722abff