Skip to content

Commit

Permalink
Expand fields for GitLab project (#4861)
Browse files Browse the repository at this point in the history
* Expand fields for GitLab project

Get some more data. Also improve help to make it more clear what format
the URL needs to be in

Signed-off-by: Tim Smith <tsmith84@gmail.com>

* Update providers/gitlab/resources/gitlab.lr

Co-authored-by: Letha <letha@mondoo.com>

* Remove license and email for now

Signed-off-by: Tim Smith <tsmith84@gmail.com>

* Fix in the indents

Signed-off-by: Tim Smith <tsmith84@gmail.com>

---------

Signed-off-by: Tim Smith <tsmith84@gmail.com>
Co-authored-by: Letha <letha@mondoo.com>
  • Loading branch information
tas50 and misterpantz authored Nov 19, 2024
1 parent a20e12c commit 7cd1ec5
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 19 deletions.
2 changes: 1 addition & 1 deletion providers/gitlab/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var Config = plugin.Provider{
Long: "url",
Type: plugin.FlagType_String,
Default: "",
Desc: "Custom GitLab base url",
Desc: "Custom GitLab base URL (https://example.com/)",
},
},
},
Expand Down
13 changes: 10 additions & 3 deletions providers/gitlab/resources/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ func getGitlabProjectArgs(prj *gitlab.Project) map[string]*llx.RawData {
"visibility": llx.StringData(string(prj.Visibility)),
"webURL": llx.StringData(prj.WebURL),
"wikiEnabled": llx.BoolData(prj.WikiEnabled),
"jobsEnabled": llx.BoolData(prj.JobsEnabled),
"emptyRepo": llx.BoolData(prj.EmptyRepo),
"sharedRunnersEnabled": llx.BoolData(prj.SharedRunnersEnabled),
"groupRunnersEnabled": llx.BoolData(prj.GroupRunnersEnabled),
}
}

Expand Down Expand Up @@ -141,6 +145,7 @@ func (p *mqlGitlabProject) approvalSettings() (*mqlGitlabProjectApprovalSetting,
"mergeRequestsAuthorApproval": llx.BoolData(approvalConfig.MergeRequestsAuthorApproval),
"mergeRequestsDisableCommittersApproval": llx.BoolData(approvalConfig.MergeRequestsDisableCommittersApproval),
"requirePasswordToApprove": llx.BoolData(approvalConfig.RequirePasswordToApprove),
"selectiveCodeOwnerRemovals": llx.BoolData(approvalConfig.SelectiveCodeOwnerRemovals),
}

mqlApprovalSettings, err := CreateResource(p.MqlRuntime, "gitlab.project.approvalSetting", approvalSettings)
Expand Down Expand Up @@ -286,9 +291,11 @@ func (p *mqlGitlabProject) projectMembers() ([]interface{}, error) {
for _, member := range members {
role := mapAccessLevelToRole(int(member.AccessLevel))
memberInfo := map[string]*llx.RawData{
"id": llx.IntData(int64(member.ID)),
"name": llx.StringData(member.Name),
"role": llx.StringData(role),
"id": llx.IntData(int64(member.ID)),
"username": llx.StringData(member.Username),
"state": llx.StringData(member.State),
"name": llx.StringData(member.Name),
"role": llx.StringData(role),
}

mqlMember, err := CreateResource(p.MqlRuntime, "gitlab.project.member", memberInfo)
Expand Down
38 changes: 25 additions & 13 deletions providers/gitlab/resources/gitlab.lr
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ gitlab.project @defaults("fullName visibility webURL") {
// Project path
path string
// Create date of the project
createdAt time
createdAt time
// Project description
description string
// Default Git branch
Expand All @@ -66,21 +66,21 @@ gitlab.project @defaults("fullName visibility webURL") {
onlyAllowMergeIfAllDiscussionsAreResolved bool
// Whether the issues feature is enabled
issuesEnabled bool
// Whether the merge request feature is enabled
// Whether the merge request feature is enabled
mergeRequestsEnabled bool
// Whether the wiki feature is enabled
// Whether the wiki feature is enabled
wikiEnabled bool
// Whether the snippets feature is enabled
// Whether the snippets feature is enabled
snippetsEnabled bool
// Whether the container registry feature is enabled
// Whether the container registry feature is enabled
containerRegistryEnabled bool
// Whether the Service Desk feature is enabled
// Whether the Service Desk feature is enabled
serviceDeskEnabled bool
// Whether the packages feature is enabled
// Whether the packages feature is enabled
packagesEnabled bool
// Whether the Auto DevOps feature is enabled
// Whether the Auto DevOps feature is enabled
autoDevopsEnabled bool
// Whether the requirements feature is enabled
// Whether the requirements feature is enabled
requirementsEnabled bool
// Approval rules for the project
approvalRules() []gitlab.project.approvalRule
Expand All @@ -96,9 +96,16 @@ gitlab.project @defaults("fullName visibility webURL") {
projectFiles() []gitlab.project.file
// List of webhooks for the project
webhooks() []gitlab.project.webhook
// Whether CI jobs are enabled
jobsEnabled bool
// Whether the repo is empty
emptyRepo bool
// Whether the project is enabled for shared runners
sharedRunnersEnabled bool
// Whether the project is enabled for group runners
groupRunnersEnabled bool
}


// GitLab project approval rule
private gitlab.project.approvalRule @defaults("id name approvalsRequired") {
// Rule ID
Expand All @@ -123,9 +130,10 @@ private gitlab.project.approvalSetting @defaults("approvalsBeforeMerge requirePa
mergeRequestsDisableCommittersApproval bool
// Whether a password is required to approve
requirePasswordToApprove bool
// Whether approvals are reset from Code Owners if their files changed
selectiveCodeOwnerRemovals bool
}


// GitLab protected branch
private gitlab.project.protectedBranch @defaults("name allowForcePush") {
// Branch name
Expand All @@ -139,13 +147,17 @@ private gitlab.project.protectedBranch @defaults("name allowForcePush") {
}

// GitLab project member
gitlab.project.member @defaults("id name role") {
gitlab.project.member @defaults("username role name") {
// Member ID
id int
// Member name
name string
// Member role
role string
// Member username
username string
// Member state
state string
}

// GitLab project file
Expand All @@ -166,4 +178,4 @@ private gitlab.project.webhook @defaults("url sslVerification") {
url string
// Whether SSL verification is enabled
sslVerification bool
}
}
84 changes: 84 additions & 0 deletions providers/gitlab/resources/gitlab.lr.go

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

13 changes: 11 additions & 2 deletions providers/gitlab/resources/gitlab.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ resources:
visibility: {}
webURL:
min_mondoo_version: 9.0.0
maturity: experimental
min_mondoo_version: 5.15.0
gitlab.project:
fields:
Expand All @@ -44,11 +43,17 @@ resources:
description: {}
emailsDisabled:
min_mondoo_version: 9.0.0
emptyRepo:
min_mondoo_version: 9.0.0
fullName:
min_mondoo_version: 9.0.0
groupRunnersEnabled:
min_mondoo_version: 9.0.0
id: {}
issuesEnabled:
min_mondoo_version: 9.0.0
jobsEnabled:
min_mondoo_version: 9.0.0
mergeMethod:
min_mondoo_version: 9.0.0
mergeRequestsEnabled:
Expand All @@ -73,6 +78,8 @@ resources:
min_mondoo_version: 9.0.0
serviceDeskEnabled:
min_mondoo_version: 9.0.0
sharedRunnersEnabled:
min_mondoo_version: 9.0.0
snippetsEnabled:
min_mondoo_version: 9.0.0
visibility: {}
Expand All @@ -82,7 +89,6 @@ resources:
min_mondoo_version: 9.0.0
wikiEnabled:
min_mondoo_version: 9.0.0
maturity: experimental
min_mondoo_version: 5.15.0
gitlab.project.approvalRule:
fields:
Expand All @@ -99,6 +105,7 @@ resources:
mergeRequestsDisableCommittersApproval: {}
requirePasswordToApprove: {}
resetApprovalsOnPush: {}
selectiveCodeOwnerRemovals: {}
is_private: true
min_mondoo_version: 9.0.0
gitlab.project.file:
Expand All @@ -114,6 +121,8 @@ resources:
id: {}
name: {}
role: {}
state: {}
username: {}
min_mondoo_version: 9.0.0
gitlab.project.protectedBranch:
fields:
Expand Down

0 comments on commit 7cd1ec5

Please sign in to comment.