Skip to content

Commit

Permalink
Update assets/credhub-service-broker
Browse files Browse the repository at this point in the history
Replaces gorilla/mux with go-chi/chi. The former project is deprecated
and unsupported, so we needed to move off it. chi should provide all of
the same functions as gorilla while hopefully remaining in support into
the future.
  • Loading branch information
ctlong committed May 19, 2023
1 parent 8b36f1c commit d753657
Show file tree
Hide file tree
Showing 50 changed files with 4,784 additions and 3,002 deletions.
2 changes: 1 addition & 1 deletion assets/credhub-service-broker/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
code.cloudfoundry.org/credhub-cli v0.0.0-20230320130818-a7d5420b283b
github.com/gorilla/mux v1.8.0
github.com/go-chi/chi/v5 v5.0.8
github.com/satori/go.uuid v1.2.0
)

Expand Down
24 changes: 7 additions & 17 deletions assets/credhub-service-broker/go.sum
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
code.cloudfoundry.org/credhub-cli v0.0.0-20230227140157-de58674f78a8 h1:DDhc3bLiHZ93naghRK6amRDghfYF7eWeCBMWzoy/Ncs=
code.cloudfoundry.org/credhub-cli v0.0.0-20230227140157-de58674f78a8/go.mod h1:ETNLtLjOySc8HLg3Jwu2BSQ9EQVgRLB7nEScNUTd/hQ=
code.cloudfoundry.org/credhub-cli v0.0.0-20230320130818-a7d5420b283b h1:spZNQ1I35NIy06pLTieIEfqWgzZ9DoZ1SkouhGwSXa8=
code.cloudfoundry.org/credhub-cli v0.0.0-20230320130818-a7d5420b283b/go.mod h1:kYbE3eZ8uDWs2YVVXs1edhaqeKSPbKh5CCkGw7OEeig=
github.com/cloudfoundry/go-socks5 v0.0.0-20180221174514-54f73bdb8a8e h1:FQdRViaoDphGRfgrotl2QGsX1gbloe57dbGBS5CG6KY=
github.com/cloudfoundry/go-socks5 v0.0.0-20180221174514-54f73bdb8a8e/go.mod h1:PXmcacyJB/pJjSxEl15IU6rEIKXrhZQRzsr0UTkgNNs=
github.com/cloudfoundry/socks5-proxy v0.2.85 h1:gncRmGJbCV+zY4YL6pO0YKt3vlODcQHlfM1GtHoBRLk=
github.com/cloudfoundry/socks5-proxy v0.2.85/go.mod h1:Sxpx0eb2A4gXq2OEBFv02gyQkeTZl5DIlmykoMspFjQ=
github.com/cloudfoundry/socks5-proxy v0.2.86 h1:thVO9X3rVhGdZw/u8DW0SqQ8GzDVsIi6htYD6m81Rhc=
github.com/cloudfoundry/socks5-proxy v0.2.86/go.mod h1:q5ZvHFcPN7+RtNnsorEyw9XFGTiXx9STc5YwbafdEZM=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0=
github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand All @@ -22,27 +18,21 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/gomega v1.27.1 h1:rfztXRbg6nv/5f+Raen9RcGoSecHIFgBBLQK3Wdj754=
github.com/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
Expand Down
30 changes: 18 additions & 12 deletions assets/credhub-service-broker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
"code.cloudfoundry.org/credhub-cli/credhub/auth"
"code.cloudfoundry.org/credhub-cli/credhub/credentials/values"
"code.cloudfoundry.org/credhub-cli/util"
"github.com/gorilla/mux"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
uuid "github.com/satori/go.uuid"
)

Expand All @@ -35,17 +36,24 @@ type bindRequest struct {
}

func (s *Server) Start() {
router := mux.NewRouter()
router := chi.NewRouter()
router.Use(middleware.Recoverer)

s.sb = &ServiceBroker{
NameMap: make(map[string]string),
}

router.HandleFunc("/v2/catalog", s.sb.Catalog).Methods("GET")
router.HandleFunc("/v2/service_instances/{service_instance_guid}", s.sb.CreateServiceInstance).Methods("PUT")
router.HandleFunc("/v2/service_instances/{service_instance_guid}", s.sb.RemoveServiceInstance).Methods("DELETE")
router.HandleFunc("/v2/service_instances/{service_instance_guid}/service_bindings/{service_binding_guid}", s.sb.Bind).Methods("PUT")
router.HandleFunc("/v2/service_instances/{service_instance_guid}/service_bindings/{service_binding_guid}", s.sb.UnBind).Methods("DELETE")
router.Get("/v2/catalog", s.sb.Catalog)

router.Route("/v2/service_instances", func(r chi.Router) {
r.Put("/{service_instance_guid}", s.sb.CreateServiceInstance)
r.Delete("/{service_instance_guid}", s.sb.RemoveServiceInstance)

r.Route("/{service_instance_guid}/service_bindings", func(r chi.Router) {
r.Put("/{service_binding_guid}", s.sb.Bind)
r.Delete("/{service_binding_guid}", s.sb.UnBind)
})
})

http.Handle("/", router)

Expand All @@ -62,7 +70,7 @@ type ServiceBroker struct {

func WriteResponse(w http.ResponseWriter, code int, response string) {
w.WriteHeader(code)
fmt.Fprintf(w, string(response))
fmt.Fprint(w, string(response))
}

func (s *ServiceBroker) Catalog(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -125,8 +133,7 @@ func (s *ServiceBroker) Bind(w http.ResponseWriter, r *http.Request) {
cred, err := ch.SetJSON(name, storedJson)
handleError(err)

pathVariables := mux.Vars(r)
s.NameMap[pathVariables["service_binding_guid"]] = name
s.NameMap[chi.URLParam(r, "service_binding_guid")] = name

if body.AppGuid != "" {
_, err = ch.AddPermission(cred.Name, "mtls-app:"+body.AppGuid, []string{"read"})
Expand All @@ -153,8 +160,7 @@ func (s *ServiceBroker) UnBind(w http.ResponseWriter, r *http.Request) {
fmt.Println("credhub client configuration failed: " + err.Error())
}

pathVariables := mux.Vars(r)
name := s.NameMap[pathVariables["service_binding_guid"]]
name := s.NameMap[chi.URLParam(r, "service_binding_guid")]

err = ch.Delete(name)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d753657

Please sign in to comment.