Skip to content

Commit

Permalink
i/prompting: removed switches for handlers based on interface name
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
  • Loading branch information
olivercalder committed Apr 18, 2024
1 parent ea7dc85 commit 596f185
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
25 changes: 6 additions & 19 deletions interfaces/prompting/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@ type Constraints struct {
// ValidateForInterface returns nil if the constraints are valid for the given
// interface, otherwise returns an error.
func (c *Constraints) ValidateForInterface(iface string) error {
switch iface {
case "home":
// TODO: change to this once PR #13730 is merged:
// if err := ValidatePathPattern(c.PathPattern); err != nil {
// return err
// }
default:
return fmt.Errorf("constraints incompatible with the given interface: %q", iface)
}
// TODO: change to this once PR #13730 is merged:
// if err := ValidatePathPattern(c.PathPattern); err != nil {
// return err
// }
permissions, err := AbstractPermissionsFromList(iface, c.Permissions)
if err != nil {
return err
Expand Down Expand Up @@ -134,11 +129,7 @@ func AvailablePermissions(iface string) ([]string, error) {
// AbstractPermissionsFromAppArmorPermissions returns the list of permissions
// corresponding to the given AppArmor permissions for the given interface.
func AbstractPermissionsFromAppArmorPermissions(iface string, permissions interface{}) ([]string, error) {
switch iface {
case "home":
return abstractPermissionsFromAppArmorFilePermissions(iface, permissions)
}
return nil, fmt.Errorf("cannot parse AppArmor permissions: unsupported interface: %q", iface)
return abstractPermissionsFromAppArmorFilePermissions(iface, permissions)
}

// abstractPermissionsFromAppArmorFilePermissions returns the list of permissions
Expand Down Expand Up @@ -217,11 +208,7 @@ func AbstractPermissionsFromList(iface string, permissions []string) ([]string,
// AbstractPermissionsToAppArmorPermissions returns AppArmor permissions
// corresponding to the given permissions for the given interface.
func AbstractPermissionsToAppArmorPermissions(iface string, permissions []string) (interface{}, error) {
switch iface {
case "home":
return abstractPermissionsToAppArmorFilePermissions(iface, permissions)
}
return nil, fmt.Errorf("cannot convert abstract permissions to AppArmor permissions: unsupported interface: %q", iface)
return abstractPermissionsToAppArmorFilePermissions(iface, permissions)
}

// AbstractPermissionsToAppArmorFilePermissions returns AppArmor file
Expand Down
12 changes: 1 addition & 11 deletions interfaces/prompting/constraints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *promptingSuite) TestConstraintsValidateForInterface(c *C) {
"foo",
"invalid/path",
[]string{"read"},
"constraints incompatible with the given interface.*",
"unsupported interface.*",
},
// TODO: add this once PR #13730 is merged:
// {
Expand Down Expand Up @@ -359,11 +359,6 @@ func (s *promptingSuite) TestAbstractPermissionsFromAppArmorFilePermissionsUnhap
perms interface{}
errStr string
}{
{
"foo",
"anything",
".*unsupported interface.*",
},
{
"home",
"not a file permission",
Expand Down Expand Up @@ -502,11 +497,6 @@ func (s *promptingSuite) TestAbstractPermissionsToAppArmorFilePermissionsUnhappy
perms []string
errStr string
}{
{
"foo",
[]string{},
".*unsupported interface.*",
},
{
"home",
[]string{},
Expand Down

0 comments on commit 596f185

Please sign in to comment.