Skip to content
This repository was archived by the owner on Jan 8, 2026. It is now read-only.

Commit af051f5

Browse files
authored
fix: github actions lint (#11)
* Ignore build binary Signed-off-by: Ashish Malik <b218008@iiit-bh.ac.in> * Update modules Signed-off-by: Ashish Malik <b218008@iiit-bh.ac.in> * Update CI badge Signed-off-by: Ashish Malik <b218008@iiit-bh.ac.in> * Updated go.mod Signed-off-by: Ashish Malik <b218008@iiit-bh.ac.in> * Removed comments Signed-off-by: Ashish Malik <b218008@iiit-bh.ac.in>
1 parent 3560551 commit af051f5

File tree

6 files changed

+32
-223
lines changed

6 files changed

+32
-223
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
k8s-authz

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Contributions Welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/casbin/k8s-authz/issues)
33
[![Go Report Card](https://goreportcard.com/badge/github.com/casbin/k8s-authz)](https://goreportcard.com/report/github.com/casbin/k8s-authz)
44
[![Coverage Status](https://coveralls.io/repos/github/casbin/k8s-authz/badge.svg?branch=master)](https://coveralls.io/github/casbin/k8s-authz?branch=master)
5-
[![CI](https://github.com/casbin/k8s-authz/workflows/CI/badge.svg)](https://github.com/casbin/k8s-authz/actions?query=workflow%3CI)
5+
[![Go](https://github.com/casbin/k8s-authz/actions/workflows/ci.yaml/badge.svg)](https://github.com/casbin/k8s-authz/actions/workflows/ci.yaml)
66
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/casbin/lobby)
77
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
88

main.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,26 @@ func main() {
3535
Addr: fmt.Sprintf(":%v", port),
3636
TLSConfig: &tls.Config{Certificates: []tls.Certificate{certs}},
3737
}
38-
//cs = CasbinServerHandler{}
38+
cs := CasbinServerHandler{}
3939
router := mux.NewRouter()
40-
router.HandleFunc("/validate", (*CasbinServerHandler).serve)
41-
server.ListenAndServeTLS("", "")
40+
router.HandleFunc("/validate", cs.serve)
4241

42+
if err := server.ListenAndServeTLS("", ""); err != nil {
43+
glog.Error("Server error", err)
44+
}
4345
go func() {
4446
if err := server.ListenAndServeTLS("", ""); err != nil {
4547
glog.Errorf("Failed to listen and serve webhook server: %v", err)
4648
}
4749
}()
4850

49-
glog.Infof("Server running listening in port: ", port)
51+
glog.Info("Server running listening in port: ", port)
5052
signalChan := make(chan os.Signal, 1)
5153
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
5254
<-signalChan
5355
glog.Info("Shutting down webhook server...")
54-
server.Shutdown(context.Background())
56+
if err := server.Shutdown(context.Background()); err != nil {
57+
glog.Error("Unable to shutdown the server", err)
58+
}
59+
5560
}

server.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
operation_name string
2020
)
2121

22-
func (gs *CasbinServerHandler) serve(w http.ResponseWriter, r *http.Request) {
22+
func (cs *CasbinServerHandler) serve(w http.ResponseWriter, r *http.Request) {
2323
var body []byte
2424
if r.Body != nil {
2525
if data, err := ioutil.ReadAll(r.Body); err == nil {
@@ -43,7 +43,11 @@ func (gs *CasbinServerHandler) serve(w http.ResponseWriter, r *http.Request) {
4343
http.Error(w, "incorrect body", http.StatusBadRequest)
4444
}
4545
raw := v1.AdmissionReview{}.Request.Object.Raw
46-
json.Unmarshal([]byte(arRequest.Operation), &operation_name)
46+
47+
if err := json.Unmarshal([]byte(arRequest.Operation), &operation_name); err != nil {
48+
glog.Error("incorrect body")
49+
http.Error(w, "incorrect body", http.StatusBadRequest)
50+
}
4751
user := arRequest.UserInfo.Username
4852

4953
if err := json.Unmarshal(raw, &user); err != nil {
@@ -59,27 +63,26 @@ func (gs *CasbinServerHandler) serve(w http.ResponseWriter, r *http.Request) {
5963
glog.Errorf("Filed to load the policies: %v", err)
6064
return
6165
}
62-
if e.HasPermissionForUser(user, operation_name) == true {
63-
response := v1.AdmissionReview{
64-
Response: &v1.AdmissionResponse{
65-
Allowed: true,
66-
},
67-
}
66+
67+
arReview := v1.AdmissionReview{}
68+
arReview.Response = &v1.AdmissionResponse{
69+
UID: arReview.Request.UID,
70+
Allowed: true,
6871
}
69-
response := v1.AdmissionReview{
70-
Response: &v1.AdmissionResponse{
71-
Allowed: false,
72-
Result: &metav1.Status{
73-
Message: " You are not authorized to perform any operations on these pods!",
74-
},
75-
},
72+
73+
if !e.HasPermissionForUser(user, operation_name) {
74+
arReview.Response.Allowed = false
75+
arReview.Response.Result = &metav1.Status{
76+
Message: " You are not authorized to perform any operations on these pods!",
77+
}
78+
7679
}
77-
resp, err := json.Marshal(response)
80+
resp, err := json.Marshal(arReview)
7881
if err != nil {
7982
glog.Errorf("Can't encode response: %v", err)
8083
http.Error(w, fmt.Sprintf("could not encode response: %v", err), http.StatusInternalServerError)
8184
}
82-
glog.Infof("Ready to write response ...")
85+
glog.Info("Ready to write response ...")
8386
if _, err := w.Write(resp); err != nil {
8487
glog.Errorf("Can't write response: %v", err)
8588
http.Error(w, fmt.Sprintf("could not write response: %v", err), http.StatusInternalServerError)

tests/server_test.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

tests/webhook_test.go

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)