From d06cadbdb4c967be17e303de7368fa860986db5b Mon Sep 17 00:00:00 2001 From: Tim Smith <tsmith84@gmail.com> Date: Sun, 5 May 2024 11:29:47 -0700 Subject: [PATCH] Add new fields for github orgs (#3925) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add new fields for github orgs Grab project data for the org and projects Signed-off-by: Tim Smith <tsmith84@gmail.com> * 🧹 fix whitespace in github lr file --------- Signed-off-by: Tim Smith <tsmith84@gmail.com> Co-authored-by: Christoph Hartmann <chris@lollyrock.com> --- providers/github/resources/github.lr | 4 ++++ providers/github/resources/github.lr.go | 24 +++++++++++++++++++ .../github/resources/github.lr.manifest.yaml | 4 ++++ providers/github/resources/github_org.go | 3 +++ 4 files changed, 35 insertions(+) diff --git a/providers/github/resources/github.lr b/providers/github/resources/github.lr index b4612b8f10..75095a4fef 100644 --- a/providers/github/resources/github.lr +++ b/providers/github/resources/github.lr @@ -128,6 +128,10 @@ github.organization @defaults("login name") { webhooks() []github.webhook // List of packages packages() []github.package + // Whether the organization has projects + hasOrganizationProjects bool + // Whether projects in the organization have projects + hasRepositoryProjects bool } // GitHub user diff --git a/providers/github/resources/github.lr.go b/providers/github/resources/github.lr.go index 726b069c10..c13ea8d9d6 100644 --- a/providers/github/resources/github.lr.go +++ b/providers/github/resources/github.lr.go @@ -344,6 +344,12 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "github.organization.packages": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlGithubOrganization).GetPackages()).ToDataRes(types.Array(types.Resource("github.package"))) }, + "github.organization.hasOrganizationProjects": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlGithubOrganization).GetHasOrganizationProjects()).ToDataRes(types.Bool) + }, + "github.organization.hasRepositoryProjects": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlGithubOrganization).GetHasRepositoryProjects()).ToDataRes(types.Bool) + }, "github.user.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlGithubUser).GetId()).ToDataRes(types.Int) }, @@ -1162,6 +1168,14 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlGithubOrganization).Packages, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "github.organization.hasOrganizationProjects": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlGithubOrganization).HasOrganizationProjects, ok = plugin.RawToTValue[bool](v.Value, v.Error) + return + }, + "github.organization.hasRepositoryProjects": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlGithubOrganization).HasRepositoryProjects, ok = plugin.RawToTValue[bool](v.Value, v.Error) + return + }, "github.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlGithubUser).__id, ok = v.Value.(string) return @@ -2308,6 +2322,8 @@ type mqlGithubOrganization struct { Installations plugin.TValue[[]interface{}] Webhooks plugin.TValue[[]interface{}] Packages plugin.TValue[[]interface{}] + HasOrganizationProjects plugin.TValue[bool] + HasRepositoryProjects plugin.TValue[bool] } // createGithubOrganization creates a new instance of this resource @@ -2591,6 +2607,14 @@ func (c *mqlGithubOrganization) GetPackages() *plugin.TValue[[]interface{}] { }) } +func (c *mqlGithubOrganization) GetHasOrganizationProjects() *plugin.TValue[bool] { + return &c.HasOrganizationProjects +} + +func (c *mqlGithubOrganization) GetHasRepositoryProjects() *plugin.TValue[bool] { + return &c.HasRepositoryProjects +} + // mqlGithubUser for the github.user resource type mqlGithubUser struct { MqlRuntime *plugin.Runtime diff --git a/providers/github/resources/github.lr.manifest.yaml b/providers/github/resources/github.lr.manifest.yaml index 14d816de15..6c5b223e90 100755 --- a/providers/github/resources/github.lr.manifest.yaml +++ b/providers/github/resources/github.lr.manifest.yaml @@ -203,6 +203,10 @@ resources: min_mondoo_version: 7.14.0 following: min_mondoo_version: 7.14.0 + hasOrganizationProjects: + min_mondoo_version: 9.0.0 + hasRepositoryProjects: + min_mondoo_version: 9.0.0 id: {} installations: min_mondoo_version: 5.31.0 diff --git a/providers/github/resources/github_org.go b/providers/github/resources/github_org.go index aa73acc62f..6ecb566f8c 100644 --- a/providers/github/resources/github_org.go +++ b/providers/github/resources/github_org.go @@ -76,6 +76,9 @@ func initGithubOrganization(runtime *plugin.Runtime, args map[string]*llx.RawDat args["twoFactorRequirementEnabled"] = llx.BoolData(convert.ToBool(org.TwoFactorRequirementEnabled)) args["isVerified"] = llx.BoolData(convert.ToBool(org.IsVerified)) + args["hasOrganizationProjects"] = llx.BoolData(convert.ToBool(org.HasOrganizationProjects)) + args["hasRepositoryProjects"] = llx.BoolData(convert.ToBool(org.HasRepositoryProjects)) + args["defaultRepositoryPermission"] = llx.StringDataPtr(org.DefaultRepoPermission) args["membersCanCreateRepositories"] = llx.BoolData(convert.ToBool(org.MembersCanCreateRepos)) args["membersCanCreatePublicRepositories"] = llx.BoolData(convert.ToBool(org.MembersCanCreatePublicRepos))