-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mathieu Tortuyaux <[email protected]>
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(®ion, "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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |