Skip to content

Commit

Permalink
style: Deactivate future-use code blocks and annotate server.go for c…
Browse files Browse the repository at this point in the history
…larity
  • Loading branch information
b0m313 committed Jan 2, 2024
1 parent ee8db0a commit 2583368
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion nimbus-kubearmor/processor/network_policy.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Authors of Nimbus

package policy
package processor

/*
import (
"context"
Expand Down Expand Up @@ -61,3 +62,4 @@ func (npc *NetworkPolicyController) DeletePolicy(ctx context.Context, bindingInf
log.Info("Deleted Network Policy", "PolicyName", bindingInfo.Binding.Name)
return nil
}
*/
4 changes: 3 additions & 1 deletion nimbus-kubearmor/processor/system_policy.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Authors of Nimbus

package policy
package processor

/*
import (
"context"
Expand Down Expand Up @@ -60,3 +61,4 @@ func (spc *SystemPolicyController) DeletePolicy(ctx context.Context, bindingInfo
log.Info("Deleted System Policy", "PolicyName", bindingInfo.Binding.Name)
return nil
}
*/
2 changes: 2 additions & 0 deletions nimbus-kubearmor/processor/utils/utils_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package utils

/*
import (
"context"
"fmt"
Expand Down Expand Up @@ -423,3 +424,4 @@ func DeletePolicy(ctx context.Context, c client.Client, policyType, name, namesp
}
return nil
}
*/
12 changes: 9 additions & 3 deletions nimbus-kubearmor/receiver/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,46 @@ import (
)

var (
// 저장된 Nimbus Policy를 저장하는 메모리 저장소
// Memory store for saved Nimbus Policies
nimbusPolicies []interface{}
lock sync.Mutex
)

func main() {
// Handler for exporting Nimbus Policies
http.HandleFunc("/api/v1/nimbus/export", func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "Only POST method is accepted", http.StatusMethodNotAllowed)
return
}

// Read the request body
body, err := ioutil.ReadAll(r.Body)
if err != nil {
http.Error(w, "Error reading request body", http.StatusInternalServerError)
return
}
defer r.Body.Close()

// Unmarshal the JSON data from the request
var data interface{}
err = json.Unmarshal(body, &data)
if err != nil {
http.Error(w, "Error unmarshalling request body", http.StatusBadRequest)
return
}

// 수신된 Nimbus Policy 저장
// Store the received Nimbus Policy
lock.Lock()
nimbusPolicies = append(nimbusPolicies, data)
lock.Unlock()

// Log the received policy
fmt.Printf("Received Nimbus Policy: %+v\n", data)
w.WriteHeader(http.StatusOK)
})

// 저장된 Nimbus Policies를 조회하는 API
// Handler for retrieving stored Nimbus Policies
http.HandleFunc("/api/v1/nimbus/policies", func(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
http.Error(w, "Only GET method is accepted", http.StatusMethodNotAllowed)
Expand All @@ -54,11 +58,13 @@ func main() {

lock.Lock()
defer lock.Unlock()
// Encode and respond with the stored policies
if err := json.NewEncoder(w).Encode(nimbusPolicies); err != nil {
http.Error(w, "Error encoding response", http.StatusInternalServerError)
}
})

// Start the server on port 13000
log.Println("Server starting on port 13000...")
log.Fatal(http.ListenAndServe(":13000", nil))

Check failure

Code scanning / gosec

Use of net/http serve function that has no support for setting timeouts Error

Use of net/http serve function that has no support for setting timeouts
}

0 comments on commit 2583368

Please sign in to comment.