From 7770470a9e201a9e9b6490fce9ea4ee8c5630e71 Mon Sep 17 00:00:00 2001 From: Rocktavious Date: Fri, 21 Oct 2022 21:20:31 -0500 Subject: [PATCH] check feature parity and update opslevel-go --- .../Dependency-20221021-210422.yaml | 3 + .../unreleased/Feature-20221021-210156.yaml | 3 + .../unreleased/Feature-20221021-210214.yaml | 3 + .../unreleased/Feature-20221021-210236.yaml | 3 + .../unreleased/Feature-20221021-210249.yaml | 3 + .../unreleased/Feature-20221021-210301.yaml | 3 + .gitignore | 1 + src/cmd/check.go | 73 +++++++++++++++++-- src/go.mod | 2 +- src/go.sum | 13 +++- 10 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 .changes/unreleased/Dependency-20221021-210422.yaml create mode 100644 .changes/unreleased/Feature-20221021-210156.yaml create mode 100644 .changes/unreleased/Feature-20221021-210214.yaml create mode 100644 .changes/unreleased/Feature-20221021-210236.yaml create mode 100644 .changes/unreleased/Feature-20221021-210249.yaml create mode 100644 .changes/unreleased/Feature-20221021-210301.yaml diff --git a/.changes/unreleased/Dependency-20221021-210422.yaml b/.changes/unreleased/Dependency-20221021-210422.yaml new file mode 100644 index 00000000..774d8a05 --- /dev/null +++ b/.changes/unreleased/Dependency-20221021-210422.yaml @@ -0,0 +1,3 @@ +kind: Dependency +body: bump opslevel-go to 2022.10.22 +time: 2022-10-21T21:04:22.197974-05:00 diff --git a/.changes/unreleased/Feature-20221021-210156.yaml b/.changes/unreleased/Feature-20221021-210156.yaml new file mode 100644 index 00000000..70ea0c7a --- /dev/null +++ b/.changes/unreleased/Feature-20221021-210156.yaml @@ -0,0 +1,3 @@ +kind: Feature +body: Add support for check type 'HasRecentDeploy' +time: 2022-10-21T21:01:56.930212-05:00 diff --git a/.changes/unreleased/Feature-20221021-210214.yaml b/.changes/unreleased/Feature-20221021-210214.yaml new file mode 100644 index 00000000..b6a683aa --- /dev/null +++ b/.changes/unreleased/Feature-20221021-210214.yaml @@ -0,0 +1,3 @@ +kind: Feature +body: Add support for check type 'HasDocumentation' +time: 2022-10-21T21:02:14.849837-05:00 diff --git a/.changes/unreleased/Feature-20221021-210236.yaml b/.changes/unreleased/Feature-20221021-210236.yaml new file mode 100644 index 00000000..7469785f --- /dev/null +++ b/.changes/unreleased/Feature-20221021-210236.yaml @@ -0,0 +1,3 @@ +kind: Feature +body: Add support for check type 'AlertSourceUsage' +time: 2022-10-21T21:02:36.747703-05:00 diff --git a/.changes/unreleased/Feature-20221021-210249.yaml b/.changes/unreleased/Feature-20221021-210249.yaml new file mode 100644 index 00000000..dd6e5121 --- /dev/null +++ b/.changes/unreleased/Feature-20221021-210249.yaml @@ -0,0 +1,3 @@ +kind: Feature +body: Add support for check type 'GitBranchProtection' +time: 2022-10-21T21:02:49.291798-05:00 diff --git a/.changes/unreleased/Feature-20221021-210301.yaml b/.changes/unreleased/Feature-20221021-210301.yaml new file mode 100644 index 00000000..4f57ca41 --- /dev/null +++ b/.changes/unreleased/Feature-20221021-210301.yaml @@ -0,0 +1,3 @@ +kind: Feature +body: Add support for check type 'ServiceDependency' +time: 2022-10-21T21:03:01.483957-05:00 diff --git a/.gitignore b/.gitignore index bcfc81fb..d5ca8668 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ ./src/opslevel src/dist .idea +.DS_Store diff --git a/src/cmd/check.go b/src/cmd/check.go index f0ba78a9..7fb88b7b 100644 --- a/src/cmd/check.go +++ b/src/cmd/check.go @@ -200,6 +200,12 @@ func (self *CheckCreateType) AsServiceOwnershipCreateInput() *opslevel.CheckServ return payload } +func (self *CheckCreateType) AsHasRecentDeployCreateInput() *opslevel.CheckHasRecentDeployCreateInput { + payload := &opslevel.CheckHasRecentDeployCreateInput{} + json.Unmarshal(toJson(self.Spec), payload) + return payload +} + func (self *CheckCreateType) AsServicePropertyCreateInput() *opslevel.CheckServicePropertyCreateInput { payload := &opslevel.CheckServicePropertyCreateInput{} json.Unmarshal(toJson(self.Spec), payload) @@ -212,8 +218,8 @@ func (self *CheckCreateType) AsServiceConfigurationCreateInput() *opslevel.Check return payload } -func (self *CheckCreateType) AsRepositoryFileCreateInput() *opslevel.CheckRepositoryFileCreateInput { - payload := &opslevel.CheckRepositoryFileCreateInput{} +func (self *CheckCreateType) AsHasDocumentationCreateInput() *opslevel.CheckHasDocumentationCreateInput { + payload := &opslevel.CheckHasDocumentationCreateInput{} json.Unmarshal(toJson(self.Spec), payload) return payload } @@ -224,8 +230,8 @@ func (self *CheckCreateType) AsRepositoryIntegratedCreateInput() *opslevel.Check return payload } -func (self *CheckCreateType) AsRepositorySearchCreateInput() *opslevel.CheckRepositorySearchCreateInput { - payload := &opslevel.CheckRepositorySearchCreateInput{} +func (self *CheckCreateType) AsToolUsageCreateInput() *opslevel.CheckToolUsageCreateInput { + payload := &opslevel.CheckToolUsageCreateInput{} json.Unmarshal(toJson(self.Spec), payload) return payload } @@ -236,8 +242,14 @@ func (self *CheckCreateType) AsTagDefinedCreateInput() *opslevel.CheckTagDefined return payload } -func (self *CheckCreateType) AsToolUsageCreateInput() *opslevel.CheckToolUsageCreateInput { - payload := &opslevel.CheckToolUsageCreateInput{} +func (self *CheckCreateType) AsRepositoryFileCreateInput() *opslevel.CheckRepositoryFileCreateInput { + payload := &opslevel.CheckRepositoryFileCreateInput{} + json.Unmarshal(toJson(self.Spec), payload) + return payload +} + +func (self *CheckCreateType) AsRepositorySearchCreateInput() *opslevel.CheckRepositorySearchCreateInput { + payload := &opslevel.CheckRepositorySearchCreateInput{} json.Unmarshal(toJson(self.Spec), payload) return payload } @@ -248,6 +260,24 @@ func (self *CheckCreateType) AsManualCreateInput() *opslevel.CheckManualCreateIn return payload } +func (self *CheckCreateType) AsAlertSourceUsageCreateInput() *opslevel.CheckAlertSourceUsageCreateInput { + payload := &opslevel.CheckAlertSourceUsageCreateInput{} + json.Unmarshal(toJson(self.Spec), payload) + return payload +} + +func (self *CheckCreateType) AsGitBranchProtectionCreateInput() *opslevel.CheckGitBranchProtectionCreateInput { + payload := &opslevel.CheckGitBranchProtectionCreateInput{} + json.Unmarshal(toJson(self.Spec), payload) + return payload +} + +func (self *CheckCreateType) AsServiceDependencyCreateInput() *opslevel.CheckServiceDependencyCreateInput { + payload := &opslevel.CheckServiceDependencyCreateInput{} + json.Unmarshal(toJson(self.Spec), payload) + return payload +} + func (self *CheckCreateType) resolveIntegrationAliases(client *opslevel.Client, usePrompt bool) error { if item, ok := self.Spec["integration"]; ok { delete(self.Spec, "integration") @@ -297,12 +327,18 @@ func createCheck(input CheckCreateType, usePrompts bool) (*opslevel.Check, error case opslevel.CheckTypeHasOwner: output, err = clientGQL.CreateCheckServiceOwnership(*input.AsServiceOwnershipCreateInput()) + case opslevel.CheckTypeHasRecentDeploy: + output, err = clientGQL.CreateCheckHasRecentDeploy(*input.AsHasRecentDeployCreateInput()) + case opslevel.CheckTypeServiceProperty: output, err = clientGQL.CreateCheckServiceProperty(*input.AsServicePropertyCreateInput()) case opslevel.CheckTypeHasServiceConfig: output, err = clientGQL.CreateCheckServiceConfiguration(*input.AsServiceConfigurationCreateInput()) + case opslevel.CheckTypeHasDocumentation: + output, err = clientGQL.CreateCheckHasDocumentation(*input.AsHasDocumentationCreateInput()) + case opslevel.CheckTypeHasRepository: output, err = clientGQL.CreateCheckRepositoryIntegrated(*input.AsRepositoryIntegratedCreateInput()) @@ -326,6 +362,15 @@ func createCheck(input CheckCreateType, usePrompts bool) (*opslevel.Check, error err = input.resolveIntegrationAliases(clientGQL, usePrompts) cobra.CheckErr(err) output, err = clientGQL.CreateCheckCustomEvent(*input.AsCustomEventCreateInput()) + + case opslevel.CheckTypeAlertSourceUsage: + output, err = clientGQL.CreateCheckAlertSourceUsage(*input.AsAlertSourceUsageCreateInput()) + + case opslevel.CheckTypeGitBranchProtection: + output, err = clientGQL.CreateCheckGitBranchProtection(*input.AsGitBranchProtectionCreateInput()) + + case opslevel.CheckTypeServiceDependency: + output, err = clientGQL.CreateCheckServiceDependency(*input.AsServiceDependencyCreateInput()) } cobra.CheckErr(err) if output == nil { @@ -355,12 +400,19 @@ func marshalCheck(check opslevel.Check) *CheckCreateType { switch check.Type { case opslevel.CheckTypeHasOwner: + case opslevel.CheckTypeHasRecentDeploy: + output.Spec["days"] = check.HasRecentDeployCheckFragment.Days + case opslevel.CheckTypeServiceProperty: output.Spec["serviceProperty"] = check.ServicePropertyCheckFragment.Property output.Spec["propertyValuePredicate"] = check.ServicePropertyCheckFragment.Predicate case opslevel.CheckTypeHasServiceConfig: + case opslevel.CheckTypeHasDocumentation: + output.Spec["documentType"] = check.HasDocumentationCheckFragment.DocumentType + output.Spec["documentSubtype"] = check.HasDocumentationCheckFragment.DocumentSubtype + case opslevel.CheckTypeHasRepository: case opslevel.CheckTypeToolUsage: @@ -394,6 +446,15 @@ func marshalCheck(check opslevel.Check) *CheckCreateType { output.Spec["serviceSelector"] = check.CustomEventCheckFragment.ServiceSelector output.Spec["successCondition"] = check.CustomEventCheckFragment.SuccessCondition output.Spec["message"] = check.CustomEventCheckFragment.ResultMessage + + case opslevel.CheckTypeAlertSourceUsage: + output.Spec["alertSourceNamePredicate"] = check.AlertSourceUsageCheckFragment.AlertSourceNamePredicate + output.Spec["alertSourceType"] = check.AlertSourceUsageCheckFragment.AlertSourceType + + case opslevel.CheckTypeGitBranchProtection: + + case opslevel.CheckTypeServiceDependency: + } return output diff --git a/src/go.mod b/src/go.mod index e8000828..eb86f4fd 100644 --- a/src/go.mod +++ b/src/go.mod @@ -9,7 +9,7 @@ require ( github.com/gosimple/slug v1.13.1 github.com/manifoldco/promptui v0.9.0 github.com/open-policy-agent/opa v0.45.0 - github.com/opslevel/opslevel-go/v2022 v2022.8.25 + github.com/opslevel/opslevel-go/v2022 v2022.10.22 github.com/relvacode/iso8601 v1.1.0 github.com/rocktavious/autopilot v0.1.5 github.com/rs/zerolog v1.28.0 diff --git a/src/go.sum b/src/go.sum index 7f98caea..65e1f57d 100644 --- a/src/go.sum +++ b/src/go.sum @@ -38,6 +38,9 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= +github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= +github.com/Masterminds/sprig/v3 v3.2.2 h1:17jRggJu518dr3QaafizSXOjKYp94wKfABxUmyxvxX8= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY= @@ -179,6 +182,7 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= @@ -198,6 +202,7 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/huandu/xstrings v1.3.1 h1:4jgBlKK6tLKFvO8u5pmYjG91cqytmDCDvGh7ECVFfFs= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= @@ -234,15 +239,17 @@ github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9 github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI= github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg= +github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs= github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/open-policy-agent/opa v0.45.0 h1:P5nuhVRtR+e58fk3CMMbiqr6ZFyWQPNOC3otsorGsFs= github.com/open-policy-agent/opa v0.45.0/go.mod h1:/OnsYljNEWJ6DXeFOOnoGn8CvwZGMUS4iRqzYdJvmBI= -github.com/opslevel/opslevel-go/v2022 v2022.8.25 h1:SUYm84vJei6fErxtfz5KpQFIpPFyr1x8eYUTcuSOTrY= -github.com/opslevel/opslevel-go/v2022 v2022.8.25/go.mod h1:2/cWgSTLK/6n7XlXe4kqG7IeHlNyjpP+BJ+YbKj28JM= +github.com/opslevel/opslevel-go/v2022 v2022.10.22 h1:AUOh2B1Ata/fyrXhIMrlnJ+ymiDdbUpXArmLoaFipcI= +github.com/opslevel/opslevel-go/v2022 v2022.10.22/go.mod h1:eP1z9RRBgY4hs2kDOiM1ZFhT+zXOwxOjkHs14TdO+U8= github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM= github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml/v2 v2.0.0-beta.8 h1:dy81yyLYJDwMTifq24Oi/IslOslRrDSb3jwDggjz3Z0= @@ -264,6 +271,7 @@ github.com/relvacode/iso8601 v1.1.0 h1:2nV8sp0eOjpoKQ2vD3xSDygsjAx37NHG2UlZiCkDH github.com/relvacode/iso8601 v1.1.0/go.mod h1:FlNp+jz+TXpyRqgmM7tnzHHzBnz776kmAH2h3sZCn0I= github.com/rocktavious/autopilot v0.1.5 h1:qrKDFbVI3pskUKfiCNkWzlDlBs9Xn4kn5AfwTLoJwnY= github.com/rocktavious/autopilot v0.1.5/go.mod h1:UFzF0IumK28znz4qO4YxR3HXwM7/abz8jBtdLO8soMY= +github.com/rocktavious/autopilot/v2022 v2022.8.28 h1:wS8wkvtv81UNyahR+x0DTkRcBkx9gSJimMV/yOJFj0E= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY= @@ -271,6 +279,7 @@ github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6us github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29 h1:B1PEwpArrNp4dkQrfxh/abbBAOZBVp0ds+fBEOUOqOc= github.com/shurcooL/graphql v0.0.0-20220606043923-3cf50f8a0a29/go.mod h1:AuYgA5Kyo4c7HfUmvRGs/6rGlMMV/6B1bVnB9JxJEEg= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=