Skip to content

Commit cfda96e

Browse files
authored
[feat:extensions] add support to package web-bot-auth (#62)
<!-- CURSOR_SUMMARY --> > [!NOTE] > Adds a new CLI flow to fetch, build, and package Cloudflare’s `web-bot-auth` browser extension with Kernel-specific configs, plus supporting utils and tests. > > - New `kernel extensions build-web-bot-auth` command in `cmd/extensions.go` with flags `--to`, `--url`, `--key`, `--upload`; can auto-upload to Kernel under a specified name > - Implements build pipeline in `pkg/extensions/webbotauth.go`: downloads GitHub archive, validates/converts Ed25519 keys (JWK/PEM), modifies policy/build templates, runs `npm install/build/bundle`, extracts extension ID, and copies artifacts (`.crx`, `update.xml`, `policy`, built files) to output > - Adds crypto helpers in `pkg/util/crypto.go` (`ValidatePEMKey`, `IsPEMKey`, `ConvertJWKToPEM`) and file ops in `pkg/util/fileops.go` (`CopyFile`, `CopyDir`, `ModifyFile`) > - New tests: download/extract integration in `pkg/extensions/webbotauth_test.go` and crypto unit tests in `pkg/util/crypto_test.go` > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5268e7a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 251fba5 commit cfda96e

File tree

6 files changed

+964
-0
lines changed

6 files changed

+964
-0
lines changed

cmd/extensions.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"path/filepath"
1212
"time"
1313

14+
"github.com/kernel/cli/pkg/extensions"
1415
"github.com/kernel/cli/pkg/util"
1516
"github.com/kernel/kernel-go-sdk"
1617
"github.com/kernel/kernel-go-sdk/option"
@@ -422,12 +423,60 @@ var extensionsUploadCmd = &cobra.Command{
422423
},
423424
}
424425

426+
var extensionsBuildWebBotAuthCmd = &cobra.Command{
427+
Use: "build-web-bot-auth",
428+
Short: "Build the Cloudflare web-bot-auth extension for Kernel",
429+
Long: `Download, build, and prepare the Cloudflare web-bot-auth extension with Kernel-specific configurations.
430+
Defaults to RFC9421 test key (works with Cloudflare's test site).
431+
Uploads it to Kernel as 'web-bot-auth'. Optionally accepts a custom JWK or PEM key file.`,
432+
Args: cobra.NoArgs,
433+
RunE: func(cmd *cobra.Command, args []string) error {
434+
output, _ := cmd.Flags().GetString("to")
435+
url, _ := cmd.Flags().GetString("url")
436+
keyPath, _ := cmd.Flags().GetString("key")
437+
uploadName, _ := cmd.Flags().GetString("upload")
438+
439+
// Use upload name for extension name, or default to "web-bot-auth"
440+
extensionName := "web-bot-auth"
441+
if uploadName != "" {
442+
extensionName = uploadName
443+
}
444+
445+
// Build the extension
446+
result, err := extensions.BuildWebBotAuth(cmd.Context(), extensions.ExtensionsBuildWebBotAuthInput{
447+
Output: output,
448+
HostURL: url,
449+
KeyPath: keyPath,
450+
ExtensionName: extensionName,
451+
AutoUpload: uploadName != "",
452+
})
453+
if err != nil {
454+
return err
455+
}
456+
457+
// Upload if requested
458+
if uploadName != "" {
459+
client := getKernelClient(cmd)
460+
svc := client.Extensions
461+
e := ExtensionsCmd{extensions: &svc}
462+
pterm.Info.Println("Uploading extension to Kernel...")
463+
return e.Upload(cmd.Context(), ExtensionsUploadInput{
464+
Dir: result.OutputDir,
465+
Name: extensionName,
466+
})
467+
}
468+
469+
return nil
470+
},
471+
}
472+
425473
func init() {
426474
extensionsCmd.AddCommand(extensionsListCmd)
427475
extensionsCmd.AddCommand(extensionsDeleteCmd)
428476
extensionsCmd.AddCommand(extensionsDownloadCmd)
429477
extensionsCmd.AddCommand(extensionsDownloadWebStoreCmd)
430478
extensionsCmd.AddCommand(extensionsUploadCmd)
479+
extensionsCmd.AddCommand(extensionsBuildWebBotAuthCmd)
431480

432481
extensionsListCmd.Flags().StringP("output", "o", "", "Output format: json for raw API response")
433482
extensionsDeleteCmd.Flags().BoolP("yes", "y", false, "Skip confirmation prompt")
@@ -436,4 +485,8 @@ func init() {
436485
extensionsDownloadWebStoreCmd.Flags().String("os", "", "Target OS: mac, win, or linux (default linux)")
437486
extensionsUploadCmd.Flags().StringP("output", "o", "", "Output format: json for raw API response")
438487
extensionsUploadCmd.Flags().String("name", "", "Optional unique extension name")
488+
extensionsBuildWebBotAuthCmd.Flags().String("to", "./web-bot-auth", "Output directory for the prepared extension")
489+
extensionsBuildWebBotAuthCmd.Flags().String("url", "http://127.0.0.1:10001", "Base URL for update.xml and policy templates")
490+
extensionsBuildWebBotAuthCmd.Flags().String("key", "", "Path to Ed25519 private key file (JWK or PEM format)")
491+
extensionsBuildWebBotAuthCmd.Flags().String("upload", "", "Upload extension to Kernel with specified name (e.g., --upload web-bot-auth)")
439492
}

0 commit comments

Comments
 (0)