@@ -20,14 +20,15 @@ import (
2020 "github.com/mindersec/minder/internal/util/ptr"
2121 minderv1 "github.com/mindersec/minder/pkg/api/protobuf/go/minder/v1"
2222 "github.com/mindersec/minder/pkg/entities/properties"
23+ provifv1 "github.com/mindersec/minder/pkg/providers/v1"
2324)
2425
2526// RegisterEntity implements the Provider interface
2627func (c * gitlabClient ) RegisterEntity (
2728 ctx context.Context , entType minderv1.Entity , props * properties.Properties ,
2829) (* properties.Properties , error ) {
2930 if ! c .SupportsEntity (entType ) {
30- return nil , errors . New ( "unsupported entity type" )
31+ return nil , provifv1 . ErrUnsupportedEntity
3132 }
3233
3334 if entType != minderv1 .Entity_ENTITY_REPOSITORIES {
@@ -88,32 +89,6 @@ func (c *gitlabClient) DeregisterEntity(
8889 return nil
8990}
9091
91- // ReregisterEntity implements the Provider interface
92- func (c * gitlabClient ) ReregisterEntity (
93- ctx context.Context , entType minderv1.Entity , props * properties.Properties ,
94- ) error {
95- if ! c .SupportsEntity (entType ) {
96- return errors .New ("unsupported entity type" )
97- }
98-
99- upstreamID := props .GetProperty (properties .PropertyUpstreamID ).GetString ()
100- if upstreamID == "" {
101- return errors .New ("missing upstream ID" )
102- }
103-
104- hookID := props .GetProperty (RepoPropertyHookID ).GetString ()
105- if hookID == "" {
106- return errors .New ("missing hook ID" )
107- }
108-
109- hookURL := props .GetProperty (RepoPropertyHookURL ).GetString ()
110- if hookURL == "" {
111- return errors .New ("missing hook URL" )
112- }
113-
114- return c .updateWebhook (ctx , upstreamID , hookID , hookURL )
115- }
116-
11792func (c * gitlabClient ) createWebhook (ctx context.Context , upstreamID string ) (* properties.Properties , error ) {
11893 createHookPath , err := url .JoinPath ("projects" , upstreamID , "hooks" )
11994 if err != nil {
@@ -236,64 +211,3 @@ func (c *gitlabClient) cleanUpStaleWebhooks(ctx context.Context, upstreamID stri
236211
237212 return nil
238213}
239-
240- func (c * gitlabClient ) updateWebhook (ctx context.Context , upstreamID , hookID string , hookURL string ) error {
241- // We don't need to update the webhook URL, as it's unique for each
242- // registration. We only need to update the secret.
243- updateHookPath , err := url .JoinPath ("projects" , upstreamID , "hooks" , hookID )
244- if err != nil {
245- return fmt .Errorf ("failed to join URL path for hook: %w" , err )
246- }
247-
248- hookURLParsed , err := url .Parse (hookURL )
249- if err != nil {
250- return fmt .Errorf ("failed to parse hook URL: %w" , err )
251- }
252-
253- // We need to extract the UUID from the webhook URL. The UUID is
254- // the last part of the path.
255- hookMinderUUID := hookURLParsed .Path [strings .LastIndex (hookURLParsed .Path , "/" )+ 1 :]
256-
257- sec , err := webhooksecret .New (c .currentWebhookSecret , hookMinderUUID )
258- if err != nil {
259- return fmt .Errorf ("failed to create webhook secret: %w" , err )
260- }
261-
262- trve := ptr .Ptr (true )
263- hreq := & gitlab.EditProjectHookOptions {
264- URL : & hookURL ,
265- Token : & sec ,
266- PushEvents : trve ,
267- TagPushEvents : trve ,
268- MergeRequestsEvents : trve ,
269- ReleasesEvents : trve ,
270- EnableSSLVerification : trve ,
271- }
272-
273- if err := c .doUpdateWebhook (ctx , updateHookPath , hreq ); err != nil {
274- return fmt .Errorf ("failed to update webhook: %w" , err )
275- }
276-
277- return nil
278- }
279-
280- func (c * gitlabClient ) doUpdateWebhook (
281- ctx context.Context , updateHookPath string , hreq * gitlab.EditProjectHookOptions ,
282- ) error {
283- req , err := c .NewRequest (http .MethodPut , updateHookPath , hreq )
284- if err != nil {
285- return fmt .Errorf ("failed to create request: %w" , err )
286- }
287-
288- resp , err := c .Do (ctx , req )
289- if err != nil {
290- return fmt .Errorf ("failed to get projects: %w" , err )
291- }
292- defer resp .Body .Close ()
293-
294- if resp .StatusCode != http .StatusOK {
295- return fmt .Errorf ("unexpected status code: %d" , resp .StatusCode )
296- }
297-
298- return nil
299- }
0 commit comments