Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: import/export charm actions, config and lxd-profile #151

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
feat: lxd profile
This also adds the LXD profile to the charm metadata. Adding this to
charm metadata as a blob allows us to pass it through without it
being incorrectly interpreted as a yaml.
SimonRichardson committed Jul 30, 2024
commit dfac62caf6de2268a18f54a8111cd0513354cbbb
15 changes: 15 additions & 0 deletions charmmetadata.go
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ type CharmMetadataArgs struct {
Resources map[string]CharmMetadataResource
Terms []string
Containers map[string]CharmMetadataContainer
LXDProfile string
}

func newCharmMetadata(args CharmMetadataArgs) *charmMetadata {
@@ -176,6 +177,7 @@ func newCharmMetadata(args CharmMetadataArgs) *charmMetadata {
Resources_: resources,
Terms_: args.Terms,
Containers_: containers,
LXDProfile_: args.LXDProfile,
}
}

@@ -201,6 +203,7 @@ type charmMetadata struct {
Resources_ map[string]charmMetadataResource `yaml:"resources,omitempty"`
Terms_ []string `yaml:"terms,omitempty"`
Containers_ map[string]charmMetadataContainer `yaml:"containers,omitempty"`
LXDProfile_ string `yaml:"lxd-profile,omitempty"`
}

// Name returns the name of the charm.
@@ -330,6 +333,11 @@ func (m *charmMetadata) Containers() map[string]CharmMetadataContainer {
return containers
}

// LXDPofile returns the LXD profile of the charm.
func (m *charmMetadata) LXDProfile() string {
return m.LXDProfile_
}

func importCharmMetadata(source map[string]interface{}) (*charmMetadata, error) {
version, err := getVersion(source)
if err != nil {
@@ -375,6 +383,7 @@ func importCharmMetadataVersion(source map[string]interface{}, importVersion int
"resources": schema.StringMap(schema.Any()),
"terms": schema.List(schema.String()),
"containers": schema.StringMap(schema.Any()),
"lxd-profile": schema.String(),
}
defaults := schema.Defaults{
"summary": schema.Omit,
@@ -395,6 +404,7 @@ func importCharmMetadataVersion(source map[string]interface{}, importVersion int
"resources": schema.Omit,
"terms": schema.Omit,
"containers": schema.Omit,
"lxd-profile": schema.Omit,
}
checker := schema.FieldMap(fields, defaults)

@@ -531,6 +541,7 @@ func importCharmMetadataVersion(source map[string]interface{}, importVersion int
minJujuVersion string
runAs string
assumes string
lxdProfile string
)

if valid["summary"] != nil {
@@ -551,6 +562,9 @@ func importCharmMetadataVersion(source map[string]interface{}, importVersion int
if valid["assumes"] != nil {
assumes = valid["assumes"].(string)
}
if valid["lxd-profile"] != nil {
lxdProfile = valid["lxd-profile"].(string)
}

return &charmMetadata{
Version_: 1,
@@ -573,6 +587,7 @@ func importCharmMetadataVersion(source map[string]interface{}, importVersion int
Payloads_: payloads,
Containers_: containers,
Terms_: terms,
LXDProfile_: lxdProfile,
}, nil
}

2 changes: 2 additions & 0 deletions charmmetadata_test.go
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@ func maximalCharmMetadataMap() map[interface{}]interface{} {
"run-as": "root",
"assumes": "{}",
"min-juju-version": "4.0.0",
"lxd-profile": "{}",
"categories": []interface{}{"test", "testing"},
"tags": []interface{}{"foo", "bar"},
"terms": []interface{}{"baz", "qux"},
@@ -154,6 +155,7 @@ func maximalCharmMetadataArgs() CharmMetadataArgs {
RunAs: "root",
Assumes: "{}",
MinJujuVersion: "4.0.0",
LXDProfile: "{}",
Categories: []string{"test", "testing"},
Tags: []string{"foo", "bar"},
Terms: []string{"baz", "qux"},