anonpenguin23 106c2df4d2 feat: implement wallet-based SSH authentication using Ed25519 keys
- Added documentation for wallet-based SSH authentication in WALLET_SSH_AUTH.md.
- Introduced SSH key derivation and management in rootwallet core and CLI.
- Created commands for generating, loading, and unloading SSH keys in the CLI.
- Updated Orama network to support SSH key authentication.
- Added migration steps for nodes to transition from password-based to key-based authentication.

feat: add serverless function management commands

- Implemented function command structure in CLI for managing serverless functions.
- Added commands for initializing, building, deploying, invoking, deleting, and listing functions.
- Created helper functions for handling function configuration and API requests.
- Integrated TinyGo for building functions to WASM.
- Added logging and version management for deployed functions.
2026-02-19 10:51:03 +02:00

85 lines
2.0 KiB
Go

package functions
import (
"fmt"
"os"
"path/filepath"
"github.com/spf13/cobra"
)
// InitCmd scaffolds a new function project.
var InitCmd = &cobra.Command{
Use: "init <name>",
Short: "Create a new serverless function project",
Long: "Scaffolds a new directory with function.go and function.yaml templates.",
Args: cobra.ExactArgs(1),
RunE: runInit,
}
func runInit(cmd *cobra.Command, args []string) error {
name := args[0]
if !validNameRegex.MatchString(name) {
return fmt.Errorf("invalid function name %q: must start with a letter and contain only letters, digits, hyphens, or underscores", name)
}
dir := filepath.Join(".", name)
if _, err := os.Stat(dir); err == nil {
return fmt.Errorf("directory %q already exists", name)
}
if err := os.MkdirAll(dir, 0o755); err != nil {
return fmt.Errorf("failed to create directory: %w", err)
}
// Write function.yaml
yamlContent := fmt.Sprintf(`name: %s
public: false
memory: 64
timeout: 30
retry:
count: 0
delay: 5
`, name)
if err := os.WriteFile(filepath.Join(dir, "function.yaml"), []byte(yamlContent), 0o644); err != nil {
return fmt.Errorf("failed to write function.yaml: %w", err)
}
// Write function.go
goContent := fmt.Sprintf(`package main
import "github.com/DeBrosOfficial/network/sdk/fn"
func main() {
fn.Run(func(input []byte) ([]byte, error) {
var req struct {
Name string `+"`"+`json:"name"`+"`"+`
}
fn.ParseJSON(input, &req)
if req.Name == "" {
req.Name = "World"
}
return fn.JSON(map[string]string{
"greeting": "Hello, " + req.Name + "!",
})
})
}
`)
if err := os.WriteFile(filepath.Join(dir, "function.go"), []byte(goContent), 0o644); err != nil {
return fmt.Errorf("failed to write function.go: %w", err)
}
fmt.Printf("Created function project: %s/\n", name)
fmt.Printf(" %s/function.yaml — configuration\n", name)
fmt.Printf(" %s/function.go — handler code\n\n", name)
fmt.Printf("Next steps:\n")
fmt.Printf(" cd %s\n", name)
fmt.Printf(" orama function build\n")
fmt.Printf(" orama function deploy\n")
return nil
}