Skip to content

Commit

Permalink
cmd/ore: add akamai create-image
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu Tortuyaux <[email protected]>
  • Loading branch information
tormath1 committed Dec 3, 2024
1 parent 268b0b7 commit 5cad630
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
49 changes: 49 additions & 0 deletions cmd/ore/akamai/akamai.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright The Mantle Authors.
// SPDX-License-Identifier: Apache-2.0

package akamai

import (
"fmt"
"os"

"github.com/coreos/pkg/capnslog"
"github.com/flatcar/mantle/cli"
"github.com/flatcar/mantle/platform"
"github.com/flatcar/mantle/platform/api/akamai"
"github.com/spf13/cobra"
)

var (
plog = capnslog.NewPackageLogger("github.com/flatcar/mantle", "ore/akamai")

Akamai = &cobra.Command{
Use: "akamai [command]",
Short: "akamai image utilities",
}

API *akamai.API
region string
token string
)

func init() {
cli.WrapPreRun(Akamai, preflightCheck)
Akamai.PersistentFlags().StringVar(&region, "akamai-region", "us-ord", "Akamai region")
Akamai.PersistentFlags().StringVar(&token, "akamai-token", "", "Akamai access token")
}

func preflightCheck(cmd *cobra.Command, args []string) error {
api, err := akamai.New(&akamai.Options{
Region: region,
Token: token,
Options: &platform.Options{},
})
if err != nil {
fmt.Fprintf(os.Stderr, "could not create Akamai API client: %v\n", err)
os.Exit(1)
}

API = api
return nil
}
43 changes: 43 additions & 0 deletions cmd/ore/akamai/create-image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright The Mantle Authors.
// SPDX-License-Identifier: Apache-2.0

package akamai

import (
"context"
"fmt"

"github.com/spf13/cobra"
)

var (
cmdCreate = &cobra.Command{
Use: "create-image",
Short: "Create Akamai image",
RunE: runCreate,
Example: `IMAGE_ID=$(ore akamai \
--akamai-token "${AKAMAI_TOKEN}" \
--akamai-region "${AKAMAI_REGION}" \
create-image --name my-image --file /path/to/flatcar_production_akamai_image.bin.gz)`,
}
file string
name string
)

func init() {
Akamai.AddCommand(cmdCreate)

cmdCreate.Flags().StringVar(&file, "file", "flatcar_production_akamai_image.bin.gz", "path to local Flatcar image (.bin.gz)")
cmdCreate.Flags().StringVar(&name, "name", "flatcar-kola-test", "name of the image")
}

func runCreate(cmd *cobra.Command, args []string) error {
ID, err := API.UploadImage(context.Background(), name, file)
if err != nil {
return fmt.Errorf("creating Flatcar image: %v", err)
}

fmt.Println(ID)

return nil
}

0 comments on commit 5cad630

Please sign in to comment.