mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
configapi: simplify pkg structure
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
parent
f604a8dfd2
commit
5bfaae2304
@ -1,11 +1,21 @@
|
|||||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
||||||
|
load("//bazel/go:go_test.bzl", "go_test")
|
||||||
|
|
||||||
go_library(
|
go_library(
|
||||||
name = "configapi_lib",
|
name = "configapi_lib",
|
||||||
srcs = ["main.go"],
|
srcs = [
|
||||||
|
"delete.go",
|
||||||
|
"root.go",
|
||||||
|
],
|
||||||
importpath = "github.com/edgelesssys/constellation/v2/hack/configapi",
|
importpath = "github.com/edgelesssys/constellation/v2/hack/configapi",
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
deps = ["//hack/configapi/cmd"],
|
deps = [
|
||||||
|
"//internal/api/attestationconfigapi",
|
||||||
|
"//internal/logger",
|
||||||
|
"//internal/staticupload",
|
||||||
|
"@com_github_spf13_cobra//:cobra",
|
||||||
|
"@org_uber_go_zap//:zap",
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
go_binary(
|
go_binary(
|
||||||
@ -13,3 +23,17 @@ go_binary(
|
|||||||
embed = [":configapi_lib"],
|
embed = [":configapi_lib"],
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
go_test(
|
||||||
|
name = "configapi_test",
|
||||||
|
srcs = [
|
||||||
|
"delete_test.go",
|
||||||
|
"root_test.go",
|
||||||
|
],
|
||||||
|
embed = [":configapi_lib"],
|
||||||
|
deps = [
|
||||||
|
"//internal/api/attestationconfigapi",
|
||||||
|
"@com_github_stretchr_testify//assert",
|
||||||
|
"@com_github_stretchr_testify//require",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
|
||||||
load("//bazel/go:go_test.bzl", "go_test")
|
|
||||||
|
|
||||||
go_library(
|
|
||||||
name = "cmd",
|
|
||||||
srcs = [
|
|
||||||
"delete.go",
|
|
||||||
"root.go",
|
|
||||||
],
|
|
||||||
importpath = "github.com/edgelesssys/constellation/v2/hack/configapi/cmd",
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
deps = [
|
|
||||||
"//internal/api/attestationconfigapi",
|
|
||||||
"//internal/logger",
|
|
||||||
"//internal/staticupload",
|
|
||||||
"@com_github_spf13_cobra//:cobra",
|
|
||||||
"@org_uber_go_zap//:zap",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
go_test(
|
|
||||||
name = "cmd_test",
|
|
||||||
srcs = [
|
|
||||||
"delete_test.go",
|
|
||||||
"root_test.go",
|
|
||||||
],
|
|
||||||
embed = [":cmd"],
|
|
||||||
deps = [
|
|
||||||
"//internal/api/attestationconfigapi",
|
|
||||||
"@com_github_stretchr_testify//assert",
|
|
||||||
"@com_github_stretchr_testify//require",
|
|
||||||
],
|
|
||||||
)
|
|
@ -3,7 +3,7 @@ Copyright (c) Edgeless Systems GmbH
|
|||||||
|
|
||||||
SPDX-License-Identifier: AGPL-3.0-only
|
SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
package cmd
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -50,13 +50,13 @@ func runDelete(cmd *cobra.Command, _ []string) error {
|
|||||||
Bucket: awsBucket,
|
Bucket: awsBucket,
|
||||||
Region: awsRegion,
|
Region: awsRegion,
|
||||||
}
|
}
|
||||||
client, close, err := attestationconfigapi.NewClient(cmd.Context(), cfg, []byte(cosignPwd), []byte(privateKey), false, log)
|
client, stop, err := attestationconfigapi.NewClient(cmd.Context(), cfg, []byte(cosignPwd), []byte(privateKey), false, log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("create attestation client: %w", err)
|
return fmt.Errorf("create attestation client: %w", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := close(cmd.Context()); err != nil {
|
if err := stop(cmd.Context()); err != nil {
|
||||||
cmd.Printf("close client: %s\n", err.Error())
|
cmd.Printf("stopping client: %s\n", err.Error())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
deleteCmd := deleteCmd{
|
deleteCmd := deleteCmd{
|
@ -3,7 +3,7 @@ Copyright (c) Edgeless Systems GmbH
|
|||||||
|
|
||||||
SPDX-License-Identifier: AGPL-3.0-only
|
SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
package cmd
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) Edgeless Systems GmbH
|
|
||||||
|
|
||||||
SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/edgelesssys/constellation/v2/hack/configapi/cmd"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if err := cmd.Execute(); err != nil {
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
@ -4,7 +4,7 @@ Copyright (c) Edgeless Systems GmbH
|
|||||||
SPDX-License-Identifier: AGPL-3.0-only
|
SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cmd
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -34,9 +34,11 @@ var (
|
|||||||
privateKey string
|
privateKey string
|
||||||
)
|
)
|
||||||
|
|
||||||
// Execute executes the root command.
|
func main() {
|
||||||
func Execute() error {
|
if err := newRootCmd().Execute(); err != nil {
|
||||||
return newRootCmd().Execute()
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// newRootCmd creates the root command.
|
// newRootCmd creates the root command.
|
@ -4,7 +4,7 @@ Copyright (c) Edgeless Systems GmbH
|
|||||||
SPDX-License-Identifier: AGPL-3.0-only
|
SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package cmd
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@ -13,14 +13,16 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testCfg = attestationconfigapi.AzureSEVSNPVersion{
|
|
||||||
Microcode: 93,
|
|
||||||
TEE: 0,
|
|
||||||
SNP: 6,
|
|
||||||
Bootloader: 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestIsInputNewerThanLatestAPI(t *testing.T) {
|
func TestIsInputNewerThanLatestAPI(t *testing.T) {
|
||||||
|
newTestCfg := func() attestationconfigapi.AzureSEVSNPVersion {
|
||||||
|
return attestationconfigapi.AzureSEVSNPVersion{
|
||||||
|
Microcode: 93,
|
||||||
|
TEE: 0,
|
||||||
|
SNP: 6,
|
||||||
|
Bootloader: 2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
testCases := map[string]struct {
|
testCases := map[string]struct {
|
||||||
latest attestationconfigapi.AzureSEVSNPVersion
|
latest attestationconfigapi.AzureSEVSNPVersion
|
||||||
input attestationconfigapi.AzureSEVSNPVersion
|
input attestationconfigapi.AzureSEVSNPVersion
|
||||||
@ -31,8 +33,8 @@ func TestIsInputNewerThanLatestAPI(t *testing.T) {
|
|||||||
input: func(c attestationconfigapi.AzureSEVSNPVersion) attestationconfigapi.AzureSEVSNPVersion {
|
input: func(c attestationconfigapi.AzureSEVSNPVersion) attestationconfigapi.AzureSEVSNPVersion {
|
||||||
c.Microcode--
|
c.Microcode--
|
||||||
return c
|
return c
|
||||||
}(testCfg),
|
}(newTestCfg()),
|
||||||
latest: testCfg,
|
latest: newTestCfg(),
|
||||||
expect: false,
|
expect: false,
|
||||||
errMsg: "input Microcode version: 92 is older than latest API version: 93",
|
errMsg: "input Microcode version: 92 is older than latest API version: 93",
|
||||||
},
|
},
|
||||||
@ -41,8 +43,8 @@ func TestIsInputNewerThanLatestAPI(t *testing.T) {
|
|||||||
c.Microcode++
|
c.Microcode++
|
||||||
c.Bootloader--
|
c.Bootloader--
|
||||||
return c
|
return c
|
||||||
}(testCfg),
|
}(newTestCfg()),
|
||||||
latest: testCfg,
|
latest: newTestCfg(),
|
||||||
expect: false,
|
expect: false,
|
||||||
errMsg: "input Bootloader version: 1 is older than latest API version: 2",
|
errMsg: "input Bootloader version: 1 is older than latest API version: 2",
|
||||||
},
|
},
|
||||||
@ -50,13 +52,13 @@ func TestIsInputNewerThanLatestAPI(t *testing.T) {
|
|||||||
input: func(c attestationconfigapi.AzureSEVSNPVersion) attestationconfigapi.AzureSEVSNPVersion {
|
input: func(c attestationconfigapi.AzureSEVSNPVersion) attestationconfigapi.AzureSEVSNPVersion {
|
||||||
c.TEE++
|
c.TEE++
|
||||||
return c
|
return c
|
||||||
}(testCfg),
|
}(newTestCfg()),
|
||||||
latest: testCfg,
|
latest: newTestCfg(),
|
||||||
expect: true,
|
expect: true,
|
||||||
},
|
},
|
||||||
"input is equal to latest": {
|
"input is equal to latest": {
|
||||||
input: testCfg,
|
input: newTestCfg(),
|
||||||
latest: testCfg,
|
latest: newTestCfg(),
|
||||||
expect: false,
|
expect: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user