Skip to content

Commit

Permalink
vm_policy_handling
Browse files Browse the repository at this point in the history
Signed-off-by: Aryan-sharma11 <[email protected]>
  • Loading branch information
Aryan-sharma11 committed Aug 22, 2023
1 parent 55d8580 commit 76b3f62
Showing 1 changed file with 64 additions and 5 deletions.
69 changes: 64 additions & 5 deletions vm/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type PolicyOptions struct {
GRPC string
}

func sendPolicyOverGRPC(o PolicyOptions, policyEventData []byte, kind string) error {
func sendPolicyOverGRPC(o PolicyOptions, policyEventData []byte, kind string, eventType string) error {
gRPC := ""

if o.GRPC != "" {
Expand All @@ -66,16 +66,75 @@ func sendPolicyOverGRPC(o PolicyOptions, policyEventData []byte, kind string) er

if kind == KubeArmorHostPolicy {
resp, err := client.HostPolicy(context.Background(), &req)
if err != nil || resp.Status != 1 {
if err != nil {
return fmt.Errorf("failed to send policy")
}
if eventType == "ADDED" {

if resp.Status == 1 {
if resp.Present == true {
fmt.Println("Policy configured successfully ")
} else {
fmt.Println("Policy applied successfully")
}
} else {
return fmt.Errorf(" Failed to apply policy")
}

}
if eventType == "DELETED" {

if resp.Status == 1 {
if resp.Applied {
fmt.Println("Policy Deleted successfully")
} else if resp.Present {
return fmt.Errorf("Failed to delete policy")
} else {
return fmt.Errorf("Policy doesn't exist")
}
} else {
return fmt.Errorf("Failed to delete policy")
}

}

} else {

resp, err := client.ContainerPolicy(context.Background(), &req)
if err != nil || resp.Status != 1 {
if err != nil {
return fmt.Errorf("failed to send policy")
}
if eventType == "ADDED" {

if resp.Status == 1 {
if resp.Present == true {
fmt.Println("Policy configured successfully ")
} else {
fmt.Println("Policy applied successfully")
}
} else {
return fmt.Errorf(" Failed to apply policy")
}

}
if eventType == "DELETED" {

if resp.Status == 1 {
if resp.Applied {
fmt.Println("Policy Deleted successfully")
} else if resp.Present {
return fmt.Errorf("Failed to delete policy")
} else {
return fmt.Errorf("Policy doesn't exist")
}
} else {
return fmt.Errorf("Failed to delete policy")
}

}

}
fmt.Println("Success")

return nil
}

Expand Down Expand Up @@ -198,7 +257,7 @@ func PolicyHandling(t string, path string, o PolicyOptions, httpAddress string,
}
} else {
// Systemd mode, hence send policy over gRPC
if err = sendPolicyOverGRPC(o, policyEventData, k.Kind); err != nil {
if err = sendPolicyOverGRPC(o, policyEventData, k.Kind, t); err != nil {
return err

}
Expand Down

0 comments on commit 76b3f62

Please sign in to comment.