@@ -23,32 +23,22 @@ import (
23
23
"fmt"
24
24
"github.com/djcass44/cso-proxy/internal/adapter/harbor"
25
25
"github.com/djcass44/go-utils/pkg/httputils"
26
- "github.com/gorilla/mux"
27
26
"github.com/quay/container-security-operator/secscan"
28
27
"github.com/quay/container-security-operator/secscan/quay"
29
28
log "github.com/sirupsen/logrus"
30
29
"io/ioutil"
31
30
"net"
32
31
"net/http"
33
32
"net/url"
34
- "path/filepath "
33
+ "strings "
35
34
"time"
36
35
)
37
36
38
37
type Harbor struct {}
39
38
40
- func NewHarborAdapter (router * mux. Router ) * Harbor {
39
+ func NewHarborAdapter () * Harbor {
41
40
h := new (Harbor )
42
41
43
- router .HandleFunc ("/cso/v1/repository/{registry}/{namespace}/{reponame}/manifest/{digest}/security" , h .ManifestSecurity ).
44
- Methods (http .MethodGet )
45
- router .HandleFunc ("/cso/v1/repository/{namespace}/{reponame}/manifest/{digest}/security" , h .ManifestSecurity ).
46
- Methods (http .MethodGet )
47
- router .HandleFunc ("/cso/v1/repository/{registry}/{namespace}/{reponame}/image/{imageid}/security" , h .ImageSecurity ).
48
- Methods (http .MethodGet )
49
- router .HandleFunc ("/cso/v1/repository/{namespace}/{reponame}/image/{imageid}/security" , h .ImageSecurity ).
50
- Methods (http .MethodGet )
51
-
52
42
return h
53
43
}
54
44
@@ -70,56 +60,22 @@ func (*Harbor) Capabilities(uri *url.URL) *quay.AppCapabilities {
70
60
ImageSecurity : struct {
71
61
RestApiTemplate string `json:"rest-api-template"`
72
62
}{
73
- RestApiTemplate : fmt . Sprintf ( "%s/cso/v1/repository/{namespace}/{reponame}/image/{imageid}/security" , appURL ) ,
63
+ RestApiTemplate : "" ,
74
64
},
75
65
},
76
66
}
77
67
}
78
68
79
- func (h * Harbor ) ManifestSecurity (w http.ResponseWriter , r * http.Request ) {
80
- features , vulnerabilities := r .URL .Query ().Get ("features" ) == "true" , r .URL .Query ().Get ("vulnerabilities" ) == "true"
81
- vars := mux .Vars (r )
82
- registry , namespace , reponame , digest := vars ["registry" ], vars ["namespace" ], vars ["reponame" ], vars ["digest" ]
83
- log .WithContext (r .Context ()).WithFields (log.Fields {
84
- "registry" : registry ,
69
+ func (h * Harbor ) ManifestSecurity (ctx context.Context , path , digest string , opts Opts ) (* secscan.Response , int , error ) {
70
+ bits := strings .SplitN (path , "/" , 2 )
71
+ namespace , reponame := bits [0 ], bits [1 ]
72
+ log .WithContext (ctx ).WithFields (log.Fields {
85
73
"namespace" : namespace ,
86
74
"reponame" : reponame ,
87
75
"digest" : digest ,
88
76
}).Infof ("fetching manifest information" )
89
- uri := fmt .Sprintf ("https://%s" , r .Host )
90
- if registry != "" {
91
- reponame = url .PathEscape (filepath .Join (namespace , reponame ))
92
- namespace = registry
93
- }
94
- report , code , err := h .vulnerabilityInfo (r .Context (), uri , namespace , reponame , digest , features , vulnerabilities )
95
- if err != nil {
96
- http .Error (w , err .Error (), code )
97
- return
98
- }
99
- httputils .ReturnJSON (w , code , report )
100
- }
101
-
102
- func (h * Harbor ) ImageSecurity (w http.ResponseWriter , r * http.Request ) {
103
- features , vulnerabilities := r .URL .Query ().Get ("features" ) == "true" , r .URL .Query ().Get ("vulnerabilities" ) == "true"
104
- vars := mux .Vars (r )
105
- registry , namespace , reponame , imageid := vars ["registry" ], vars ["namespace" ], vars ["reponame" ], vars ["imageid" ]
106
- log .WithContext (r .Context ()).WithFields (log.Fields {
107
- "registry" : registry ,
108
- "namespace" : namespace ,
109
- "reponame" : reponame ,
110
- "imageid" : imageid ,
111
- }).Infof ("fetching image information" )
112
- if registry != "" {
113
- reponame = url .PathEscape (filepath .Join (namespace , reponame ))
114
- namespace = registry
115
- }
116
- uri := fmt .Sprintf ("https://%s" , r .Host )
117
- report , code , err := h .vulnerabilityInfo (r .Context (), uri , namespace , reponame , imageid , features , vulnerabilities )
118
- if err != nil {
119
- http .Error (w , err .Error (), code )
120
- return
121
- }
122
- httputils .ReturnJSON (w , code , report )
77
+ reponame = url .PathEscape (reponame )
78
+ return h .vulnerabilityInfo (ctx , opts .URI , namespace , reponame , digest , opts .Features , opts .Vulnerabilities )
123
79
}
124
80
125
81
func (* Harbor ) vulnerabilityInfo (ctx context.Context , uri , namespace , repository , reference string , showFeatures , showVulnerabilities bool ) (* secscan.Response , int , error ) {
0 commit comments