-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
agent-config: generate and use attestation-agent toml
agent-config: generate and use attestation-agent toml - Generate the attestation-agent toml file aa.toml when aaKBCParams provided - Use the cfg file to start attestation agent service when it exists - Start attestation agent service directly when no cfg file exists - remove aa_kbc_params in agent-config so that cdh won't read from it - rename agent to aa to reflect the real config Signed-off-by: Qi Feng Huo <huoqif@cn.ibm.com>
- Loading branch information
Qi Feng Huo
committed
Jun 20, 2024
1 parent
94dd1a4
commit 0c83f87
Showing
16 changed files
with
102 additions
and
469 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
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
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
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 @@ | ||
package aa | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
toml "github.com/pelletier/go-toml/v2" | ||
) | ||
|
||
const ( | ||
DefaultAaConfigPath = "/run/peerpod/aa.toml" | ||
) | ||
|
||
type AAConfig struct { | ||
TokenCfg struct { | ||
CocoAs struct { | ||
URL string `toml:"url"` | ||
} `toml:"coco_as"` | ||
Kbs struct { | ||
URL string `toml:"url"` | ||
} `toml:"kbs"` | ||
} `toml:"token_configs"` | ||
} | ||
|
||
func parseAAKBCParams(aaKBCParams string) (string, error) { | ||
parts := strings.SplitN(aaKBCParams, "::", 2) | ||
if len(parts) != 2 { | ||
return "", fmt.Errorf("Invalid aa-kbs-params input: %s", aaKBCParams) | ||
} | ||
_, url := parts[0], parts[1] | ||
return url, nil | ||
} | ||
|
||
func CreateConfigFile(aaKBCParams string) (string, error) { | ||
url, err := parseAAKBCParams(aaKBCParams) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
config := AAConfig{} | ||
config.TokenCfg.CocoAs.URL = "" | ||
config.TokenCfg.Kbs.URL = url | ||
|
||
bytes, err := toml.Marshal(config) | ||
if err != nil { | ||
return "", err | ||
} | ||
return string(bytes), 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,36 @@ | ||
package aa | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_parseAAKBCParams(t *testing.T) { | ||
url, err := parseAAKBCParams("cc_kbc::http://127.0.0.1:8080") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
expected := "http://127.0.0.1:8080" | ||
if url != expected { | ||
t.Errorf("Expected %s, got %s", expected, url) | ||
} | ||
} | ||
|
||
func TestConfigFile(t *testing.T) { | ||
refcfg := `[token_configs] | ||
[token_configs.coco_as] | ||
url = '' | ||
[token_configs.kbs] | ||
url = 'http://127.0.0.1:8080' | ||
` | ||
|
||
config, err := CreateConfigFile("cc_kbc::http://127.0.0.1:8080") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if config != refcfg { | ||
t.Errorf("Expected: \n%s, got: \n%s", refcfg, config) | ||
} | ||
} |
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
11 changes: 0 additions & 11 deletions
11
src/cloud-api-adaptor/pkg/agent/test-data/sample-agent-config.toml
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.