Skip to content

Commit

Permalink
⭐️ Adding the support to fetch the webhooks and the ssl config (Gitla…
Browse files Browse the repository at this point in the history
…b) (#4400)

* Add the support to fetch the webhooks and the ssl config

Signed-off-by: Hossein Rouhani <h_rouhani@hotmail.com>

* rebase and adjust

Signed-off-by: Hossein Rouhani <h_rouhani@hotmail.com>

---------

Signed-off-by: Hossein Rouhani <h_rouhani@hotmail.com>
  • Loading branch information
HRouhani authored Jul 24, 2024
1 parent e9d1830 commit 9541436
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
34 changes: 34 additions & 0 deletions providers/gitlab/resources/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,37 @@ func (p *mqlGitlabProject) projectFiles() ([]interface{}, error) {

return mqlFiles, nil
}

// id function for a unique identifier for a resource instance gitlab.project.webhook
func (g *mqlGitlabProjectWebhook) id() (string, error) {
return g.Url.Data, nil
}

// Function to fetch and check the webhooks for a project
func (p *mqlGitlabProject) webhooks() ([]interface{}, error) {
conn := p.MqlRuntime.Connection.(*connection.GitLabConnection)

projectID := int(p.Id.Data)

hooks, _, err := conn.Client().Projects.ListProjectHooks(projectID, nil)
if err != nil {
return nil, err
}

var mqlWebhooks []interface{}
for _, hook := range hooks {
hookInfo := map[string]*llx.RawData{
"url": llx.StringData(hook.URL),
"sslVerification": llx.BoolData(hook.EnableSSLVerification),
}

mqlWebhook, err := CreateResource(p.MqlRuntime, "gitlab.project.webhook", hookInfo)
if err != nil {
return nil, err
}

mqlWebhooks = append(mqlWebhooks, mqlWebhook)
}

return mqlWebhooks, nil
}
10 changes: 10 additions & 0 deletions providers/gitlab/resources/gitlab.lr
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ gitlab.project @defaults("fullName visibility webURL") {
projectMembers() []gitlab.project.member
// List of files in the project repository
projectFiles() []gitlab.project.file
// List of webhooks for the project
webhooks() []gitlab.project.webhook
}


Expand Down Expand Up @@ -156,4 +158,12 @@ private gitlab.project.file @defaults("path type") {
name string
// File content
content string
}

// GitLab project webhook
private gitlab.project.webhook @defaults("url sslVerification") {
// Webhook URL
url string
// Whether SSL verification is enabled
sslVerification bool
}
8 changes: 8 additions & 0 deletions providers/gitlab/resources/gitlab.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ resources:
visibility: {}
webURL:
min_mondoo_version: 9.0.0
webhooks:
min_mondoo_version: 9.0.0
wikiEnabled:
min_mondoo_version: 9.0.0
maturity: experimental
Expand Down Expand Up @@ -121,3 +123,9 @@ resources:
name: {}
is_private: true
min_mondoo_version: 9.0.0
gitlab.project.webhook:
fields:
sslVerification: {}
url: {}
is_private: true
min_mondoo_version: 9.0.0

0 comments on commit 9541436

Please sign in to comment.