From d4ad8b41298da90841c0b69b25093fec9531122a Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 2 Oct 2023 14:03:01 +0200 Subject: [PATCH 01/90] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20atlassian=20provider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marius Kimmina --- Makefile | 33 +- providers/atlassian/config/config.go | 18 + providers/atlassian/connection/connection.go | 37 ++ providers/atlassian/gen/main.go | 10 + providers/atlassian/go.mod | 55 ++ providers/atlassian/go.sum | 575 ++++++++++++++++++ providers/atlassian/main.go | 12 + providers/atlassian/provider/provider.go | 191 ++++++ providers/atlassian/resources/atlassian.go | 9 + providers/atlassian/resources/atlassian.lr | 18 + providers/atlassian/resources/atlassian.lr.go | 382 ++++++++++++ .../resources/atlassian.lr.manifest.yaml | 22 + .../atlassian/resources/atlassian_admin.go | 15 + 13 files changed, 1376 insertions(+), 1 deletion(-) create mode 100644 providers/atlassian/config/config.go create mode 100644 providers/atlassian/connection/connection.go create mode 100644 providers/atlassian/gen/main.go create mode 100644 providers/atlassian/go.mod create mode 100644 providers/atlassian/go.sum create mode 100644 providers/atlassian/main.go create mode 100644 providers/atlassian/provider/provider.go create mode 100644 providers/atlassian/resources/atlassian.go create mode 100644 providers/atlassian/resources/atlassian.lr create mode 100644 providers/atlassian/resources/atlassian.lr.go create mode 100644 providers/atlassian/resources/atlassian.lr.manifest.yaml create mode 100644 providers/atlassian/resources/atlassian_admin.go diff --git a/Makefile b/Makefile index 9a41da76ba..1720d39241 100644 --- a/Makefile +++ b/Makefile @@ -186,7 +186,8 @@ providers/build: \ providers/build/k8s \ providers/build/azure \ providers/build/ms365 \ - providers/build/aws + providers/build/aws \ + providers/build/atlassian .PHONY: providers/install # Note we need \ to escape the target line into multiple lines @@ -313,6 +314,9 @@ providers/build/aws: providers/lr providers/install/aws: @$(call installProvider, providers/aws) +providers/build/atlassian: providers/lr + @$(call buildProvider, providers/atlassian) + providers/build/ms365: providers/lr @$(call buildProvider, providers/ms365) providers/install/ms365: @@ -339,6 +343,31 @@ providers/dist: @$(call buildProviderDist, providers/azure) @$(call buildProviderDist, providers/ms365) @$(call buildProviderDist, providers/aws) + @$(call buildProviderDist, providers/atlassian) + +providers/install: +# @$(call installProvider, providers/core) + @$(call installProvider, providers/network) + @$(call installProvider, providers/os) + @$(call installProvider, providers/ipmi) + @$(call installProvider, providers/oci) + @$(call installProvider, providers/slack) + @$(call installProvider, providers/github) + @$(call installProvider, providers/gitlab) + @$(call installProvider, providers/terraform) + @$(call installProvider, providers/vsphere) + @$(call installProvider, providers/opcua) + @$(call installProvider, providers/okta) + @$(call installProvider, providers/google-workspace) + @$(call installProvider, providers/arista) + @$(call installProvider, providers/equinix) + @$(call installProvider, providers/vcd) + @$(call installProvider, providers/gcp) + @$(call installProvider, providers/k8s) + @$(call installProvider, providers/azure) + @$(call installProvider, providers/ms365) + @$(call installProvider, providers/aws) + @$(call installProvider, providers/atlassian) providers/bundle: @$(call bundleProvider, providers/network) @@ -361,6 +390,7 @@ providers/bundle: @$(call bundleProvider, providers/azure) @$(call bundleProvider, providers/ms365) @$(call bundleProvider, providers/aws) + @$(call bundleProvider, providers/atlassian) providers/test: @$(call testProvider, providers/core) @@ -384,6 +414,7 @@ providers/test: @$(call testGpModProvider, providers/azure) @$(call testGpModProvider, providers/ms365) @$(call testGpModProvider, providers/aws) + @$(call testGpModProvider, providers/atlassian) lr/test: go test ./resources/lr/... diff --git a/providers/atlassian/config/config.go b/providers/atlassian/config/config.go new file mode 100644 index 0000000000..9ba9b420ab --- /dev/null +++ b/providers/atlassian/config/config.go @@ -0,0 +1,18 @@ +package config + +import "go.mondoo.com/cnquery/providers-sdk/v1/plugin" + +var Config = plugin.Provider{ + Name: "atlassian", + ID: "go.mondoo.com/cnquery/providers/atlassian", + Version: "9.0.0", + Connectors: []plugin.Connector{ + { + Name: "atlassian", + Use: "atlassian", + Short: "Atlassian", + Discovery: []string{}, + Flags: []plugin.Flag{}, + }, + }, +} diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go new file mode 100644 index 0000000000..c59bd0a427 --- /dev/null +++ b/providers/atlassian/connection/connection.go @@ -0,0 +1,37 @@ +package connection + +import ( + "go.mondoo.com/cnquery/providers-sdk/v1/inventory" +) + +type AtlassianConnection struct { + id uint32 + Conf *inventory.Config + asset *inventory.Asset + // Add custom connection fields here +} + +func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AtlassianConnection, error) { + conn := &AtlassianConnection{ + Conf: conf, + id: id, + asset: asset, + } + + // initialize your connection here + + return conn, nil +} + +func (c *AtlassianConnection) Name() string { + return "atlassian" +} + +func (c *AtlassianConnection) ID() uint32 { + return c.id +} + +func (c *AtlassianConnection) Asset() *inventory.Asset { + return c.asset +} + diff --git a/providers/atlassian/gen/main.go b/providers/atlassian/gen/main.go new file mode 100644 index 0000000000..f95f800717 --- /dev/null +++ b/providers/atlassian/gen/main.go @@ -0,0 +1,10 @@ +package main + +import ( + "go.mondoo.com/cnquery/providers-sdk/v1/plugin/gen" + "go.mondoo.com/cnquery/providers/atlassian/config" +) + +func main() { + gen.CLI(&config.Config) +} diff --git a/providers/atlassian/go.mod b/providers/atlassian/go.mod new file mode 100644 index 0000000000..dad25856ce --- /dev/null +++ b/providers/atlassian/go.mod @@ -0,0 +1,55 @@ +module go.mondoo.com/cnquery/providers/atlassian + +go 1.20 + +require go.mondoo.com/cnquery v0.0.0-20231002111758-82a0179e7dbd + +require ( + github.com/Masterminds/semver v1.5.0 // indirect + github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect + github.com/cockroachdb/errors v1.11.1 // indirect + github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect + github.com/cockroachdb/redact v1.1.5 // indirect + github.com/fatih/color v1.15.0 // indirect + github.com/getsentry/sentry-go v0.24.1 // indirect + github.com/gofrs/uuid v4.4.0+incompatible // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang-jwt/jwt v3.2.2+incompatible // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/google/uuid v1.3.1 // indirect + github.com/gopherjs/gopherjs v1.17.2 // indirect + github.com/hashicorp/go-hclog v1.5.0 // indirect + github.com/hashicorp/go-plugin v1.5.2 // indirect + github.com/hashicorp/yamux v0.1.1 // indirect + github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f // indirect + github.com/jtolds/gls v4.20.0+incompatible // indirect + github.com/kr/pretty v0.3.1 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/mitchellh/go-testing-interface v1.14.1 // indirect + github.com/muesli/termenv v0.15.2 // indirect + github.com/oklog/run v1.1.0 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/rivo/uniseg v0.4.4 // indirect + github.com/rogpeppe/go-internal v1.11.0 // indirect + github.com/rs/zerolog v1.31.0 // indirect + github.com/segmentio/fasthash v1.0.3 // indirect + github.com/segmentio/ksuid v1.0.4 // indirect + github.com/smarty/assertions v1.15.1 // indirect + github.com/spf13/afero v1.10.0 // indirect + go.mondoo.com/ranger-rpc v0.5.1 // indirect + golang.org/x/crypto v0.13.0 // indirect + golang.org/x/net v0.15.0 // indirect + golang.org/x/sys v0.12.0 // indirect + golang.org/x/text v0.13.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect + google.golang.org/grpc v1.58.2 // indirect + google.golang.org/protobuf v1.31.0 // indirect + gopkg.in/square/go-jose.v2 v2.6.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + moul.io/http2curl v1.0.0 // indirect + sigs.k8s.io/yaml v1.3.0 // indirect +) diff --git a/providers/atlassian/go.sum b/providers/atlassian/go.sum new file mode 100644 index 0000000000..89e7995df9 --- /dev/null +++ b/providers/atlassian/go.sum @@ -0,0 +1,575 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.44.3/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= +cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= +cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= +cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= +cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= +cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= +cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= +cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= +cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI= +cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk= +cloud.google.com/go v0.75.0/go.mod h1:VGuuCn7PG0dwsd5XPVm2Mm3wlh3EL55/79EKB6hlPTY= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= +cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= +cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= +cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= +cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= +cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= +cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= +cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= +cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= +cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= +cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= +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/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= +github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= +github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= +github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= +github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= +github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= +github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8= +github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4MIpiWMSNRfxw= +github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= +github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= +github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= +github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= +github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= +github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +github.com/getsentry/sentry-go v0.24.1 h1:W6/0GyTy8J6ge6lVCc94WB6Gx2ZuLrgopnn9w8Hiwuk= +github.com/getsentry/sentry-go v0.24.1/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= +github.com/go-errors/errors v1.5.0 h1:/EuijeGOu7ckFxzhkj4CXJ8JaenxK7bKUxpPYqeLHqQ= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= +github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= +github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= +github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +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/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/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= +github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= +github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g= +github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k= +github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c= +github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= +github.com/hashicorp/go-plugin v1.5.2 h1:aWv8eimFqWlsEiMrYZdPYl+FdHaBJSN4AWwGWfT1G2Y= +github.com/hashicorp/go-plugin v1.5.2/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= +github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= +github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f h1:7LYC+Yfkj3CTRcShK0KOL/w6iTiKyqqBA9a41Wnggw8= +github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f/go.mod h1:pFlLw2CfqZiIBOx6BuCeRLCrfxBJipTY0nIOF/VbGcI= +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/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= +github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= +github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= +github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo= +github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= +github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= +github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= +github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= +github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/segmentio/fasthash v1.0.3 h1:EI9+KE1EwvMLBWwjpRDc+fEM+prwxDYbslddQGtrmhM= +github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY= +github.com/segmentio/ksuid v1.0.4 h1:sBo2BdShXjmcugAMwjugoGUdUV0pcxY5mW4xKRn3v4c= +github.com/segmentio/ksuid v1.0.4/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O73XgrPE= +github.com/smarty/assertions v1.15.1 h1:812oFiXI+G55vxsFf+8bIZ1ux30qtkdqzKbEFwyX3Tk= +github.com/smarty/assertions v1.15.1/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec= +github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY= +github.com/spf13/afero v1.10.0 h1:EaGW2JJh15aKOejeuJ+wpFSHnbd7GE6Wvp3TsNhb6LY= +github.com/spf13/afero v1.10.0/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.mondoo.com/cnquery v0.0.0-20231002111758-82a0179e7dbd h1:61ziiW1w0vR+004KFqgzp5JG8QlsS5NMnU4FkH2bjOk= +go.mondoo.com/cnquery v0.0.0-20231002111758-82a0179e7dbd/go.mod h1:CyLGmRezek/8PswuVkmSLLScZqpMbACwFqL21eGeyYU= +go.mondoo.com/ranger-rpc v0.5.1 h1:OaVQntDJWDRgbc9nXBP4wOCR9h9Bij8LgHHs86IguGk= +go.mondoo.com/ranger-rpc v0.5.1/go.mod h1:3YKcqFrlPgaB4FZ4EoLgdmRtwMQdO7RoAkZYFn+F1eY= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= +go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs= +go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE= +go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= +golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= +golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= +golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= +golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= +golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= +golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= +golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= +golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= +golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= +google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= +google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= +google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= +google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg= +google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE= +google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= +google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= +google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 h1:N3bU/SQDCDyD6R528GJ/PwW9KjYcJA3dgyH+MovAkIM= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13/go.mod h1:KSqppvjFjtoCI+KGd4PELB0qLNxdJHRGqRI09mB6pQA= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= +google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= +google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= +google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= +google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI= +gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +moul.io/http2curl v1.0.0 h1:6XwpyZOYsgZJrU8exnG87ncVkU1FVCcTRpwzOkTDUi8= +moul.io/http2curl v1.0.0/go.mod h1:f6cULg+e4Md/oW1cYmwW4IWQOVl2lGbmCNGOHvzX2kE= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= +rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= +rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= +sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= +sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= diff --git a/providers/atlassian/main.go b/providers/atlassian/main.go new file mode 100644 index 0000000000..3dc0243f9e --- /dev/null +++ b/providers/atlassian/main.go @@ -0,0 +1,12 @@ +package main + +import ( + "os" + + "go.mondoo.com/cnquery/providers-sdk/v1/plugin" + "go.mondoo.com/cnquery/providers/atlassian/provider" +) + +func main() { + plugin.Start(os.Args, provider.Init()) +} diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go new file mode 100644 index 0000000000..dcce2f7ef2 --- /dev/null +++ b/providers/atlassian/provider/provider.go @@ -0,0 +1,191 @@ +package provider + +import ( + "errors" + "strconv" + + "go.mondoo.com/cnquery/llx" + "go.mondoo.com/cnquery/providers-sdk/v1/inventory" + "go.mondoo.com/cnquery/providers-sdk/v1/plugin" + "go.mondoo.com/cnquery/providers-sdk/v1/upstream" + "go.mondoo.com/cnquery/providers/atlassian/connection" + "go.mondoo.com/cnquery/providers/atlassian/resources" +) + +type Service struct { + runtimes map[uint32]*plugin.Runtime + lastConnectionID uint32 +} + +func Init() *Service { + return &Service{ + runtimes: map[uint32]*plugin.Runtime{}, + lastConnectionID: 0, + } +} + +func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) { + flags := req.Flags + if flags == nil { + flags = map[string]*llx.Primitive{} + } + + conf := &inventory.Config{ + Type: req.Connector, + Options: map[string]string{}, + } + + // Do custom flag parsing here + + asset := inventory.Asset{ + Connections: []*inventory.Config{conf}, + } + + return &plugin.ParseCLIRes{Asset: &asset}, nil +} + +func (s *Service) Connect(req *plugin.ConnectReq, callback plugin.ProviderCallback) (*plugin.ConnectRes, error) { + if req == nil || req.Asset == nil { + return nil, errors.New("no connection data provided") + } + + conn, err := s.connect(req, callback) + if err != nil { + return nil, err + } + + // We only need to run the detection step when we don't have any asset information yet. + if req.Asset.Platform == nil { + if err := s.detect(req.Asset, conn); err != nil { + return nil, err + } + } + + return &plugin.ConnectRes{ + Id: conn.ID(), + Name: conn.Name(), + Asset: req.Asset, + Inventory: nil, + }, nil +} + +// Shutdown is automatically called when the shell closes. +// It is not necessary to implement this method. +// If you want to do some cleanup, you can do it here. +func (s *Service) Shutdown(req *plugin.ShutdownReq) (*plugin.ShutdownRes, error) { + return &plugin.ShutdownRes{}, nil +} + +func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallback) (*connection.AtlassianConnection, error) { + if len(req.Asset.Connections) == 0 { + return nil, errors.New("no connection options for asset") + } + + asset := req.Asset + conf := asset.Connections[0] + var conn *connection.AtlassianConnection + var err error + + switch conf.Type { + default: + s.lastConnectionID++ + conn, err = connection.NewAtlassianConnection(s.lastConnectionID, asset, conf) + } + + if err != nil { + return nil, err + } + + var upstream *upstream.UpstreamClient + if req.Upstream != nil && !req.Upstream.Incognito { + upstream, err = req.Upstream.InitClient() + if err != nil { + return nil, err + } + } + + asset.Connections[0].Id = conn.ID() + s.runtimes[conn.ID()] = &plugin.Runtime{ + Connection: conn, + //Resources: map[string]plugin.Resource{}, + Callback: callback, + HasRecording: req.HasRecording, + CreateResource: resources.CreateResource, + Upstream: upstream, + } + + return conn, err +} + +func (s *Service) detect(asset *inventory.Asset, conn *connection.AtlassianConnection) error { + // TODO: adjust asset detection + asset.Id = conn.Conf.Type + asset.Name = conn.Conf.Host + + asset.Platform = &inventory.Platform{ + Name: "atlassian", + Family: []string{"atlassian"}, + Kind: "api", + Title: "Atlassian", + } + + // TODO: Add platform IDs + asset.PlatformIds = []string{"//platformid.api.mondoo.app/runtime/oci/"} + return nil +} + +func (s *Service) GetData(req *plugin.DataReq) (*plugin.DataRes, error) { + runtime, ok := s.runtimes[req.Connection] + if !ok { + return nil, errors.New("connection " + strconv.FormatUint(uint64(req.Connection), 10) + " not found") + } + + args := plugin.PrimitiveArgsToRawDataArgs(req.Args, runtime) + + if req.ResourceId == "" && req.Field == "" { + res, err := resources.NewResource(runtime, req.Resource, args) + if err != nil { + return nil, err + } + + rd := llx.ResourceData(res, res.MqlName()).Result() + return &plugin.DataRes{ + Data: rd.Data, + }, nil + } + + resource, ok := runtime.Resources.Get(req.Resource + "\x00" + req.ResourceId) + //resource, ok := runtime.Resources[req.Resource+"\x00"+req.ResourceId] + if !ok { + // Note: Since resources are internally always created, there are only very + // few cases where we arrive here: + // 1. The caller is wrong. Possibly a mixup with IDs + // 2. The resource was loaded from a recording, but the field is not + // in the recording. Thus the resource was never created inside the + // plugin. We will attempt to create the resource and see if the field + // can be computed. + if !runtime.HasRecording { + return nil, errors.New("resource '" + req.Resource + "' (id: " + req.ResourceId + ") doesn't exist") + } + + args, err := runtime.ResourceFromRecording(req.Resource, req.ResourceId) + if err != nil { + return nil, errors.New("attempted to load resource '" + req.Resource + "' (id: " + req.ResourceId + ") from recording failed: " + err.Error()) + } + + resource, err = resources.CreateResource(runtime, req.Resource, args) + if err != nil { + return nil, errors.New("attempted to create resource '" + req.Resource + "' (id: " + req.ResourceId + ") from recording failed: " + err.Error()) + } + } + + return resources.GetData(resource, req.Field, args), nil +} + +func (s *Service) StoreData(req *plugin.StoreReq) (*plugin.StoreRes, error) { + return nil, errors.New("not yet implemented") +} + +func (s *Service) MockConnect(req *plugin.ConnectReq, callback plugin.ProviderCallback) (*plugin.ConnectRes, error) { + return nil, errors.New("mock connect not yet implemented") +} diff --git a/providers/atlassian/resources/atlassian.go b/providers/atlassian/resources/atlassian.go new file mode 100644 index 0000000000..3192e6b5df --- /dev/null +++ b/providers/atlassian/resources/atlassian.go @@ -0,0 +1,9 @@ +package resources + +func (r *mqlAtlassian) id() (string, error) { + return "atlassian", nil +} + +func (r *mqlAtlassian) field() (string, error) { + return "example", nil +} diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr new file mode 100644 index 0000000000..9c37756850 --- /dev/null +++ b/providers/atlassian/resources/atlassian.lr @@ -0,0 +1,18 @@ +option provider = "go.mondoo.com/cnquery/providers/atlassian" +option go_package = "go.mondoo.com/cnquery/providers/atlassian/resources" + +// Atlassian +atlassian { + field() string +} + +atlassian.admin { + organizations() []atlassian.admin.organization +} + +atlassian.admin.organization { + users() []atlassian.admin.user +} + +atlassian.admin.user { +} diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go new file mode 100644 index 0000000000..92267080fe --- /dev/null +++ b/providers/atlassian/resources/atlassian.lr.go @@ -0,0 +1,382 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +// Code generated by resources. DO NOT EDIT. + +package resources + +import ( + "errors" + + "go.mondoo.com/cnquery/llx" + "go.mondoo.com/cnquery/providers-sdk/v1/plugin" + "go.mondoo.com/cnquery/types" +) + +var resourceFactories map[string]plugin.ResourceFactory + +func init() { + resourceFactories = map[string]plugin.ResourceFactory { + "atlassian": { + // to override args, implement: initAtlassian(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassian, + }, + "atlassian.admin": { + // to override args, implement: initAtlassianAdmin(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianAdmin, + }, + "atlassian.admin.organization": { + // to override args, implement: initAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianAdminOrganization, + }, + "atlassian.admin.user": { + // to override args, implement: initAtlassianAdminUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianAdminUser, + }, + } +} + +// NewResource is used by the runtime of this plugin to create new resources. +// Its arguments may be provided by users. This function is generally not +// used by initializing resources from recordings or from lists. +func NewResource(runtime *plugin.Runtime, name string, args map[string]*llx.RawData) (plugin.Resource, error) { + f, ok := resourceFactories[name] + if !ok { + return nil, errors.New("cannot find resource " + name + " in this provider") + } + + if f.Init != nil { + cargs, res, err := f.Init(runtime, args) + if err != nil { + return res, err + } + + if res != nil { + id := name+"\x00"+res.MqlID() + if x, ok := runtime.Resources.Get(id); ok { + return x, nil + } + runtime.Resources.Set(id, res) + return res, nil + } + + args = cargs + } + + res, err := f.Create(runtime, args) + if err != nil { + return nil, err + } + + id := name+"\x00"+res.MqlID() + if x, ok := runtime.Resources.Get(id); ok { + return x, nil + } + + runtime.Resources.Set(id, res) + return res, nil +} + +// CreateResource is used by the runtime of this plugin to create resources. +// Its arguments must be complete and pre-processed. This method is used +// for initializing resources from recordings or from lists. +func CreateResource(runtime *plugin.Runtime, name string, args map[string]*llx.RawData) (plugin.Resource, error) { + f, ok := resourceFactories[name] + if !ok { + return nil, errors.New("cannot find resource " + name + " in this provider") + } + + res, err := f.Create(runtime, args) + if err != nil { + return nil, err + } + + id := name+"\x00"+res.MqlID() + if x, ok := runtime.Resources.Get(id); ok { + return x, nil + } + + runtime.Resources.Set(id, res) + return res, nil +} + +var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ + "atlassian.field": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassian).GetField()).ToDataRes(types.String) + }, + "atlassian.admin.organizations": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdmin).GetOrganizations()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization"))) + }, + "atlassian.admin.organization.users": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganization).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.admin.user"))) + }, +} + +func GetData(resource plugin.Resource, field string, args map[string]*llx.RawData) *plugin.DataRes { + f, ok := getDataFields[resource.MqlName()+"."+field] + if !ok { + return &plugin.DataRes{Error: "cannot find '" + field + "' in resource '" + resource.MqlName() + "'"} + } + + return f(resource) +} + +var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { + "atlassian.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassian).__id, ok = v.Value.(string) + return + }, + "atlassian.field": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassian).Field, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdmin).__id, ok = v.Value.(string) + return + }, + "atlassian.admin.organizations": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdmin).Organizations, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, + "atlassian.admin.organization.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganization).__id, ok = v.Value.(string) + return + }, + "atlassian.admin.organization.users": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganization).Users, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, + "atlassian.admin.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminUser).__id, ok = v.Value.(string) + return + }, +} + +func SetData(resource plugin.Resource, field string, val *llx.RawData) error { + f, ok := setDataFields[resource.MqlName() + "." + field] + if !ok { + return errors.New("[atlassian] cannot set '"+field+"' in resource '"+resource.MqlName()+"', field not found") + } + + if ok := f(resource, val); !ok { + return errors.New("[atlassian] cannot set '"+field+"' in resource '"+resource.MqlName()+"', type does not match") + } + return nil +} + +func SetAllData(resource plugin.Resource, args map[string]*llx.RawData) error { + var err error + for k, v := range args { + if err = SetData(resource, k, v); err != nil { + return err + } + } + return nil +} + +// mqlAtlassian for the atlassian resource +type mqlAtlassian struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianInternal it will be used here + Field plugin.TValue[string] +} + +// createAtlassian creates a new instance of this resource +func createAtlassian(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassian{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassian) MqlName() string { + return "atlassian" +} + +func (c *mqlAtlassian) MqlID() string { + return c.__id +} + +func (c *mqlAtlassian) GetField() *plugin.TValue[string] { + return plugin.GetOrCompute[string](&c.Field, func() (string, error) { + return c.field() + }) +} + +// mqlAtlassianAdmin for the atlassian.admin resource +type mqlAtlassianAdmin struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianAdminInternal it will be used here + Organizations plugin.TValue[[]interface{}] +} + +// createAtlassianAdmin creates a new instance of this resource +func createAtlassianAdmin(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianAdmin{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.admin", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianAdmin) MqlName() string { + return "atlassian.admin" +} + +func (c *mqlAtlassianAdmin) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianAdmin) GetOrganizations() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Organizations, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin", c.__id, "organizations") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.organizations() + }) +} + +// mqlAtlassianAdminOrganization for the atlassian.admin.organization resource +type mqlAtlassianAdminOrganization struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianAdminOrganizationInternal it will be used here + Users plugin.TValue[[]interface{}] +} + +// createAtlassianAdminOrganization creates a new instance of this resource +func createAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianAdminOrganization{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + // to override __id implement: id() (string, error) + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.admin.organization", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianAdminOrganization) MqlName() string { + return "atlassian.admin.organization" +} + +func (c *mqlAtlassianAdminOrganization) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianAdminOrganization) GetUsers() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Users, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization", c.__id, "users") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.users() + }) +} + +// mqlAtlassianAdminUser for the atlassian.admin.user resource +type mqlAtlassianAdminUser struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianAdminUserInternal it will be used here +} + +// createAtlassianAdminUser creates a new instance of this resource +func createAtlassianAdminUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianAdminUser{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + // to override __id implement: id() (string, error) + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.admin.user", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianAdminUser) MqlName() string { + return "atlassian.admin.user" +} + +func (c *mqlAtlassianAdminUser) MqlID() string { + return c.__id +} diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml new file mode 100644 index 0000000000..3f6c7c8ea2 --- /dev/null +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -0,0 +1,22 @@ +# Copyright (c) Mondoo, Inc. +# SPDX-License-Identifier: BUSL-1.1 + +resources: + atlassian: + docs: + desc: | + The `atlassian` can be used to assess the configuration of atlassian accounts. + fields: + field: {} + min_mondoo_version: latest + atlassian.admin: + fields: + organizations: {} + min_mondoo_version: latest + atlassian.admin.organization: + fields: + users: {} + min_mondoo_version: latest + atlassian.admin.user: + fields: {} + min_mondoo_version: latest diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go new file mode 100644 index 0000000000..5602175bf1 --- /dev/null +++ b/providers/atlassian/resources/atlassian_admin.go @@ -0,0 +1,15 @@ +package resources + +func (a *mqlAtlassianAdmin) id() (string, error) { + return "wip", nil +} + +func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { + res := []interface{}{} + return res, nil +} + +func (a *mqlAtlassianAdminOrganization) users() ([]interface{}, error) { + res := []interface{}{} + return res, nil +} From f98be0d937f893c2f71db15a9f5831e58832464d Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Tue, 3 Oct 2023 14:04:31 +0200 Subject: [PATCH 02/90] wip --- providers/atlassian/connection/connection.go | 23 +++++++++++++---- providers/atlassian/go.mod | 9 ++++++- providers/atlassian/go.sum | 25 +++++++++++++++++++ .../atlassian/resources/atlassian_admin.go | 19 ++++++++++++++ 4 files changed, 70 insertions(+), 6 deletions(-) diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index c59bd0a427..957ccf79f3 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -1,25 +1,35 @@ package connection import ( + "github.com/ctreminiom/go-atlassian/admin" + "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/providers-sdk/v1/inventory" ) type AtlassianConnection struct { - id uint32 - Conf *inventory.Config - asset *inventory.Asset + id uint32 + Conf *inventory.Config + asset *inventory.Asset + admin *admin.Client // Add custom connection fields here } func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AtlassianConnection, error) { + apiKey := "ThisIsNotAnAPIKey" + admin, err := admin.New(nil) + if err != nil { + log.Fatal().Err(err) + } + admin.Auth.SetBearerToken(apiKey) + admin.Auth.SetUserAgent("curl/7.54.0") + conn := &AtlassianConnection{ Conf: conf, id: id, asset: asset, + admin: admin, } - // initialize your connection here - return conn, nil } @@ -35,3 +45,6 @@ func (c *AtlassianConnection) Asset() *inventory.Asset { return c.asset } +func (c *AtlassianConnection) Admin() *admin.Client { + return c.admin +} diff --git a/providers/atlassian/go.mod b/providers/atlassian/go.mod index dad25856ce..805bf0f642 100644 --- a/providers/atlassian/go.mod +++ b/providers/atlassian/go.mod @@ -2,7 +2,10 @@ module go.mondoo.com/cnquery/providers/atlassian go 1.20 -require go.mondoo.com/cnquery v0.0.0-20231002111758-82a0179e7dbd +require ( + github.com/ctreminiom/go-atlassian v1.5.1 + go.mondoo.com/cnquery v0.0.0-20231002111758-82a0179e7dbd +) require ( github.com/Masterminds/semver v1.5.0 // indirect @@ -22,16 +25,20 @@ require ( github.com/hashicorp/go-plugin v1.5.2 // indirect github.com/hashicorp/yamux v0.1.1 // indirect github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f // indirect + github.com/imdario/mergo v0.3.16 // indirect + github.com/josharian/intern v1.0.0 // indirect github.com/jtolds/gls v4.20.0+incompatible // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/muesli/termenv v0.15.2 // indirect github.com/oklog/run v1.1.0 // indirect + github.com/perimeterx/marshmallow v1.1.5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect diff --git a/providers/atlassian/go.sum b/providers/atlassian/go.sum index 89e7995df9..8887a24f83 100644 --- a/providers/atlassian/go.sum +++ b/providers/atlassian/go.sum @@ -59,6 +59,8 @@ github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwP github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/ctreminiom/go-atlassian v1.5.1 h1:GYji33ywQyWvePNQzxfvgb02fg6fcSH1g59vDy3ApEw= +github.com/ctreminiom/go-atlassian v1.5.1/go.mod h1:R1EaOjo33pSN9Y6xIJCEgQ68wgwYoFYAXifnaPlmyc8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -79,6 +81,8 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2 github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= +github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= @@ -161,7 +165,11 @@ github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f h1:7LYC+Yfk github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f/go.mod h1:pFlLw2CfqZiIBOx6BuCeRLCrfxBJipTY0nIOF/VbGcI= 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.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= +github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= @@ -178,6 +186,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -195,6 +205,8 @@ github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= +github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s= +github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -223,11 +235,24 @@ github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sS github.com/spf13/afero v1.10.0 h1:EaGW2JJh15aKOejeuJ+wpFSHnbd7GE6Wvp3TsNhb6LY= github.com/spf13/afero v1.10.0/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.1 h1:4VhoImhV/Bm0ToFkXFi8hXNXwpDRZ/ynw3amt82mzq0= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/tidwall/gjson v1.16.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo= +github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= +github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= +github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index 5602175bf1..a9b53d2304 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -1,15 +1,34 @@ package resources +import ( + "context" + + "github.com/rs/zerolog/log" + "go.mondoo.com/cnquery/providers/atlassian/connection" +) + func (a *mqlAtlassianAdmin) id() (string, error) { return "wip", nil } func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + admin := conn.Admin() + organizations, _, err := admin.Organization.Gets(context.Background(), "") + if err != nil { + log.Fatal().Err(err) + } res := []interface{}{} + for _, org := range organizations.Data { + res = append(res, org) + } return res, nil } func (a *mqlAtlassianAdminOrganization) users() ([]interface{}, error) { + //conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + //admin := conn.Admin() + res := []interface{}{} return res, nil } From 6869222f3636f184eadcb96611cf8fe09c5af976 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Tue, 3 Oct 2023 14:06:40 +0200 Subject: [PATCH 03/90] fix spelling --- .github/actions/spelling/expect.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index ac5b5ce3d4..7996cd1141 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -1,4 +1,5 @@ aks +atlassian Auths autoaccept autoscaler From 137fd6abf30fd075b7343ddd387743ee40cd943e Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Tue, 3 Oct 2023 14:34:42 +0200 Subject: [PATCH 04/90] wip --- providers/atlassian/resources/atlassian.lr | 7 +++++- providers/atlassian/resources/atlassian.lr.go | 24 +++++++++++++++++++ .../resources/atlassian.lr.manifest.yaml | 2 ++ .../atlassian/resources/atlassian_admin.go | 10 +++++++- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 9c37756850..e5d3bdcb1c 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -10,7 +10,12 @@ atlassian.admin { organizations() []atlassian.admin.organization } -atlassian.admin.organization { +atlassian.admin.organization @defaults("id") { + // Organization ID + id string + // Organization type + type string + // Organization users users() []atlassian.admin.user } diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 92267080fe..535afbde77 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -107,6 +107,12 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organizations": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdmin).GetOrganizations()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization"))) }, + "atlassian.admin.organization.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganization).GetId()).ToDataRes(types.String) + }, + "atlassian.admin.organization.type": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganization).GetType()).ToDataRes(types.String) + }, "atlassian.admin.organization.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganization).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.admin.user"))) }, @@ -142,6 +148,14 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganization).__id, ok = v.Value.(string) return }, + "atlassian.admin.organization.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganization).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.organization.type": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganization).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.admin.organization.users": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganization).Users, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return @@ -291,6 +305,8 @@ type mqlAtlassianAdminOrganization struct { MqlRuntime *plugin.Runtime __id string // optional: if you define mqlAtlassianAdminOrganizationInternal it will be used here + Id plugin.TValue[string] + Type plugin.TValue[string] Users plugin.TValue[[]interface{}] } @@ -326,6 +342,14 @@ func (c *mqlAtlassianAdminOrganization) MqlID() string { return c.__id } +func (c *mqlAtlassianAdminOrganization) GetId() *plugin.TValue[string] { + return &c.Id +} + +func (c *mqlAtlassianAdminOrganization) GetType() *plugin.TValue[string] { + return &c.Type +} + func (c *mqlAtlassianAdminOrganization) GetUsers() *plugin.TValue[[]interface{}] { return plugin.GetOrCompute[[]interface{}](&c.Users, func() ([]interface{}, error) { if c.MqlRuntime.HasRecording { diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 3f6c7c8ea2..b442c31db7 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -15,6 +15,8 @@ resources: min_mondoo_version: latest atlassian.admin.organization: fields: + id: {} + type: {} users: {} min_mondoo_version: latest atlassian.admin.user: diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index a9b53d2304..dba3259a54 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -4,6 +4,7 @@ import ( "context" "github.com/rs/zerolog/log" + "go.mondoo.com/cnquery/llx" "go.mondoo.com/cnquery/providers/atlassian/connection" ) @@ -20,7 +21,14 @@ func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { } res := []interface{}{} for _, org := range organizations.Data { - res = append(res, org) + mqlAtlassianAdminOrg, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization", + map[string]*llx.RawData{ + "id": llx.StringData(org.ID), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianAdminOrg) } return res, nil } From 7627896e49db927aecae00bec53c92d13c74fb1f Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 4 Oct 2023 08:52:47 +0200 Subject: [PATCH 05/90] wip --- providers/atlassian/connection/connection.go | 4 +- providers/atlassian/resources/atlassian.lr | 22 ++- providers/atlassian/resources/atlassian.lr.go | 169 ++++++++++++++++-- .../resources/atlassian.lr.manifest.yaml | 15 +- 4 files changed, 192 insertions(+), 18 deletions(-) diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index 957ccf79f3..ca6e470cfd 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -1,6 +1,8 @@ package connection import ( + "os" + "github.com/ctreminiom/go-atlassian/admin" "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/providers-sdk/v1/inventory" @@ -15,7 +17,7 @@ type AtlassianConnection struct { } func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AtlassianConnection, error) { - apiKey := "ThisIsNotAnAPIKey" + apiKey := os.Getenv("ATLASSIAN_KEY") admin, err := admin.New(nil) if err != nil { log.Fatal().Err(err) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index e5d3bdcb1c..a62d67738f 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -3,7 +3,6 @@ option go_package = "go.mondoo.com/cnquery/providers/atlassian/resources" // Atlassian atlassian { - field() string } atlassian.admin { @@ -20,4 +19,25 @@ atlassian.admin.organization @defaults("id") { } atlassian.admin.user { + // Account ID + id string + // Account type + type string + // Account status + status string + // Name of the user + name string + // Picture of the user + picture string + // Email of the user + email string + // Billable + accessBillable bool + // Time when the user was last active + lastActive string + // ProductAccess + productAccess []atlassian.admin.user.products +} + +atlassian.admin.user.products { } diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 535afbde77..5e3474563a 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -33,6 +33,10 @@ func init() { // to override args, implement: initAtlassianAdminUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminUser, }, + "atlassian.admin.user.products": { + // to override args, implement: initAtlassianAdminUserProducts(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianAdminUserProducts, + }, } } @@ -101,9 +105,6 @@ func CreateResource(runtime *plugin.Runtime, name string, args map[string]*llx.R } var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ - "atlassian.field": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassian).GetField()).ToDataRes(types.String) - }, "atlassian.admin.organizations": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdmin).GetOrganizations()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization"))) }, @@ -116,6 +117,33 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganization).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.admin.user"))) }, + "atlassian.admin.user.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminUser).GetId()).ToDataRes(types.String) + }, + "atlassian.admin.user.type": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminUser).GetType()).ToDataRes(types.String) + }, + "atlassian.admin.user.status": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminUser).GetStatus()).ToDataRes(types.String) + }, + "atlassian.admin.user.name": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminUser).GetName()).ToDataRes(types.String) + }, + "atlassian.admin.user.picture": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminUser).GetPicture()).ToDataRes(types.String) + }, + "atlassian.admin.user.email": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminUser).GetEmail()).ToDataRes(types.String) + }, + "atlassian.admin.user.accessBillable": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminUser).GetAccessBillable()).ToDataRes(types.Bool) + }, + "atlassian.admin.user.lastActive": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminUser).GetLastActive()).ToDataRes(types.String) + }, + "atlassian.admin.user.productAccess": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminUser).GetProductAccess()).ToDataRes(types.Array(types.Resource("atlassian.admin.user.products"))) + }, } func GetData(resource plugin.Resource, field string, args map[string]*llx.RawData) *plugin.DataRes { @@ -132,10 +160,6 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassian).__id, ok = v.Value.(string) return }, - "atlassian.field": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassian).Field, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, "atlassian.admin.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdmin).__id, ok = v.Value.(string) return @@ -164,6 +188,46 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminUser).__id, ok = v.Value.(string) return }, + "atlassian.admin.user.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminUser).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.user.type": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminUser).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.user.status": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminUser).Status, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.user.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminUser).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.user.picture": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminUser).Picture, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.user.email": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminUser).Email, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.user.accessBillable": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminUser).AccessBillable, ok = plugin.RawToTValue[bool](v.Value, v.Error) + return + }, + "atlassian.admin.user.lastActive": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminUser).LastActive, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.user.productAccess": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminUser).ProductAccess, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, + "atlassian.admin.user.products.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminUserProducts).__id, ok = v.Value.(string) + return + }, } func SetData(resource plugin.Resource, field string, val *llx.RawData) error { @@ -193,7 +257,6 @@ type mqlAtlassian struct { MqlRuntime *plugin.Runtime __id string // optional: if you define mqlAtlassianInternal it will be used here - Field plugin.TValue[string] } // createAtlassian creates a new instance of this resource @@ -233,12 +296,6 @@ func (c *mqlAtlassian) MqlID() string { return c.__id } -func (c *mqlAtlassian) GetField() *plugin.TValue[string] { - return plugin.GetOrCompute[string](&c.Field, func() (string, error) { - return c.field() - }) -} - // mqlAtlassianAdmin for the atlassian.admin resource type mqlAtlassianAdmin struct { MqlRuntime *plugin.Runtime @@ -371,6 +428,15 @@ type mqlAtlassianAdminUser struct { MqlRuntime *plugin.Runtime __id string // optional: if you define mqlAtlassianAdminUserInternal it will be used here + Id plugin.TValue[string] + Type plugin.TValue[string] + Status plugin.TValue[string] + Name plugin.TValue[string] + Picture plugin.TValue[string] + Email plugin.TValue[string] + AccessBillable plugin.TValue[bool] + LastActive plugin.TValue[string] + ProductAccess plugin.TValue[[]interface{}] } // createAtlassianAdminUser creates a new instance of this resource @@ -404,3 +470,78 @@ func (c *mqlAtlassianAdminUser) MqlName() string { func (c *mqlAtlassianAdminUser) MqlID() string { return c.__id } + +func (c *mqlAtlassianAdminUser) GetId() *plugin.TValue[string] { + return &c.Id +} + +func (c *mqlAtlassianAdminUser) GetType() *plugin.TValue[string] { + return &c.Type +} + +func (c *mqlAtlassianAdminUser) GetStatus() *plugin.TValue[string] { + return &c.Status +} + +func (c *mqlAtlassianAdminUser) GetName() *plugin.TValue[string] { + return &c.Name +} + +func (c *mqlAtlassianAdminUser) GetPicture() *plugin.TValue[string] { + return &c.Picture +} + +func (c *mqlAtlassianAdminUser) GetEmail() *plugin.TValue[string] { + return &c.Email +} + +func (c *mqlAtlassianAdminUser) GetAccessBillable() *plugin.TValue[bool] { + return &c.AccessBillable +} + +func (c *mqlAtlassianAdminUser) GetLastActive() *plugin.TValue[string] { + return &c.LastActive +} + +func (c *mqlAtlassianAdminUser) GetProductAccess() *plugin.TValue[[]interface{}] { + return &c.ProductAccess +} + +// mqlAtlassianAdminUserProducts for the atlassian.admin.user.products resource +type mqlAtlassianAdminUserProducts struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianAdminUserProductsInternal it will be used here +} + +// createAtlassianAdminUserProducts creates a new instance of this resource +func createAtlassianAdminUserProducts(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianAdminUserProducts{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + // to override __id implement: id() (string, error) + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.admin.user.products", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianAdminUserProducts) MqlName() string { + return "atlassian.admin.user.products" +} + +func (c *mqlAtlassianAdminUserProducts) MqlID() string { + return c.__id +} diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index b442c31db7..d349322209 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -6,8 +6,7 @@ resources: docs: desc: | The `atlassian` can be used to assess the configuration of atlassian accounts. - fields: - field: {} + fields: {} min_mondoo_version: latest atlassian.admin: fields: @@ -20,5 +19,17 @@ resources: users: {} min_mondoo_version: latest atlassian.admin.user: + fields: + accessBillable: {} + email: {} + id: {} + lastActive: {} + name: {} + picture: {} + productAccess: {} + status: {} + type: {} + min_mondoo_version: latest + atlassian.admin.user.products: fields: {} min_mondoo_version: latest From 9cce482c71595edf1dded85db7c33b3b10211cef Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 4 Oct 2023 10:25:09 +0200 Subject: [PATCH 06/90] connection and receiving organizations works --- providers/atlassian/resources/atlassian_admin.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index dba3259a54..f07f1d7ce2 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -15,10 +15,13 @@ func (a *mqlAtlassianAdmin) id() (string, error) { func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) admin := conn.Admin() - organizations, _, err := admin.Organization.Gets(context.Background(), "") + organizations, response, err := admin.Organization.Gets(context.Background(), "") if err != nil { log.Fatal().Err(err) } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response) + } res := []interface{}{} for _, org := range organizations.Data { mqlAtlassianAdminOrg, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization", @@ -37,6 +40,10 @@ func (a *mqlAtlassianAdminOrganization) users() ([]interface{}, error) { //conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) //admin := conn.Admin() + //permissions, response, err := admin.User + + //fmt.Println("Response HTTP Code", response.StatusCode) + res := []interface{}{} return res, nil } From 8cda130f36e5ed8cf4d4c570d70db2a42575f172 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 4 Oct 2023 14:19:00 +0200 Subject: [PATCH 07/90] adding basic jira and confluence --- providers/atlassian/connection/connection.go | 15 + providers/atlassian/go.mod | 5 +- providers/atlassian/go.sum | 3 + providers/atlassian/resources/atlassian.lr | 25 +- providers/atlassian/resources/atlassian.lr.go | 367 ++++++++++++++---- .../resources/atlassian.lr.manifest.yaml | 27 ++ .../atlassian/resources/atlassian_admin.go | 40 +- .../resources/atlassian_confluence.go | 10 + .../atlassian/resources/atlassian_jira.go | 10 + 9 files changed, 409 insertions(+), 93 deletions(-) create mode 100644 providers/atlassian/resources/atlassian_confluence.go create mode 100644 providers/atlassian/resources/atlassian_jira.go diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index ca6e470cfd..0ea6b05b47 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -4,6 +4,8 @@ import ( "os" "github.com/ctreminiom/go-atlassian/admin" + "github.com/ctreminiom/go-atlassian/jira/v2" + _ "github.com/ctreminiom/go-atlassian/jira/v3" "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/providers-sdk/v1/inventory" ) @@ -13,11 +15,13 @@ type AtlassianConnection struct { Conf *inventory.Config asset *inventory.Asset admin *admin.Client + jira *v2.Client // Add custom connection fields here } func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AtlassianConnection, error) { apiKey := os.Getenv("ATLASSIAN_KEY") + token := os.Getenv("ATLASSIAN_TOKEN") admin, err := admin.New(nil) if err != nil { log.Fatal().Err(err) @@ -25,6 +29,13 @@ func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.C admin.Auth.SetBearerToken(apiKey) admin.Auth.SetUserAgent("curl/7.54.0") + jira, err := v2.New(nil, "lunalectric.atlassian.net") + if err != nil { + log.Fatal().Err(err) + } + + jira.Auth.SetBasicAuth("marius@mondoo.com", token) + conn := &AtlassianConnection{ Conf: conf, id: id, @@ -50,3 +61,7 @@ func (c *AtlassianConnection) Asset() *inventory.Asset { func (c *AtlassianConnection) Admin() *admin.Client { return c.admin } + +func (c *AtlassianConnection) Jira() *v2.Client { + return c.jira +} diff --git a/providers/atlassian/go.mod b/providers/atlassian/go.mod index 805bf0f642..cdd40c0166 100644 --- a/providers/atlassian/go.mod +++ b/providers/atlassian/go.mod @@ -4,6 +4,7 @@ go 1.20 require ( github.com/ctreminiom/go-atlassian v1.5.1 + github.com/rs/zerolog v1.31.0 go.mondoo.com/cnquery v0.0.0-20231002111758-82a0179e7dbd ) @@ -42,11 +43,13 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect - github.com/rs/zerolog v1.31.0 // indirect github.com/segmentio/fasthash v1.0.3 // indirect github.com/segmentio/ksuid v1.0.4 // indirect github.com/smarty/assertions v1.15.1 // indirect github.com/spf13/afero v1.10.0 // indirect + github.com/tidwall/gjson v1.16.0 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.0 // indirect go.mondoo.com/ranger-rpc v0.5.1 // indirect golang.org/x/crypto v0.13.0 // indirect golang.org/x/net v0.15.0 // indirect diff --git a/providers/atlassian/go.sum b/providers/atlassian/go.sum index 8887a24f83..195e684393 100644 --- a/providers/atlassian/go.sum +++ b/providers/atlassian/go.sum @@ -246,8 +246,11 @@ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1F github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/tidwall/gjson v1.16.0 h1:SyXa+dsSPpUlcwEDuKuEBJEz5vzTvOea+9rjyYodQFg= github.com/tidwall/gjson v1.16.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo= github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index a62d67738f..111bc6366f 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -15,10 +15,10 @@ atlassian.admin.organization @defaults("id") { // Organization type type string // Organization users - users() []atlassian.admin.user + users() []atlassian.admin.organization.user } -atlassian.admin.user { +atlassian.admin.organization.user { // Account ID id string // Account type @@ -35,9 +35,24 @@ atlassian.admin.user { accessBillable bool // Time when the user was last active lastActive string - // ProductAccess - productAccess []atlassian.admin.user.products } -atlassian.admin.user.products { +atlassian.jira { + // Jira users + users() []atlassian.jira.user +} + +atlassian.jira.user { + // AccountID + id string +} + +atlassian.confluence { + // Confluence users + users() []atlassian.confluence.user +} + +atlassian.confluence.user { + // AccountID + id string } diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 5e3474563a..7f3f48eaf7 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -29,13 +29,25 @@ func init() { // to override args, implement: initAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganization, }, - "atlassian.admin.user": { - // to override args, implement: initAtlassianAdminUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) - Create: createAtlassianAdminUser, + "atlassian.admin.organization.user": { + // to override args, implement: initAtlassianAdminOrganizationUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianAdminOrganizationUser, }, - "atlassian.admin.user.products": { - // to override args, implement: initAtlassianAdminUserProducts(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) - Create: createAtlassianAdminUserProducts, + "atlassian.jira": { + // to override args, implement: initAtlassianJira(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianJira, + }, + "atlassian.jira.user": { + // to override args, implement: initAtlassianJiraUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianJiraUser, + }, + "atlassian.confluence": { + // to override args, implement: initAtlassianConfluence(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianConfluence, + }, + "atlassian.confluence.user": { + // to override args, implement: initAtlassianConfluenceUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianConfluenceUser, }, } } @@ -115,34 +127,43 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ return (r.(*mqlAtlassianAdminOrganization).GetType()).ToDataRes(types.String) }, "atlassian.admin.organization.users": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganization).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.admin.user"))) + return (r.(*mqlAtlassianAdminOrganization).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.user"))) + }, + "atlassian.admin.organization.user.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationUser).GetId()).ToDataRes(types.String) + }, + "atlassian.admin.organization.user.type": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationUser).GetType()).ToDataRes(types.String) }, - "atlassian.admin.user.id": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminUser).GetId()).ToDataRes(types.String) + "atlassian.admin.organization.user.status": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationUser).GetStatus()).ToDataRes(types.String) }, - "atlassian.admin.user.type": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminUser).GetType()).ToDataRes(types.String) + "atlassian.admin.organization.user.name": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationUser).GetName()).ToDataRes(types.String) }, - "atlassian.admin.user.status": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminUser).GetStatus()).ToDataRes(types.String) + "atlassian.admin.organization.user.picture": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationUser).GetPicture()).ToDataRes(types.String) }, - "atlassian.admin.user.name": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminUser).GetName()).ToDataRes(types.String) + "atlassian.admin.organization.user.email": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationUser).GetEmail()).ToDataRes(types.String) }, - "atlassian.admin.user.picture": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminUser).GetPicture()).ToDataRes(types.String) + "atlassian.admin.organization.user.accessBillable": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationUser).GetAccessBillable()).ToDataRes(types.Bool) }, - "atlassian.admin.user.email": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminUser).GetEmail()).ToDataRes(types.String) + "atlassian.admin.organization.user.lastActive": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationUser).GetLastActive()).ToDataRes(types.String) }, - "atlassian.admin.user.accessBillable": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminUser).GetAccessBillable()).ToDataRes(types.Bool) + "atlassian.jira.users": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJira).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.jira.user"))) }, - "atlassian.admin.user.lastActive": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminUser).GetLastActive()).ToDataRes(types.String) + "atlassian.jira.user.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraUser).GetId()).ToDataRes(types.String) }, - "atlassian.admin.user.productAccess": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminUser).GetProductAccess()).ToDataRes(types.Array(types.Resource("atlassian.admin.user.products"))) + "atlassian.confluence.users": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianConfluence).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.confluence.user"))) + }, + "atlassian.confluence.user.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianConfluenceUser).GetId()).ToDataRes(types.String) }, } @@ -184,50 +205,74 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganization).Users, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, - "atlassian.admin.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminUser).__id, ok = v.Value.(string) + "atlassian.admin.organization.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationUser).__id, ok = v.Value.(string) return }, - "atlassian.admin.user.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminUser).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + "atlassian.admin.organization.user.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationUser).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, - "atlassian.admin.user.type": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminUser).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) + "atlassian.admin.organization.user.type": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationUser).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, - "atlassian.admin.user.status": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminUser).Status, ok = plugin.RawToTValue[string](v.Value, v.Error) + "atlassian.admin.organization.user.status": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationUser).Status, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, - "atlassian.admin.user.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminUser).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) + "atlassian.admin.organization.user.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationUser).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, - "atlassian.admin.user.picture": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminUser).Picture, ok = plugin.RawToTValue[string](v.Value, v.Error) + "atlassian.admin.organization.user.picture": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationUser).Picture, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, - "atlassian.admin.user.email": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminUser).Email, ok = plugin.RawToTValue[string](v.Value, v.Error) + "atlassian.admin.organization.user.email": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationUser).Email, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, - "atlassian.admin.user.accessBillable": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminUser).AccessBillable, ok = plugin.RawToTValue[bool](v.Value, v.Error) + "atlassian.admin.organization.user.accessBillable": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationUser).AccessBillable, ok = plugin.RawToTValue[bool](v.Value, v.Error) return }, - "atlassian.admin.user.lastActive": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminUser).LastActive, ok = plugin.RawToTValue[string](v.Value, v.Error) + "atlassian.admin.organization.user.lastActive": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationUser).LastActive, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, - "atlassian.admin.user.productAccess": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminUser).ProductAccess, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + "atlassian.jira.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJira).__id, ok = v.Value.(string) + return + }, + "atlassian.jira.users": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJira).Users, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, - "atlassian.admin.user.products.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminUserProducts).__id, ok = v.Value.(string) + "atlassian.jira.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraUser).__id, ok = v.Value.(string) return }, + "atlassian.jira.user.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraUser).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.confluence.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianConfluence).__id, ok = v.Value.(string) + return + }, + "atlassian.confluence.users": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianConfluence).Users, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, + "atlassian.confluence.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianConfluenceUser).__id, ok = v.Value.(string) + return + }, + "atlassian.confluence.user.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianConfluenceUser).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, } func SetData(resource plugin.Resource, field string, val *llx.RawData) error { @@ -423,11 +468,11 @@ func (c *mqlAtlassianAdminOrganization) GetUsers() *plugin.TValue[[]interface{}] }) } -// mqlAtlassianAdminUser for the atlassian.admin.user resource -type mqlAtlassianAdminUser struct { +// mqlAtlassianAdminOrganizationUser for the atlassian.admin.organization.user resource +type mqlAtlassianAdminOrganizationUser struct { MqlRuntime *plugin.Runtime __id string - // optional: if you define mqlAtlassianAdminUserInternal it will be used here + // optional: if you define mqlAtlassianAdminOrganizationUserInternal it will be used here Id plugin.TValue[string] Type plugin.TValue[string] Status plugin.TValue[string] @@ -436,12 +481,11 @@ type mqlAtlassianAdminUser struct { Email plugin.TValue[string] AccessBillable plugin.TValue[bool] LastActive plugin.TValue[string] - ProductAccess plugin.TValue[[]interface{}] } -// createAtlassianAdminUser creates a new instance of this resource -func createAtlassianAdminUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { - res := &mqlAtlassianAdminUser{ +// createAtlassianAdminOrganizationUser creates a new instance of this resource +func createAtlassianAdminOrganizationUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianAdminOrganizationUser{ MqlRuntime: runtime, } @@ -453,7 +497,7 @@ func createAtlassianAdminUser(runtime *plugin.Runtime, args map[string]*llx.RawD // to override __id implement: id() (string, error) if runtime.HasRecording { - args, err = runtime.ResourceFromRecording("atlassian.admin.user", res.__id) + args, err = runtime.ResourceFromRecording("atlassian.admin.organization.user", res.__id) if err != nil || args == nil { return res, err } @@ -463,60 +507,118 @@ func createAtlassianAdminUser(runtime *plugin.Runtime, args map[string]*llx.RawD return res, nil } -func (c *mqlAtlassianAdminUser) MqlName() string { - return "atlassian.admin.user" +func (c *mqlAtlassianAdminOrganizationUser) MqlName() string { + return "atlassian.admin.organization.user" } -func (c *mqlAtlassianAdminUser) MqlID() string { +func (c *mqlAtlassianAdminOrganizationUser) MqlID() string { return c.__id } -func (c *mqlAtlassianAdminUser) GetId() *plugin.TValue[string] { +func (c *mqlAtlassianAdminOrganizationUser) GetId() *plugin.TValue[string] { return &c.Id } -func (c *mqlAtlassianAdminUser) GetType() *plugin.TValue[string] { +func (c *mqlAtlassianAdminOrganizationUser) GetType() *plugin.TValue[string] { return &c.Type } -func (c *mqlAtlassianAdminUser) GetStatus() *plugin.TValue[string] { +func (c *mqlAtlassianAdminOrganizationUser) GetStatus() *plugin.TValue[string] { return &c.Status } -func (c *mqlAtlassianAdminUser) GetName() *plugin.TValue[string] { +func (c *mqlAtlassianAdminOrganizationUser) GetName() *plugin.TValue[string] { return &c.Name } -func (c *mqlAtlassianAdminUser) GetPicture() *plugin.TValue[string] { +func (c *mqlAtlassianAdminOrganizationUser) GetPicture() *plugin.TValue[string] { return &c.Picture } -func (c *mqlAtlassianAdminUser) GetEmail() *plugin.TValue[string] { +func (c *mqlAtlassianAdminOrganizationUser) GetEmail() *plugin.TValue[string] { return &c.Email } -func (c *mqlAtlassianAdminUser) GetAccessBillable() *plugin.TValue[bool] { +func (c *mqlAtlassianAdminOrganizationUser) GetAccessBillable() *plugin.TValue[bool] { return &c.AccessBillable } -func (c *mqlAtlassianAdminUser) GetLastActive() *plugin.TValue[string] { +func (c *mqlAtlassianAdminOrganizationUser) GetLastActive() *plugin.TValue[string] { return &c.LastActive } -func (c *mqlAtlassianAdminUser) GetProductAccess() *plugin.TValue[[]interface{}] { - return &c.ProductAccess +// mqlAtlassianJira for the atlassian.jira resource +type mqlAtlassianJira struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianJiraInternal it will be used here + Users plugin.TValue[[]interface{}] +} + +// createAtlassianJira creates a new instance of this resource +func createAtlassianJira(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianJira{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.jira", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianJira) MqlName() string { + return "atlassian.jira" +} + +func (c *mqlAtlassianJira) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianJira) GetUsers() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Users, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.jira", c.__id, "users") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.users() + }) } -// mqlAtlassianAdminUserProducts for the atlassian.admin.user.products resource -type mqlAtlassianAdminUserProducts struct { +// mqlAtlassianJiraUser for the atlassian.jira.user resource +type mqlAtlassianJiraUser struct { MqlRuntime *plugin.Runtime __id string - // optional: if you define mqlAtlassianAdminUserProductsInternal it will be used here + // optional: if you define mqlAtlassianJiraUserInternal it will be used here + Id plugin.TValue[string] } -// createAtlassianAdminUserProducts creates a new instance of this resource -func createAtlassianAdminUserProducts(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { - res := &mqlAtlassianAdminUserProducts{ +// createAtlassianJiraUser creates a new instance of this resource +func createAtlassianJiraUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianJiraUser{ MqlRuntime: runtime, } @@ -528,7 +630,7 @@ func createAtlassianAdminUserProducts(runtime *plugin.Runtime, args map[string]* // to override __id implement: id() (string, error) if runtime.HasRecording { - args, err = runtime.ResourceFromRecording("atlassian.admin.user.products", res.__id) + args, err = runtime.ResourceFromRecording("atlassian.jira.user", res.__id) if err != nil || args == nil { return res, err } @@ -538,10 +640,119 @@ func createAtlassianAdminUserProducts(runtime *plugin.Runtime, args map[string]* return res, nil } -func (c *mqlAtlassianAdminUserProducts) MqlName() string { - return "atlassian.admin.user.products" +func (c *mqlAtlassianJiraUser) MqlName() string { + return "atlassian.jira.user" } -func (c *mqlAtlassianAdminUserProducts) MqlID() string { +func (c *mqlAtlassianJiraUser) MqlID() string { return c.__id } + +func (c *mqlAtlassianJiraUser) GetId() *plugin.TValue[string] { + return &c.Id +} + +// mqlAtlassianConfluence for the atlassian.confluence resource +type mqlAtlassianConfluence struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianConfluenceInternal it will be used here + Users plugin.TValue[[]interface{}] +} + +// createAtlassianConfluence creates a new instance of this resource +func createAtlassianConfluence(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianConfluence{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.confluence", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianConfluence) MqlName() string { + return "atlassian.confluence" +} + +func (c *mqlAtlassianConfluence) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianConfluence) GetUsers() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Users, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.confluence", c.__id, "users") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.users() + }) +} + +// mqlAtlassianConfluenceUser for the atlassian.confluence.user resource +type mqlAtlassianConfluenceUser struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianConfluenceUserInternal it will be used here + Id plugin.TValue[string] +} + +// createAtlassianConfluenceUser creates a new instance of this resource +func createAtlassianConfluenceUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianConfluenceUser{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + // to override __id implement: id() (string, error) + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.confluence.user", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianConfluenceUser) MqlName() string { + return "atlassian.confluence.user" +} + +func (c *mqlAtlassianConfluenceUser) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianConfluenceUser) GetId() *plugin.TValue[string] { + return &c.Id +} diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index d349322209..1bcf11be19 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -18,6 +18,17 @@ resources: type: {} users: {} min_mondoo_version: latest + atlassian.admin.organization.user: + fields: + accessBillable: {} + email: {} + id: {} + lastActive: {} + name: {} + picture: {} + status: {} + type: {} + min_mondoo_version: latest atlassian.admin.user: fields: accessBillable: {} @@ -33,3 +44,19 @@ resources: atlassian.admin.user.products: fields: {} min_mondoo_version: latest + atlassian.confluence: + fields: + users: {} + min_mondoo_version: latest + atlassian.confluence.user: + fields: + id: {} + min_mondoo_version: latest + atlassian.jira: + fields: + users: {} + min_mondoo_version: latest + atlassian.jira.user: + fields: + id: {} + min_mondoo_version: latest diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index f07f1d7ce2..fb8ae39275 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -2,6 +2,7 @@ package resources import ( "context" + "fmt" "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/llx" @@ -20,13 +21,14 @@ func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { log.Fatal().Err(err) } if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response) + log.Fatal().Msgf("Received response: %s\n", response.Status) } res := []interface{}{} for _, org := range organizations.Data { mqlAtlassianAdminOrg, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization", map[string]*llx.RawData{ - "id": llx.StringData(org.ID), + "id": llx.StringData(org.ID), + "type": llx.StringData(org.Type), }) if err != nil { log.Fatal().Err(err) @@ -37,13 +39,33 @@ func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { } func (a *mqlAtlassianAdminOrganization) users() ([]interface{}, error) { - //conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - //admin := conn.Admin() - - //permissions, response, err := admin.User - - //fmt.Println("Response HTTP Code", response.StatusCode) - + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + admin := conn.Admin() + orgId := a.Id.Data + fmt.Println("orgId: ", orgId) + users, response, err := admin.Organization.Users(context.Background(), orgId, "") + fmt.Println(response.Status) + fmt.Println(response.Endpoint) + fmt.Println(users.Data) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } res := []interface{}{} + fmt.Println("Num of users: ", len(users.Data)) + for _, user := range users.Data { + fmt.Println("adding user: ", user.Name) + mqlAtlassianAdminUser, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.user", + map[string]*llx.RawData{ + "id": llx.StringData(user.AccountID), + "name": llx.StringData(user.Name), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianAdminUser) + } return res, nil } diff --git a/providers/atlassian/resources/atlassian_confluence.go b/providers/atlassian/resources/atlassian_confluence.go new file mode 100644 index 0000000000..c0f8b739c0 --- /dev/null +++ b/providers/atlassian/resources/atlassian_confluence.go @@ -0,0 +1,10 @@ +package resources + +func (a *mqlAtlassianConfluence) id() (string, error) { + return "wip", nil +} + +func (a *mqlAtlassianConfluence) users() ([]interface{}, error) { + res := []interface{}{} + return res, nil +} diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go new file mode 100644 index 0000000000..3d36e320eb --- /dev/null +++ b/providers/atlassian/resources/atlassian_jira.go @@ -0,0 +1,10 @@ +package resources + +func (a *mqlAtlassianJira) id() (string, error) { + return "wip", nil +} + +func (a *mqlAtlassianJira) users() ([]interface{}, error) { + res := []interface{}{} + return res, nil +} From 2b1e9f771ea731c3fff54d8b3398ff366fb62e90 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 4 Oct 2023 15:22:12 +0200 Subject: [PATCH 08/90] wip getting users from jira --- providers/atlassian/connection/connection.go | 4 ++- .../atlassian/resources/atlassian_jira.go | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index 0ea6b05b47..e965629659 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -29,18 +29,20 @@ func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.C admin.Auth.SetBearerToken(apiKey) admin.Auth.SetUserAgent("curl/7.54.0") - jira, err := v2.New(nil, "lunalectric.atlassian.net") + jira, err := v2.New(nil, "https://lunalectric.atlassian.net") if err != nil { log.Fatal().Err(err) } jira.Auth.SetBasicAuth("marius@mondoo.com", token) + jira.Auth.SetUserAgent("curl/7.54.0") conn := &AtlassianConnection{ Conf: conf, id: id, asset: asset, admin: admin, + jira: jira, } return conn, nil diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index 3d36e320eb..956ee74487 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -1,10 +1,41 @@ package resources +import ( + "context" + "fmt" + + "github.com/rs/zerolog/log" + "go.mondoo.com/cnquery/llx" + "go.mondoo.com/cnquery/providers/atlassian/connection" +) + func (a *mqlAtlassianJira) id() (string, error) { return "wip", nil } func (a *mqlAtlassianJira) users() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + jira := conn.Jira() + users, response, err := jira.User.Search.Do(context.Background(), "", "", 0, 4) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + + fmt.Printf("response: %s\n", response.Status) res := []interface{}{} + for _, user := range users { + mqlAtlassianAdminOrg, err := CreateResource(a.MqlRuntime, "atlassian.jira.user", + map[string]*llx.RawData{ + "id": llx.StringData(user.AccountID), + "name": llx.StringData(user.Name), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianAdminOrg) + } return res, nil } From 8902a8379b8e868a2d9dc21e414d26e8093fee20 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 4 Oct 2023 15:54:53 +0200 Subject: [PATCH 09/90] receving users from jira works --- providers/atlassian/resources/atlassian.lr | 6 +++- providers/atlassian/resources/atlassian.lr.go | 31 ++++++++++++++++++- .../resources/atlassian.lr.manifest.yaml | 2 ++ .../atlassian/resources/atlassian_jira.go | 14 +++++---- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 111bc6366f..cff9eb3e0e 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -42,9 +42,11 @@ atlassian.jira { users() []atlassian.jira.user } -atlassian.jira.user { +atlassian.jira.user @defaults("id") { // AccountID id string + // Name + name string } atlassian.confluence { @@ -55,4 +57,6 @@ atlassian.confluence { atlassian.confluence.user { // AccountID id string + // Name + name string } diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 7f3f48eaf7..89ab384353 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -159,12 +159,18 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.jira.user.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraUser).GetId()).ToDataRes(types.String) }, + "atlassian.jira.user.name": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraUser).GetName()).ToDataRes(types.String) + }, "atlassian.confluence.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianConfluence).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.confluence.user"))) }, "atlassian.confluence.user.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianConfluenceUser).GetId()).ToDataRes(types.String) }, + "atlassian.confluence.user.name": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianConfluenceUser).GetName()).ToDataRes(types.String) + }, } func GetData(resource plugin.Resource, field string, args map[string]*llx.RawData) *plugin.DataRes { @@ -257,6 +263,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJiraUser).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.jira.user.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraUser).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.confluence.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianConfluence).__id, ok = v.Value.(string) return @@ -273,6 +283,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianConfluenceUser).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.confluence.user.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianConfluenceUser).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, } func SetData(resource plugin.Resource, field string, val *llx.RawData) error { @@ -614,6 +628,7 @@ type mqlAtlassianJiraUser struct { __id string // optional: if you define mqlAtlassianJiraUserInternal it will be used here Id plugin.TValue[string] + Name plugin.TValue[string] } // createAtlassianJiraUser creates a new instance of this resource @@ -627,7 +642,12 @@ func createAtlassianJiraUser(runtime *plugin.Runtime, args map[string]*llx.RawDa return res, err } - // to override __id implement: id() (string, error) + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } if runtime.HasRecording { args, err = runtime.ResourceFromRecording("atlassian.jira.user", res.__id) @@ -652,6 +672,10 @@ func (c *mqlAtlassianJiraUser) GetId() *plugin.TValue[string] { return &c.Id } +func (c *mqlAtlassianJiraUser) GetName() *plugin.TValue[string] { + return &c.Name +} + // mqlAtlassianConfluence for the atlassian.confluence resource type mqlAtlassianConfluence struct { MqlRuntime *plugin.Runtime @@ -719,6 +743,7 @@ type mqlAtlassianConfluenceUser struct { __id string // optional: if you define mqlAtlassianConfluenceUserInternal it will be used here Id plugin.TValue[string] + Name plugin.TValue[string] } // createAtlassianConfluenceUser creates a new instance of this resource @@ -756,3 +781,7 @@ func (c *mqlAtlassianConfluenceUser) MqlID() string { func (c *mqlAtlassianConfluenceUser) GetId() *plugin.TValue[string] { return &c.Id } + +func (c *mqlAtlassianConfluenceUser) GetName() *plugin.TValue[string] { + return &c.Name +} diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 1bcf11be19..735abc11af 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -51,6 +51,7 @@ resources: atlassian.confluence.user: fields: id: {} + name: {} min_mondoo_version: latest atlassian.jira: fields: @@ -59,4 +60,5 @@ resources: atlassian.jira.user: fields: id: {} + name: {} min_mondoo_version: latest diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index 956ee74487..416643dd97 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -2,7 +2,6 @@ package resources import ( "context" - "fmt" "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/llx" @@ -16,7 +15,7 @@ func (a *mqlAtlassianJira) id() (string, error) { func (a *mqlAtlassianJira) users() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) jira := conn.Jira() - users, response, err := jira.User.Search.Do(context.Background(), "", "", 0, 4) + users, response, err := jira.User.Search.Do(context.Background(), "", " ", 0, 20) if err != nil { log.Fatal().Err(err) } @@ -24,18 +23,21 @@ func (a *mqlAtlassianJira) users() ([]interface{}, error) { log.Fatal().Msgf("Received response: %s\n", response.Status) } - fmt.Printf("response: %s\n", response.Status) res := []interface{}{} for _, user := range users { - mqlAtlassianAdminOrg, err := CreateResource(a.MqlRuntime, "atlassian.jira.user", + mqlAtlassianJiraUser, err := CreateResource(a.MqlRuntime, "atlassian.jira.user", map[string]*llx.RawData{ "id": llx.StringData(user.AccountID), - "name": llx.StringData(user.Name), + "name": llx.StringData(user.DisplayName), }) if err != nil { log.Fatal().Err(err) } - res = append(res, mqlAtlassianAdminOrg) + res = append(res, mqlAtlassianJiraUser) } return res, nil } + +func (a *mqlAtlassianJiraUser) id() (string, error) { + return a.Id.Data, nil +} From f74a28ea2ca2b41ad1e5626d7b9f94f6f7997062 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 4 Oct 2023 15:56:36 +0200 Subject: [PATCH 10/90] fix spelling --- .github/actions/spelling/expect.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index 7996cd1141..ccb1b40756 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -26,6 +26,7 @@ iap ilb ingresstls iotedge +jira linux loggingservice managedzone From d9960efa85b6467fa09a8b6b95ca8307b700aac0 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 4 Oct 2023 15:57:14 +0200 Subject: [PATCH 11/90] add confluence to spelling --- .github/actions/spelling/expect.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index ccb1b40756..c586f12c8b 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -9,6 +9,7 @@ cavium cdn certificatechains cmek +confluence cryptokey customresources datapath From a8594b24756a6a62ef5991ebb78b1f39b9feb475 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 4 Oct 2023 16:15:12 +0200 Subject: [PATCH 12/90] working on confluence --- providers/atlassian/connection/connection.go | 41 +++++++++++++------ .../resources/atlassian_confluence.go | 30 ++++++++++++++ .../atlassian/resources/atlassian_jira.go | 2 +- 3 files changed, 60 insertions(+), 13 deletions(-) diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index e965629659..732bf2727e 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -4,6 +4,7 @@ import ( "os" "github.com/ctreminiom/go-atlassian/admin" + "github.com/ctreminiom/go-atlassian/confluence" "github.com/ctreminiom/go-atlassian/jira/v2" _ "github.com/ctreminiom/go-atlassian/jira/v3" "github.com/rs/zerolog/log" @@ -11,17 +12,20 @@ import ( ) type AtlassianConnection struct { - id uint32 - Conf *inventory.Config - asset *inventory.Asset - admin *admin.Client - jira *v2.Client + id uint32 + Conf *inventory.Config + asset *inventory.Asset + admin *admin.Client + jira *v2.Client + confluece *confluence.Client // Add custom connection fields here } func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AtlassianConnection, error) { apiKey := os.Getenv("ATLASSIAN_KEY") token := os.Getenv("ATLASSIAN_TOKEN") + host := "https://lunalectric.atlassian.net" + mail := "marius@mondoo.com" admin, err := admin.New(nil) if err != nil { log.Fatal().Err(err) @@ -29,20 +33,29 @@ func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.C admin.Auth.SetBearerToken(apiKey) admin.Auth.SetUserAgent("curl/7.54.0") - jira, err := v2.New(nil, "https://lunalectric.atlassian.net") + jira, err := v2.New(nil, host) if err != nil { log.Fatal().Err(err) } - jira.Auth.SetBasicAuth("marius@mondoo.com", token) + jira.Auth.SetBasicAuth(mail, token) jira.Auth.SetUserAgent("curl/7.54.0") + confluence, err := confluence.New(nil, host) + if err != nil { + log.Fatal().Err(err) + } + + confluence.Auth.SetBasicAuth(mail, token) + confluence.Auth.SetUserAgent("curl/7.54.0") + conn := &AtlassianConnection{ - Conf: conf, - id: id, - asset: asset, - admin: admin, - jira: jira, + Conf: conf, + id: id, + asset: asset, + admin: admin, + jira: jira, + confluece: confluence, } return conn, nil @@ -67,3 +80,7 @@ func (c *AtlassianConnection) Admin() *admin.Client { func (c *AtlassianConnection) Jira() *v2.Client { return c.jira } + +func (c *AtlassianConnection) Confluence() *confluence.Client { + return c.confluece +} diff --git a/providers/atlassian/resources/atlassian_confluence.go b/providers/atlassian/resources/atlassian_confluence.go index c0f8b739c0..beaccee8f0 100644 --- a/providers/atlassian/resources/atlassian_confluence.go +++ b/providers/atlassian/resources/atlassian_confluence.go @@ -1,10 +1,40 @@ package resources +import ( + "context" + + "github.com/rs/zerolog/log" + "go.mondoo.com/cnquery/llx" + "go.mondoo.com/cnquery/providers/atlassian/connection" +) + func (a *mqlAtlassianConfluence) id() (string, error) { return "wip", nil } func (a *mqlAtlassianConfluence) users() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + confluence := conn.Confluence() + cql := "type = page" + users, response, err := confluence.Search.Users(context.Background(), cql, 0, 1000, nil) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + res := []interface{}{} + for _, user := range users.Results { + mqlAtlassianJiraUser, err := CreateResource(a.MqlRuntime, "atlassian.jira.user", + map[string]*llx.RawData{ + "id": llx.StringData(user.User.AccountID), + "name": llx.StringData(user.User.DisplayName), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianJiraUser) + } return res, nil } diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index 416643dd97..056a0cd096 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -15,7 +15,7 @@ func (a *mqlAtlassianJira) id() (string, error) { func (a *mqlAtlassianJira) users() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) jira := conn.Jira() - users, response, err := jira.User.Search.Do(context.Background(), "", " ", 0, 20) + users, response, err := jira.User.Search.Do(context.Background(), "", " ", 0, 1000) if err != nil { log.Fatal().Err(err) } From dd53151348093abe8a66e94f5a673a8b681a0832 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 4 Oct 2023 16:49:36 +0200 Subject: [PATCH 13/90] add account type for filtering --- providers/atlassian/resources/atlassian.lr | 4 ++++ providers/atlassian/resources/atlassian.lr.go | 24 +++++++++++++++++++ .../resources/atlassian.lr.manifest.yaml | 2 ++ .../resources/atlassian_confluence.go | 4 ++-- .../atlassian/resources/atlassian_jira.go | 1 + 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index cff9eb3e0e..c11f33c9ce 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -47,6 +47,8 @@ atlassian.jira.user @defaults("id") { id string // Name name string + // Account type + type string } atlassian.confluence { @@ -59,4 +61,6 @@ atlassian.confluence.user { id string // Name name string + // Account type + type string } diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 89ab384353..2578877133 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -162,6 +162,9 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.jira.user.name": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraUser).GetName()).ToDataRes(types.String) }, + "atlassian.jira.user.type": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraUser).GetType()).ToDataRes(types.String) + }, "atlassian.confluence.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianConfluence).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.confluence.user"))) }, @@ -171,6 +174,9 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.confluence.user.name": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianConfluenceUser).GetName()).ToDataRes(types.String) }, + "atlassian.confluence.user.type": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianConfluenceUser).GetType()).ToDataRes(types.String) + }, } func GetData(resource plugin.Resource, field string, args map[string]*llx.RawData) *plugin.DataRes { @@ -267,6 +273,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJiraUser).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.jira.user.type": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraUser).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.confluence.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianConfluence).__id, ok = v.Value.(string) return @@ -287,6 +297,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianConfluenceUser).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.confluence.user.type": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianConfluenceUser).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, } func SetData(resource plugin.Resource, field string, val *llx.RawData) error { @@ -629,6 +643,7 @@ type mqlAtlassianJiraUser struct { // optional: if you define mqlAtlassianJiraUserInternal it will be used here Id plugin.TValue[string] Name plugin.TValue[string] + Type plugin.TValue[string] } // createAtlassianJiraUser creates a new instance of this resource @@ -676,6 +691,10 @@ func (c *mqlAtlassianJiraUser) GetName() *plugin.TValue[string] { return &c.Name } +func (c *mqlAtlassianJiraUser) GetType() *plugin.TValue[string] { + return &c.Type +} + // mqlAtlassianConfluence for the atlassian.confluence resource type mqlAtlassianConfluence struct { MqlRuntime *plugin.Runtime @@ -744,6 +763,7 @@ type mqlAtlassianConfluenceUser struct { // optional: if you define mqlAtlassianConfluenceUserInternal it will be used here Id plugin.TValue[string] Name plugin.TValue[string] + Type plugin.TValue[string] } // createAtlassianConfluenceUser creates a new instance of this resource @@ -785,3 +805,7 @@ func (c *mqlAtlassianConfluenceUser) GetId() *plugin.TValue[string] { func (c *mqlAtlassianConfluenceUser) GetName() *plugin.TValue[string] { return &c.Name } + +func (c *mqlAtlassianConfluenceUser) GetType() *plugin.TValue[string] { + return &c.Type +} diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 735abc11af..836799312f 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -52,6 +52,7 @@ resources: fields: id: {} name: {} + type: {} min_mondoo_version: latest atlassian.jira: fields: @@ -61,4 +62,5 @@ resources: fields: id: {} name: {} + type: {} min_mondoo_version: latest diff --git a/providers/atlassian/resources/atlassian_confluence.go b/providers/atlassian/resources/atlassian_confluence.go index beaccee8f0..5e10272cc7 100644 --- a/providers/atlassian/resources/atlassian_confluence.go +++ b/providers/atlassian/resources/atlassian_confluence.go @@ -26,7 +26,7 @@ func (a *mqlAtlassianConfluence) users() ([]interface{}, error) { res := []interface{}{} for _, user := range users.Results { - mqlAtlassianJiraUser, err := CreateResource(a.MqlRuntime, "atlassian.jira.user", + mqlAtlassianConfluenceUser, err := CreateResource(a.MqlRuntime, "atlassian.confluence.user", map[string]*llx.RawData{ "id": llx.StringData(user.User.AccountID), "name": llx.StringData(user.User.DisplayName), @@ -34,7 +34,7 @@ func (a *mqlAtlassianConfluence) users() ([]interface{}, error) { if err != nil { log.Fatal().Err(err) } - res = append(res, mqlAtlassianJiraUser) + res = append(res, mqlAtlassianConfluenceUser) } return res, nil } diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index 056a0cd096..7f0c5df509 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -29,6 +29,7 @@ func (a *mqlAtlassianJira) users() ([]interface{}, error) { map[string]*llx.RawData{ "id": llx.StringData(user.AccountID), "name": llx.StringData(user.DisplayName), + "type": llx.StringData(user.AccountType), }) if err != nil { log.Fatal().Err(err) From 05c1766a55d04dfb54ab71b095a1584e4a09f253 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 4 Oct 2023 17:13:48 +0200 Subject: [PATCH 14/90] add groups to jira users --- providers/atlassian/resources/atlassian.lr | 10 ++ providers/atlassian/resources/atlassian.lr.go | 100 ++++++++++++++++++ .../resources/atlassian.lr.manifest.yaml | 15 +++ .../atlassian/resources/atlassian_jira.go | 38 ++++++- 4 files changed, 160 insertions(+), 3 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index c11f33c9ce..1f4c604202 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -49,6 +49,15 @@ atlassian.jira.user @defaults("id") { name string // Account type type string + // Picture of the user + picture string + // Groups + groups() []atlassian.jira.user.group +} + +atlassian.jira.user.group @defaults("id") { + // GroupID + id string } atlassian.confluence { @@ -63,4 +72,5 @@ atlassian.confluence.user { name string // Account type type string + // Picture of the user } diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 2578877133..041e041c8d 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -41,6 +41,10 @@ func init() { // to override args, implement: initAtlassianJiraUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianJiraUser, }, + "atlassian.jira.user.group": { + // to override args, implement: initAtlassianJiraUserGroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianJiraUserGroup, + }, "atlassian.confluence": { // to override args, implement: initAtlassianConfluence(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianConfluence, @@ -165,6 +169,15 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.jira.user.type": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraUser).GetType()).ToDataRes(types.String) }, + "atlassian.jira.user.picture": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraUser).GetPicture()).ToDataRes(types.String) + }, + "atlassian.jira.user.groups": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraUser).GetGroups()).ToDataRes(types.Array(types.Resource("atlassian.jira.user.group"))) + }, + "atlassian.jira.user.group.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraUserGroup).GetId()).ToDataRes(types.String) + }, "atlassian.confluence.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianConfluence).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.confluence.user"))) }, @@ -277,6 +290,22 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJiraUser).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.jira.user.picture": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraUser).Picture, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.jira.user.groups": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraUser).Groups, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, + "atlassian.jira.user.group.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraUserGroup).__id, ok = v.Value.(string) + return + }, + "atlassian.jira.user.group.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraUserGroup).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.confluence.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianConfluence).__id, ok = v.Value.(string) return @@ -644,6 +673,8 @@ type mqlAtlassianJiraUser struct { Id plugin.TValue[string] Name plugin.TValue[string] Type plugin.TValue[string] + Picture plugin.TValue[string] + Groups plugin.TValue[[]interface{}] } // createAtlassianJiraUser creates a new instance of this resource @@ -695,6 +726,75 @@ func (c *mqlAtlassianJiraUser) GetType() *plugin.TValue[string] { return &c.Type } +func (c *mqlAtlassianJiraUser) GetPicture() *plugin.TValue[string] { + return &c.Picture +} + +func (c *mqlAtlassianJiraUser) GetGroups() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Groups, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.jira.user", c.__id, "groups") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.groups() + }) +} + +// mqlAtlassianJiraUserGroup for the atlassian.jira.user.group resource +type mqlAtlassianJiraUserGroup struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianJiraUserGroupInternal it will be used here + Id plugin.TValue[string] +} + +// createAtlassianJiraUserGroup creates a new instance of this resource +func createAtlassianJiraUserGroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianJiraUserGroup{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.jira.user.group", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianJiraUserGroup) MqlName() string { + return "atlassian.jira.user.group" +} + +func (c *mqlAtlassianJiraUserGroup) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianJiraUserGroup) GetId() *plugin.TValue[string] { + return &c.Id +} + // mqlAtlassianConfluence for the atlassian.confluence resource type mqlAtlassianConfluence struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 836799312f..3045ccc881 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -52,15 +52,30 @@ resources: fields: id: {} name: {} + picture: {} type: {} min_mondoo_version: latest atlassian.jira: fields: users: {} min_mondoo_version: latest + atlassian.jira.groups: + fields: + id: {} + min_mondoo_version: latest atlassian.jira.user: fields: + groups: {} id: {} name: {} + picture: {} type: {} min_mondoo_version: latest + atlassian.jira.user.group: + fields: + id: {} + min_mondoo_version: latest + atlassian.jira.user.groups: + fields: + id: {} + min_mondoo_version: latest diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index 7f0c5df509..4fa1e72275 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -2,6 +2,7 @@ package resources import ( "context" + "fmt" "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/llx" @@ -27,9 +28,10 @@ func (a *mqlAtlassianJira) users() ([]interface{}, error) { for _, user := range users { mqlAtlassianJiraUser, err := CreateResource(a.MqlRuntime, "atlassian.jira.user", map[string]*llx.RawData{ - "id": llx.StringData(user.AccountID), - "name": llx.StringData(user.DisplayName), - "type": llx.StringData(user.AccountType), + "id": llx.StringData(user.AccountID), + "name": llx.StringData(user.DisplayName), + "type": llx.StringData(user.AccountType), + "picture": llx.StringData(user.AvatarUrls.One6X16), }) if err != nil { log.Fatal().Err(err) @@ -39,6 +41,36 @@ func (a *mqlAtlassianJira) users() ([]interface{}, error) { return res, nil } +func (a *mqlAtlassianJiraUser) groups() ([]interface{}, error) { + fmt.Println("user groups") + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + jira := conn.Jira() + groups, response, err := jira.Group.Bulk(context.Background(), nil, 0, 1000) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + + res := []interface{}{} + for _, group := range groups.Values { + mqlAtlassianJiraUserGroup, err := CreateResource(a.MqlRuntime, "atlassian.jira.user.group", + map[string]*llx.RawData{ + "id": llx.StringData(group.GroupID), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianJiraUserGroup) + } + return res, nil +} + func (a *mqlAtlassianJiraUser) id() (string, error) { return a.Id.Data, nil } + +func (a *mqlAtlassianJiraUserGroup) id() (string, error) { + return a.Id.Data, nil +} From a97fc0713c15d4695365b3640c56472bef798fbb Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Thu, 5 Oct 2023 10:22:44 +0200 Subject: [PATCH 15/90] getting users from confluence works --- providers/atlassian/resources/atlassian.lr | 2 +- providers/atlassian/resources/atlassian.lr.go | 7 ++++++- providers/atlassian/resources/atlassian_confluence.go | 7 +++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 1f4c604202..fb118767d6 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -65,7 +65,7 @@ atlassian.confluence { users() []atlassian.confluence.user } -atlassian.confluence.user { +atlassian.confluence.user @defaults("id") { // AccountID id string // Name diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 041e041c8d..6274b65ab9 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -877,7 +877,12 @@ func createAtlassianConfluenceUser(runtime *plugin.Runtime, args map[string]*llx return res, err } - // to override __id implement: id() (string, error) + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } if runtime.HasRecording { args, err = runtime.ResourceFromRecording("atlassian.confluence.user", res.__id) diff --git a/providers/atlassian/resources/atlassian_confluence.go b/providers/atlassian/resources/atlassian_confluence.go index 5e10272cc7..960ff99499 100644 --- a/providers/atlassian/resources/atlassian_confluence.go +++ b/providers/atlassian/resources/atlassian_confluence.go @@ -15,7 +15,7 @@ func (a *mqlAtlassianConfluence) id() (string, error) { func (a *mqlAtlassianConfluence) users() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) confluence := conn.Confluence() - cql := "type = page" + cql := "type = user" users, response, err := confluence.Search.Users(context.Background(), cql, 0, 1000, nil) if err != nil { log.Fatal().Err(err) @@ -23,7 +23,6 @@ func (a *mqlAtlassianConfluence) users() ([]interface{}, error) { if response.Status != "200 OK" { log.Fatal().Msgf("Received response: %s\n", response.Status) } - res := []interface{}{} for _, user := range users.Results { mqlAtlassianConfluenceUser, err := CreateResource(a.MqlRuntime, "atlassian.confluence.user", @@ -38,3 +37,7 @@ func (a *mqlAtlassianConfluence) users() ([]interface{}, error) { } return res, nil } + +func (a *mqlAtlassianConfluenceUser) id() (string, error) { + return a.Id.Data, nil +} From d173c7ab4d274dd9b7650d79d4b17a9a044f443b Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Thu, 5 Oct 2023 10:49:55 +0200 Subject: [PATCH 16/90] add user type to filter out bots --- providers/atlassian/resources/atlassian.lr | 1 - providers/atlassian/resources/atlassian_confluence.go | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index fb118767d6..6261ef7f28 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -72,5 +72,4 @@ atlassian.confluence.user @defaults("id") { name string // Account type type string - // Picture of the user } diff --git a/providers/atlassian/resources/atlassian_confluence.go b/providers/atlassian/resources/atlassian_confluence.go index 960ff99499..9c15fd86af 100644 --- a/providers/atlassian/resources/atlassian_confluence.go +++ b/providers/atlassian/resources/atlassian_confluence.go @@ -28,6 +28,7 @@ func (a *mqlAtlassianConfluence) users() ([]interface{}, error) { mqlAtlassianConfluenceUser, err := CreateResource(a.MqlRuntime, "atlassian.confluence.user", map[string]*llx.RawData{ "id": llx.StringData(user.User.AccountID), + "type": llx.StringData(user.User.AccountType), "name": llx.StringData(user.User.DisplayName), }) if err != nil { From beeca19c59b412ae44fdc41e11e5a5e03700996c Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Thu, 5 Oct 2023 11:12:46 +0200 Subject: [PATCH 17/90] add organization policies --- providers/atlassian/resources/atlassian.lr | 11 ++ providers/atlassian/resources/atlassian.lr.go | 107 ++++++++++++++++++ .../resources/atlassian.lr.manifest.yaml | 7 ++ .../atlassian/resources/atlassian_admin.go | 33 +++++- 4 files changed, 152 insertions(+), 6 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 6261ef7f28..4b799b57e6 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -16,6 +16,17 @@ atlassian.admin.organization @defaults("id") { type string // Organization users users() []atlassian.admin.organization.user + // Policies + policies() []atlassian.admin.organization.policy +} + +atlassian.admin.organization.policy @defaults("id") { + // Policy ID + id string + // Policy type + type string + // Policy Name + name string } atlassian.admin.organization.user { diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 6274b65ab9..e9d7c377d8 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -29,6 +29,10 @@ func init() { // to override args, implement: initAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganization, }, + "atlassian.admin.organization.policy": { + // to override args, implement: initAtlassianAdminOrganizationPolicy(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianAdminOrganizationPolicy, + }, "atlassian.admin.organization.user": { // to override args, implement: initAtlassianAdminOrganizationUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganizationUser, @@ -133,6 +137,18 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganization).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.user"))) }, + "atlassian.admin.organization.policies": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganization).GetPolicies()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.policy"))) + }, + "atlassian.admin.organization.policy.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationPolicy).GetId()).ToDataRes(types.String) + }, + "atlassian.admin.organization.policy.type": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationPolicy).GetType()).ToDataRes(types.String) + }, + "atlassian.admin.organization.policy.name": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationPolicy).GetName()).ToDataRes(types.String) + }, "atlassian.admin.organization.user.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationUser).GetId()).ToDataRes(types.String) }, @@ -230,6 +246,26 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganization).Users, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "atlassian.admin.organization.policies": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganization).Policies, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, + "atlassian.admin.organization.policy.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationPolicy).__id, ok = v.Value.(string) + return + }, + "atlassian.admin.organization.policy.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationPolicy).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.organization.policy.type": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationPolicy).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.organization.policy.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationPolicy).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.admin.organization.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganizationUser).__id, ok = v.Value.(string) return @@ -467,6 +503,7 @@ type mqlAtlassianAdminOrganization struct { Id plugin.TValue[string] Type plugin.TValue[string] Users plugin.TValue[[]interface{}] + Policies plugin.TValue[[]interface{}] } // createAtlassianAdminOrganization creates a new instance of this resource @@ -525,6 +562,76 @@ func (c *mqlAtlassianAdminOrganization) GetUsers() *plugin.TValue[[]interface{}] }) } +func (c *mqlAtlassianAdminOrganization) GetPolicies() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Policies, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization", c.__id, "policies") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.policies() + }) +} + +// mqlAtlassianAdminOrganizationPolicy for the atlassian.admin.organization.policy resource +type mqlAtlassianAdminOrganizationPolicy struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianAdminOrganizationPolicyInternal it will be used here + Id plugin.TValue[string] + Type plugin.TValue[string] + Name plugin.TValue[string] +} + +// createAtlassianAdminOrganizationPolicy creates a new instance of this resource +func createAtlassianAdminOrganizationPolicy(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianAdminOrganizationPolicy{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + // to override __id implement: id() (string, error) + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.admin.organization.policy", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianAdminOrganizationPolicy) MqlName() string { + return "atlassian.admin.organization.policy" +} + +func (c *mqlAtlassianAdminOrganizationPolicy) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianAdminOrganizationPolicy) GetId() *plugin.TValue[string] { + return &c.Id +} + +func (c *mqlAtlassianAdminOrganizationPolicy) GetType() *plugin.TValue[string] { + return &c.Type +} + +func (c *mqlAtlassianAdminOrganizationPolicy) GetName() *plugin.TValue[string] { + return &c.Name +} + // mqlAtlassianAdminOrganizationUser for the atlassian.admin.organization.user resource type mqlAtlassianAdminOrganizationUser struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 3045ccc881..397b34c7bf 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -15,9 +15,16 @@ resources: atlassian.admin.organization: fields: id: {} + policies: {} type: {} users: {} min_mondoo_version: latest + atlassian.admin.organization.policy: + fields: + id: {} + name: {} + type: {} + min_mondoo_version: latest atlassian.admin.organization.user: fields: accessBillable: {} diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index fb8ae39275..f3e8c60c59 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -42,11 +42,7 @@ func (a *mqlAtlassianAdminOrganization) users() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) admin := conn.Admin() orgId := a.Id.Data - fmt.Println("orgId: ", orgId) users, response, err := admin.Organization.Users(context.Background(), orgId, "") - fmt.Println(response.Status) - fmt.Println(response.Endpoint) - fmt.Println(users.Data) if err != nil { log.Fatal().Err(err) } @@ -54,9 +50,7 @@ func (a *mqlAtlassianAdminOrganization) users() ([]interface{}, error) { log.Fatal().Msgf("Received response: %s\n", response.Status) } res := []interface{}{} - fmt.Println("Num of users: ", len(users.Data)) for _, user := range users.Data { - fmt.Println("adding user: ", user.Name) mqlAtlassianAdminUser, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.user", map[string]*llx.RawData{ "id": llx.StringData(user.AccountID), @@ -69,3 +63,30 @@ func (a *mqlAtlassianAdminOrganization) users() ([]interface{}, error) { } return res, nil } + +func (a *mqlAtlassianAdminOrganization) policies() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + admin := conn.Admin() + orgId := a.Id.Data + policies, response, err := admin.Organization.Policy.Gets(context.Background(), orgId, "", "") + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + res := []interface{}{} + for _, policy := range policies.Data { + mqlAtlassianAdminPolicy, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.policy", + map[string]*llx.RawData{ + "id": llx.StringData(policy.ID), + "type": llx.StringData(policy.Type), + "name": llx.StringData(policy.Attributes.Name), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianAdminPolicy) + } + return res, nil +} From 08facf643cd7c1f20fe232826d8848631f911c5a Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Thu, 5 Oct 2023 12:13:29 +0200 Subject: [PATCH 18/90] add domains --- providers/atlassian/resources/atlassian.lr | 7 ++ providers/atlassian/resources/atlassian.lr.go | 83 +++++++++++++++++++ .../resources/atlassian.lr.manifest.yaml | 5 ++ .../atlassian/resources/atlassian_admin.go | 26 +++++- 4 files changed, 120 insertions(+), 1 deletion(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 4b799b57e6..d4d18825ec 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -18,6 +18,8 @@ atlassian.admin.organization @defaults("id") { users() []atlassian.admin.organization.user // Policies policies() []atlassian.admin.organization.policy + // Domains + domains() []atlassian.admin.organization.domain } atlassian.admin.organization.policy @defaults("id") { @@ -29,6 +31,11 @@ atlassian.admin.organization.policy @defaults("id") { name string } +atlassian.admin.organization.domain @defaults("id") { + // Domain ID + id string +} + atlassian.admin.organization.user { // Account ID id string diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index e9d7c377d8..fde6a98d06 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -33,6 +33,10 @@ func init() { // to override args, implement: initAtlassianAdminOrganizationPolicy(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganizationPolicy, }, + "atlassian.admin.organization.domain": { + // to override args, implement: initAtlassianAdminOrganizationDomain(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianAdminOrganizationDomain, + }, "atlassian.admin.organization.user": { // to override args, implement: initAtlassianAdminOrganizationUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganizationUser, @@ -140,6 +144,9 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.policies": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganization).GetPolicies()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.policy"))) }, + "atlassian.admin.organization.domains": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganization).GetDomains()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.domain"))) + }, "atlassian.admin.organization.policy.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationPolicy).GetId()).ToDataRes(types.String) }, @@ -149,6 +156,9 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.policy.name": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationPolicy).GetName()).ToDataRes(types.String) }, + "atlassian.admin.organization.domain.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationDomain).GetId()).ToDataRes(types.String) + }, "atlassian.admin.organization.user.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationUser).GetId()).ToDataRes(types.String) }, @@ -250,6 +260,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganization).Policies, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "atlassian.admin.organization.domains": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganization).Domains, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, "atlassian.admin.organization.policy.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganizationPolicy).__id, ok = v.Value.(string) return @@ -266,6 +280,14 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganizationPolicy).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.admin.organization.domain.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationDomain).__id, ok = v.Value.(string) + return + }, + "atlassian.admin.organization.domain.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationDomain).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.admin.organization.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganizationUser).__id, ok = v.Value.(string) return @@ -504,6 +526,7 @@ type mqlAtlassianAdminOrganization struct { Type plugin.TValue[string] Users plugin.TValue[[]interface{}] Policies plugin.TValue[[]interface{}] + Domains plugin.TValue[[]interface{}] } // createAtlassianAdminOrganization creates a new instance of this resource @@ -578,6 +601,22 @@ func (c *mqlAtlassianAdminOrganization) GetPolicies() *plugin.TValue[[]interface }) } +func (c *mqlAtlassianAdminOrganization) GetDomains() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Domains, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization", c.__id, "domains") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.domains() + }) +} + // mqlAtlassianAdminOrganizationPolicy for the atlassian.admin.organization.policy resource type mqlAtlassianAdminOrganizationPolicy struct { MqlRuntime *plugin.Runtime @@ -632,6 +671,50 @@ func (c *mqlAtlassianAdminOrganizationPolicy) GetName() *plugin.TValue[string] { return &c.Name } +// mqlAtlassianAdminOrganizationDomain for the atlassian.admin.organization.domain resource +type mqlAtlassianAdminOrganizationDomain struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianAdminOrganizationDomainInternal it will be used here + Id plugin.TValue[string] +} + +// createAtlassianAdminOrganizationDomain creates a new instance of this resource +func createAtlassianAdminOrganizationDomain(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianAdminOrganizationDomain{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + // to override __id implement: id() (string, error) + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.admin.organization.domain", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianAdminOrganizationDomain) MqlName() string { + return "atlassian.admin.organization.domain" +} + +func (c *mqlAtlassianAdminOrganizationDomain) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianAdminOrganizationDomain) GetId() *plugin.TValue[string] { + return &c.Id +} + // mqlAtlassianAdminOrganizationUser for the atlassian.admin.organization.user resource type mqlAtlassianAdminOrganizationUser struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 397b34c7bf..0ff801f899 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -14,11 +14,16 @@ resources: min_mondoo_version: latest atlassian.admin.organization: fields: + domains: {} id: {} policies: {} type: {} users: {} min_mondoo_version: latest + atlassian.admin.organization.domain: + fields: + id: {} + min_mondoo_version: latest atlassian.admin.organization.policy: fields: id: {} diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index f3e8c60c59..4b0bc93757 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -2,7 +2,6 @@ package resources import ( "context" - "fmt" "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/llx" @@ -90,3 +89,28 @@ func (a *mqlAtlassianAdminOrganization) policies() ([]interface{}, error) { } return res, nil } + +func (a *mqlAtlassianAdminOrganization) domains() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + admin := conn.Admin() + orgId := a.Id.Data + domains, response, err := admin.Organization.Domains(context.Background(), orgId, "") + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + res := []interface{}{} + for _, domain := range domains.Data { + mqlAtlassianAdminDomain, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.domain", + map[string]*llx.RawData{ + "id": llx.StringData(domain.ID), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianAdminDomain) + } + return res, nil +} From d286d99f1532f749d0d0bbae1243e7fb58315f65 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Thu, 5 Oct 2023 17:09:46 +0200 Subject: [PATCH 19/90] events --- providers/atlassian/resources/atlassian.lr | 7 ++ providers/atlassian/resources/atlassian.lr.go | 83 +++++++++++++++++++ .../resources/atlassian.lr.manifest.yaml | 5 ++ .../atlassian/resources/atlassian_admin.go | 25 ++++++ 4 files changed, 120 insertions(+) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index d4d18825ec..15158d3b0e 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -20,6 +20,8 @@ atlassian.admin.organization @defaults("id") { policies() []atlassian.admin.organization.policy // Domains domains() []atlassian.admin.organization.domain + // Events + events() []atlassian.admin.organization.event } atlassian.admin.organization.policy @defaults("id") { @@ -36,6 +38,11 @@ atlassian.admin.organization.domain @defaults("id") { id string } +atlassian.admin.organization.event @defaults("id") { + // Event ID + id string +} + atlassian.admin.organization.user { // Account ID id string diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index fde6a98d06..6c52e9d462 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -37,6 +37,10 @@ func init() { // to override args, implement: initAtlassianAdminOrganizationDomain(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganizationDomain, }, + "atlassian.admin.organization.event": { + // to override args, implement: initAtlassianAdminOrganizationEvent(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianAdminOrganizationEvent, + }, "atlassian.admin.organization.user": { // to override args, implement: initAtlassianAdminOrganizationUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganizationUser, @@ -147,6 +151,9 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.domains": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganization).GetDomains()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.domain"))) }, + "atlassian.admin.organization.events": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganization).GetEvents()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.event"))) + }, "atlassian.admin.organization.policy.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationPolicy).GetId()).ToDataRes(types.String) }, @@ -159,6 +166,9 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.domain.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationDomain).GetId()).ToDataRes(types.String) }, + "atlassian.admin.organization.event.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationEvent).GetId()).ToDataRes(types.String) + }, "atlassian.admin.organization.user.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationUser).GetId()).ToDataRes(types.String) }, @@ -264,6 +274,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganization).Domains, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "atlassian.admin.organization.events": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganization).Events, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, "atlassian.admin.organization.policy.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganizationPolicy).__id, ok = v.Value.(string) return @@ -288,6 +302,14 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganizationDomain).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.admin.organization.event.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationEvent).__id, ok = v.Value.(string) + return + }, + "atlassian.admin.organization.event.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationEvent).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.admin.organization.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganizationUser).__id, ok = v.Value.(string) return @@ -527,6 +549,7 @@ type mqlAtlassianAdminOrganization struct { Users plugin.TValue[[]interface{}] Policies plugin.TValue[[]interface{}] Domains plugin.TValue[[]interface{}] + Events plugin.TValue[[]interface{}] } // createAtlassianAdminOrganization creates a new instance of this resource @@ -617,6 +640,22 @@ func (c *mqlAtlassianAdminOrganization) GetDomains() *plugin.TValue[[]interface{ }) } +func (c *mqlAtlassianAdminOrganization) GetEvents() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Events, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization", c.__id, "events") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.events() + }) +} + // mqlAtlassianAdminOrganizationPolicy for the atlassian.admin.organization.policy resource type mqlAtlassianAdminOrganizationPolicy struct { MqlRuntime *plugin.Runtime @@ -715,6 +754,50 @@ func (c *mqlAtlassianAdminOrganizationDomain) GetId() *plugin.TValue[string] { return &c.Id } +// mqlAtlassianAdminOrganizationEvent for the atlassian.admin.organization.event resource +type mqlAtlassianAdminOrganizationEvent struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianAdminOrganizationEventInternal it will be used here + Id plugin.TValue[string] +} + +// createAtlassianAdminOrganizationEvent creates a new instance of this resource +func createAtlassianAdminOrganizationEvent(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianAdminOrganizationEvent{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + // to override __id implement: id() (string, error) + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.admin.organization.event", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianAdminOrganizationEvent) MqlName() string { + return "atlassian.admin.organization.event" +} + +func (c *mqlAtlassianAdminOrganizationEvent) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianAdminOrganizationEvent) GetId() *plugin.TValue[string] { + return &c.Id +} + // mqlAtlassianAdminOrganizationUser for the atlassian.admin.organization.user resource type mqlAtlassianAdminOrganizationUser struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 0ff801f899..963fa05d4b 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -15,6 +15,7 @@ resources: atlassian.admin.organization: fields: domains: {} + events: {} id: {} policies: {} type: {} @@ -24,6 +25,10 @@ resources: fields: id: {} min_mondoo_version: latest + atlassian.admin.organization.event: + fields: + id: {} + min_mondoo_version: latest atlassian.admin.organization.policy: fields: id: {} diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index 4b0bc93757..9ac6c21687 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -114,3 +114,28 @@ func (a *mqlAtlassianAdminOrganization) domains() ([]interface{}, error) { } return res, nil } + +func (a *mqlAtlassianAdminOrganization) events() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + admin := conn.Admin() + orgId := a.Id.Data + events, response, err := admin.Organization.Events(context.Background(), orgId, nil, "") + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + res := []interface{}{} + for _, event := range events.Data { + mqlAtlassianAdminDomain, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.event", + map[string]*llx.RawData{ + "id": llx.StringData(event.ID), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianAdminDomain) + } + return res, nil +} From 65d84f22ca9a347fbccee7e4ecd33944f031e5cb Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Fri, 6 Oct 2023 16:31:20 +0200 Subject: [PATCH 20/90] v9 all the things --- providers/atlassian/config/config.go | 2 +- providers/atlassian/connection/connection.go | 2 +- providers/atlassian/gen/main.go | 4 +-- providers/atlassian/go.mod | 3 +- providers/atlassian/go.sum | 2 ++ providers/atlassian/main.go | 4 +-- providers/atlassian/provider/provider.go | 12 ++++---- providers/atlassian/resources/atlassian.lr | 4 +++ providers/atlassian/resources/atlassian.lr.go | 30 +++++++++++++++++-- .../resources/atlassian.lr.manifest.yaml | 2 ++ .../atlassian/resources/atlassian_admin.go | 12 ++++---- .../resources/atlassian_confluence.go | 4 +-- .../atlassian/resources/atlassian_jira.go | 4 +-- 13 files changed, 60 insertions(+), 25 deletions(-) diff --git a/providers/atlassian/config/config.go b/providers/atlassian/config/config.go index 9ba9b420ab..4599ea3795 100644 --- a/providers/atlassian/config/config.go +++ b/providers/atlassian/config/config.go @@ -1,6 +1,6 @@ package config -import "go.mondoo.com/cnquery/providers-sdk/v1/plugin" +import "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin" var Config = plugin.Provider{ Name: "atlassian", diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index 732bf2727e..e69df0fbe5 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -8,7 +8,7 @@ import ( "github.com/ctreminiom/go-atlassian/jira/v2" _ "github.com/ctreminiom/go-atlassian/jira/v3" "github.com/rs/zerolog/log" - "go.mondoo.com/cnquery/providers-sdk/v1/inventory" + "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" ) type AtlassianConnection struct { diff --git a/providers/atlassian/gen/main.go b/providers/atlassian/gen/main.go index f95f800717..4eca98086f 100644 --- a/providers/atlassian/gen/main.go +++ b/providers/atlassian/gen/main.go @@ -1,8 +1,8 @@ package main import ( - "go.mondoo.com/cnquery/providers-sdk/v1/plugin/gen" - "go.mondoo.com/cnquery/providers/atlassian/config" + "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin/gen" + "go.mondoo.com/cnquery/v9/providers/atlassian/config" ) func main() { diff --git a/providers/atlassian/go.mod b/providers/atlassian/go.mod index cdd40c0166..fe7975f1b5 100644 --- a/providers/atlassian/go.mod +++ b/providers/atlassian/go.mod @@ -1,4 +1,4 @@ -module go.mondoo.com/cnquery/providers/atlassian +module go.mondoo.com/cnquery/v9/providers/atlassian go 1.20 @@ -6,6 +6,7 @@ require ( github.com/ctreminiom/go-atlassian v1.5.1 github.com/rs/zerolog v1.31.0 go.mondoo.com/cnquery v0.0.0-20231002111758-82a0179e7dbd + go.mondoo.com/cnquery/v9 v9.0.1 ) require ( diff --git a/providers/atlassian/go.sum b/providers/atlassian/go.sum index 195e684393..9d57ee2d44 100644 --- a/providers/atlassian/go.sum +++ b/providers/atlassian/go.sum @@ -262,6 +262,8 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.mondoo.com/cnquery v0.0.0-20231002111758-82a0179e7dbd h1:61ziiW1w0vR+004KFqgzp5JG8QlsS5NMnU4FkH2bjOk= go.mondoo.com/cnquery v0.0.0-20231002111758-82a0179e7dbd/go.mod h1:CyLGmRezek/8PswuVkmSLLScZqpMbACwFqL21eGeyYU= +go.mondoo.com/cnquery/v9 v9.0.1 h1:bbQ4ufIf2OluZlCPYz13JjsHuDav28kG3Lw2X4iOXlM= +go.mondoo.com/cnquery/v9 v9.0.1/go.mod h1:z5QWUfNdvmjclRPcXjZBQID2/o2ivYiRCF8+3HE6dLc= go.mondoo.com/ranger-rpc v0.5.1 h1:OaVQntDJWDRgbc9nXBP4wOCR9h9Bij8LgHHs86IguGk= go.mondoo.com/ranger-rpc v0.5.1/go.mod h1:3YKcqFrlPgaB4FZ4EoLgdmRtwMQdO7RoAkZYFn+F1eY= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= diff --git a/providers/atlassian/main.go b/providers/atlassian/main.go index 3dc0243f9e..b46f40a0ba 100644 --- a/providers/atlassian/main.go +++ b/providers/atlassian/main.go @@ -3,8 +3,8 @@ package main import ( "os" - "go.mondoo.com/cnquery/providers-sdk/v1/plugin" - "go.mondoo.com/cnquery/providers/atlassian/provider" + "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin" + "go.mondoo.com/cnquery/v9/providers/atlassian/provider" ) func main() { diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index dcce2f7ef2..4caeaddfbe 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -4,12 +4,12 @@ import ( "errors" "strconv" - "go.mondoo.com/cnquery/llx" - "go.mondoo.com/cnquery/providers-sdk/v1/inventory" - "go.mondoo.com/cnquery/providers-sdk/v1/plugin" - "go.mondoo.com/cnquery/providers-sdk/v1/upstream" - "go.mondoo.com/cnquery/providers/atlassian/connection" - "go.mondoo.com/cnquery/providers/atlassian/resources" + "go.mondoo.com/cnquery/v9/llx" + "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" + "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin" + "go.mondoo.com/cnquery/v9/providers-sdk/v1/upstream" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection" + "go.mondoo.com/cnquery/v9/providers/atlassian/resources" ) type Service struct { diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 15158d3b0e..6b2d5a7d15 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -31,6 +31,10 @@ atlassian.admin.organization.policy @defaults("id") { type string // Policy Name name string + // PolicyType + policyType string + // Status + status string } atlassian.admin.organization.domain @defaults("id") { diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 6c52e9d462..3c41a3c02e 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -8,9 +8,9 @@ package resources import ( "errors" - "go.mondoo.com/cnquery/llx" - "go.mondoo.com/cnquery/providers-sdk/v1/plugin" - "go.mondoo.com/cnquery/types" + "go.mondoo.com/cnquery/v9/llx" + "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin" + "go.mondoo.com/cnquery/v9/types" ) var resourceFactories map[string]plugin.ResourceFactory @@ -163,6 +163,12 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.policy.name": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationPolicy).GetName()).ToDataRes(types.String) }, + "atlassian.admin.organization.policy.policyType": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationPolicy).GetPolicyType()).ToDataRes(types.String) + }, + "atlassian.admin.organization.policy.status": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationPolicy).GetStatus()).ToDataRes(types.String) + }, "atlassian.admin.organization.domain.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationDomain).GetId()).ToDataRes(types.String) }, @@ -294,6 +300,14 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganizationPolicy).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.admin.organization.policy.policyType": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationPolicy).PolicyType, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.organization.policy.status": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationPolicy).Status, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.admin.organization.domain.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganizationDomain).__id, ok = v.Value.(string) return @@ -664,6 +678,8 @@ type mqlAtlassianAdminOrganizationPolicy struct { Id plugin.TValue[string] Type plugin.TValue[string] Name plugin.TValue[string] + PolicyType plugin.TValue[string] + Status plugin.TValue[string] } // createAtlassianAdminOrganizationPolicy creates a new instance of this resource @@ -710,6 +726,14 @@ func (c *mqlAtlassianAdminOrganizationPolicy) GetName() *plugin.TValue[string] { return &c.Name } +func (c *mqlAtlassianAdminOrganizationPolicy) GetPolicyType() *plugin.TValue[string] { + return &c.PolicyType +} + +func (c *mqlAtlassianAdminOrganizationPolicy) GetStatus() *plugin.TValue[string] { + return &c.Status +} + // mqlAtlassianAdminOrganizationDomain for the atlassian.admin.organization.domain resource type mqlAtlassianAdminOrganizationDomain struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 963fa05d4b..39b8613492 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -33,6 +33,8 @@ resources: fields: id: {} name: {} + policyType: {} + status: {} type: {} min_mondoo_version: latest atlassian.admin.organization.user: diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index 9ac6c21687..1824e91d58 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -4,8 +4,8 @@ import ( "context" "github.com/rs/zerolog/log" - "go.mondoo.com/cnquery/llx" - "go.mondoo.com/cnquery/providers/atlassian/connection" + "go.mondoo.com/cnquery/v9/llx" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection" ) func (a *mqlAtlassianAdmin) id() (string, error) { @@ -78,9 +78,11 @@ func (a *mqlAtlassianAdminOrganization) policies() ([]interface{}, error) { for _, policy := range policies.Data { mqlAtlassianAdminPolicy, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.policy", map[string]*llx.RawData{ - "id": llx.StringData(policy.ID), - "type": llx.StringData(policy.Type), - "name": llx.StringData(policy.Attributes.Name), + "id": llx.StringData(policy.ID), + "type": llx.StringData(policy.Type), + "name": llx.StringData(policy.Attributes.Name), + "status": llx.StringData(policy.Attributes.Status), + "policyType": llx.StringData(policy.Attributes.Type), }) if err != nil { log.Fatal().Err(err) diff --git a/providers/atlassian/resources/atlassian_confluence.go b/providers/atlassian/resources/atlassian_confluence.go index 9c15fd86af..609c5e6a00 100644 --- a/providers/atlassian/resources/atlassian_confluence.go +++ b/providers/atlassian/resources/atlassian_confluence.go @@ -4,8 +4,8 @@ import ( "context" "github.com/rs/zerolog/log" - "go.mondoo.com/cnquery/llx" - "go.mondoo.com/cnquery/providers/atlassian/connection" + "go.mondoo.com/cnquery/v9/llx" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection" ) func (a *mqlAtlassianConfluence) id() (string, error) { diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index 4fa1e72275..86e2cedcfb 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -5,8 +5,8 @@ import ( "fmt" "github.com/rs/zerolog/log" - "go.mondoo.com/cnquery/llx" - "go.mondoo.com/cnquery/providers/atlassian/connection" + "go.mondoo.com/cnquery/v9/llx" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection" ) func (a *mqlAtlassianJira) id() (string, error) { From a47afdc9e361bfcacdcfaee68f7fd8170dddc54b Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Fri, 6 Oct 2023 16:46:00 +0200 Subject: [PATCH 21/90] fix policy id --- providers/atlassian/resources/atlassian.lr.go | 7 ++++++- providers/atlassian/resources/atlassian_admin.go | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 3c41a3c02e..3f4aa990d8 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -693,7 +693,12 @@ func createAtlassianAdminOrganizationPolicy(runtime *plugin.Runtime, args map[st return res, err } - // to override __id implement: id() (string, error) + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } if runtime.HasRecording { args, err = runtime.ResourceFromRecording("atlassian.admin.organization.policy", res.__id) diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index 1824e91d58..63d37ea6a3 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -141,3 +141,7 @@ func (a *mqlAtlassianAdminOrganization) events() ([]interface{}, error) { } return res, nil } + +func (a *mqlAtlassianAdminOrganizationPolicy) id() (string, error) { + return a.Id.Data, nil +} From 743ec20126cc7d3b656920fab1accac694ee3c68 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 9 Oct 2023 08:28:36 +0200 Subject: [PATCH 22/90] jira projects --- providers/atlassian/resources/atlassian.lr | 9 ++ providers/atlassian/resources/atlassian.lr.go | 95 +++++++++++++++++++ .../resources/atlassian.lr.manifest.yaml | 6 ++ .../atlassian/resources/atlassian_jira.go | 28 +++++- 4 files changed, 136 insertions(+), 2 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 6b2d5a7d15..29d835b15d 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -69,6 +69,8 @@ atlassian.admin.organization.user { atlassian.jira { // Jira users users() []atlassian.jira.user + // Jira projects + projects() []atlassian.jira.projects } atlassian.jira.user @defaults("id") { @@ -84,6 +86,13 @@ atlassian.jira.user @defaults("id") { groups() []atlassian.jira.user.group } +atlassian.jira.project @defaults("id") { + // AccountID + id string + // Name + name string +} + atlassian.jira.user.group @defaults("id") { // GroupID id string diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 3f4aa990d8..bf3a5bfec1 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -53,6 +53,10 @@ func init() { // to override args, implement: initAtlassianJiraUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianJiraUser, }, + "atlassian.jira.project": { + // to override args, implement: initAtlassianJiraProject(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianJiraProject, + }, "atlassian.jira.user.group": { // to override args, implement: initAtlassianJiraUserGroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianJiraUserGroup, @@ -202,6 +206,9 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.jira.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJira).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.jira.user"))) }, + "atlassian.jira.projects": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJira).GetProjects()).ToDataRes(types.Array(types.Resource("atlassian.jira.projects"))) + }, "atlassian.jira.user.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraUser).GetId()).ToDataRes(types.String) }, @@ -217,6 +224,12 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.jira.user.groups": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraUser).GetGroups()).ToDataRes(types.Array(types.Resource("atlassian.jira.user.group"))) }, + "atlassian.jira.project.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraProject).GetId()).ToDataRes(types.String) + }, + "atlassian.jira.project.name": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraProject).GetName()).ToDataRes(types.String) + }, "atlassian.jira.user.group.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraUserGroup).GetId()).ToDataRes(types.String) }, @@ -368,6 +381,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJira).Users, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "atlassian.jira.projects": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJira).Projects, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, "atlassian.jira.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianJiraUser).__id, ok = v.Value.(string) return @@ -392,6 +409,18 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJiraUser).Groups, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "atlassian.jira.project.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraProject).__id, ok = v.Value.(string) + return + }, + "atlassian.jira.project.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraProject).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.jira.project.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraProject).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.jira.user.group.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianJiraUserGroup).__id, ok = v.Value.(string) return @@ -912,6 +941,7 @@ type mqlAtlassianJira struct { __id string // optional: if you define mqlAtlassianJiraInternal it will be used here Users plugin.TValue[[]interface{}] + Projects plugin.TValue[[]interface{}] } // createAtlassianJira creates a new instance of this resource @@ -967,6 +997,22 @@ func (c *mqlAtlassianJira) GetUsers() *plugin.TValue[[]interface{}] { }) } +func (c *mqlAtlassianJira) GetProjects() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Projects, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.jira", c.__id, "projects") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.projects() + }) +} + // mqlAtlassianJiraUser for the atlassian.jira.user resource type mqlAtlassianJiraUser struct { MqlRuntime *plugin.Runtime @@ -1048,6 +1094,55 @@ func (c *mqlAtlassianJiraUser) GetGroups() *plugin.TValue[[]interface{}] { }) } +// mqlAtlassianJiraProject for the atlassian.jira.project resource +type mqlAtlassianJiraProject struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianJiraProjectInternal it will be used here + Id plugin.TValue[string] + Name plugin.TValue[string] +} + +// createAtlassianJiraProject creates a new instance of this resource +func createAtlassianJiraProject(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianJiraProject{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + // to override __id implement: id() (string, error) + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.jira.project", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianJiraProject) MqlName() string { + return "atlassian.jira.project" +} + +func (c *mqlAtlassianJiraProject) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianJiraProject) GetId() *plugin.TValue[string] { + return &c.Id +} + +func (c *mqlAtlassianJiraProject) GetName() *plugin.TValue[string] { + return &c.Name +} + // mqlAtlassianJiraUserGroup for the atlassian.jira.user.group resource type mqlAtlassianJiraUserGroup struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 39b8613492..ed39647809 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -76,12 +76,18 @@ resources: min_mondoo_version: latest atlassian.jira: fields: + projects: {} users: {} min_mondoo_version: latest atlassian.jira.groups: fields: id: {} min_mondoo_version: latest + atlassian.jira.project: + fields: + id: {} + name: {} + min_mondoo_version: latest atlassian.jira.user: fields: groups: {} diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index 86e2cedcfb..94356aee0e 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -2,7 +2,6 @@ package resources import ( "context" - "fmt" "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/llx" @@ -42,7 +41,6 @@ func (a *mqlAtlassianJira) users() ([]interface{}, error) { } func (a *mqlAtlassianJiraUser) groups() ([]interface{}, error) { - fmt.Println("user groups") conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) jira := conn.Jira() groups, response, err := jira.Group.Bulk(context.Background(), nil, 0, 1000) @@ -67,6 +65,32 @@ func (a *mqlAtlassianJiraUser) groups() ([]interface{}, error) { return res, nil } +func (a *mqlAtlassianJira) projects() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + jira := conn.Jira() + projects, response, err := jira.Group.Bulk(context.Background(), nil, 0, 1000) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + + res := []interface{}{} + for _, project := range projects.Values { + mqlAtlassianJiraProject, err := CreateResource(a.MqlRuntime, "atlassian.jira.projects", + map[string]*llx.RawData{ + "id": llx.StringData(project.GroupID), + "name": llx.StringData(project.Name), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianJiraProject) + } + return res, nil +} + func (a *mqlAtlassianJiraUser) id() (string, error) { return a.Id.Data, nil } From da6b817d685c8ecf17903530e62cce3845f3b076 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 9 Oct 2023 08:36:43 +0200 Subject: [PATCH 23/90] fix jira projects --- providers/atlassian/go.mod | 1 - providers/atlassian/go.sum | 2 -- providers/atlassian/resources/atlassian.lr | 6 +++--- providers/atlassian/resources/atlassian.lr.go | 9 +++++++-- providers/atlassian/resources/atlassian_jira.go | 10 +++++++--- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/providers/atlassian/go.mod b/providers/atlassian/go.mod index fe7975f1b5..a2d02a1f58 100644 --- a/providers/atlassian/go.mod +++ b/providers/atlassian/go.mod @@ -5,7 +5,6 @@ go 1.20 require ( github.com/ctreminiom/go-atlassian v1.5.1 github.com/rs/zerolog v1.31.0 - go.mondoo.com/cnquery v0.0.0-20231002111758-82a0179e7dbd go.mondoo.com/cnquery/v9 v9.0.1 ) diff --git a/providers/atlassian/go.sum b/providers/atlassian/go.sum index 9d57ee2d44..0b2b9005c9 100644 --- a/providers/atlassian/go.sum +++ b/providers/atlassian/go.sum @@ -260,8 +260,6 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.mondoo.com/cnquery v0.0.0-20231002111758-82a0179e7dbd h1:61ziiW1w0vR+004KFqgzp5JG8QlsS5NMnU4FkH2bjOk= -go.mondoo.com/cnquery v0.0.0-20231002111758-82a0179e7dbd/go.mod h1:CyLGmRezek/8PswuVkmSLLScZqpMbACwFqL21eGeyYU= go.mondoo.com/cnquery/v9 v9.0.1 h1:bbQ4ufIf2OluZlCPYz13JjsHuDav28kG3Lw2X4iOXlM= go.mondoo.com/cnquery/v9 v9.0.1/go.mod h1:z5QWUfNdvmjclRPcXjZBQID2/o2ivYiRCF8+3HE6dLc= go.mondoo.com/ranger-rpc v0.5.1 h1:OaVQntDJWDRgbc9nXBP4wOCR9h9Bij8LgHHs86IguGk= diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 29d835b15d..1b19db3447 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -70,7 +70,7 @@ atlassian.jira { // Jira users users() []atlassian.jira.user // Jira projects - projects() []atlassian.jira.projects + projects() []atlassian.jira.project } atlassian.jira.user @defaults("id") { @@ -87,9 +87,9 @@ atlassian.jira.user @defaults("id") { } atlassian.jira.project @defaults("id") { - // AccountID + // Project ID id string - // Name + // Project Name name string } diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index bf3a5bfec1..6d286f0860 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -207,7 +207,7 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ return (r.(*mqlAtlassianJira).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.jira.user"))) }, "atlassian.jira.projects": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianJira).GetProjects()).ToDataRes(types.Array(types.Resource("atlassian.jira.projects"))) + return (r.(*mqlAtlassianJira).GetProjects()).ToDataRes(types.Array(types.Resource("atlassian.jira.project"))) }, "atlassian.jira.user.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraUser).GetId()).ToDataRes(types.String) @@ -1114,7 +1114,12 @@ func createAtlassianJiraProject(runtime *plugin.Runtime, args map[string]*llx.Ra return res, err } - // to override __id implement: id() (string, error) + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } if runtime.HasRecording { args, err = runtime.ResourceFromRecording("atlassian.jira.project", res.__id) diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index 94356aee0e..b83f38fc84 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -68,7 +68,7 @@ func (a *mqlAtlassianJiraUser) groups() ([]interface{}, error) { func (a *mqlAtlassianJira) projects() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) jira := conn.Jira() - projects, response, err := jira.Group.Bulk(context.Background(), nil, 0, 1000) + projects, response, err := jira.Project.Search(context.Background(), nil, 0, 1000) if err != nil { log.Fatal().Err(err) } @@ -78,9 +78,9 @@ func (a *mqlAtlassianJira) projects() ([]interface{}, error) { res := []interface{}{} for _, project := range projects.Values { - mqlAtlassianJiraProject, err := CreateResource(a.MqlRuntime, "atlassian.jira.projects", + mqlAtlassianJiraProject, err := CreateResource(a.MqlRuntime, "atlassian.jira.project", map[string]*llx.RawData{ - "id": llx.StringData(project.GroupID), + "id": llx.StringData(project.ID), "name": llx.StringData(project.Name), }) if err != nil { @@ -98,3 +98,7 @@ func (a *mqlAtlassianJiraUser) id() (string, error) { func (a *mqlAtlassianJiraUserGroup) id() (string, error) { return a.Id.Data, nil } + +func (a *mqlAtlassianJiraProject) id() (string, error) { + return a.Id.Data, nil +} From bf996a9bebf2de6a60172a180f8a97375f432ac8 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 9 Oct 2023 08:58:07 +0200 Subject: [PATCH 24/90] add more field to jira project --- providers/atlassian/resources/atlassian.lr | 14 ++++ providers/atlassian/resources/atlassian.lr.go | 84 +++++++++++++++++++ .../resources/atlassian.lr.manifest.yaml | 7 ++ .../atlassian/resources/atlassian_jira.go | 11 ++- 4 files changed, 114 insertions(+), 2 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 1b19db3447..2d4ec4b7c0 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -91,6 +91,20 @@ atlassian.jira.project @defaults("id") { id string // Project Name name string + // UUID + uuid string + // Key + key string + // URL + url string + // Email + email string + // Private + private bool + // Deleted + deleted bool + // Archived + archived bool } atlassian.jira.user.group @defaults("id") { diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 6d286f0860..1a34cc4583 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -230,6 +230,27 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.jira.project.name": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraProject).GetName()).ToDataRes(types.String) }, + "atlassian.jira.project.uuid": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraProject).GetUuid()).ToDataRes(types.String) + }, + "atlassian.jira.project.key": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraProject).GetKey()).ToDataRes(types.String) + }, + "atlassian.jira.project.url": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraProject).GetUrl()).ToDataRes(types.String) + }, + "atlassian.jira.project.email": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraProject).GetEmail()).ToDataRes(types.String) + }, + "atlassian.jira.project.private": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraProject).GetPrivate()).ToDataRes(types.Bool) + }, + "atlassian.jira.project.deleted": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraProject).GetDeleted()).ToDataRes(types.Bool) + }, + "atlassian.jira.project.archived": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraProject).GetArchived()).ToDataRes(types.Bool) + }, "atlassian.jira.user.group.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraUserGroup).GetId()).ToDataRes(types.String) }, @@ -421,6 +442,34 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJiraProject).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.jira.project.uuid": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraProject).Uuid, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.jira.project.key": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraProject).Key, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.jira.project.url": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraProject).Url, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.jira.project.email": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraProject).Email, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.jira.project.private": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraProject).Private, ok = plugin.RawToTValue[bool](v.Value, v.Error) + return + }, + "atlassian.jira.project.deleted": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraProject).Deleted, ok = plugin.RawToTValue[bool](v.Value, v.Error) + return + }, + "atlassian.jira.project.archived": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraProject).Archived, ok = plugin.RawToTValue[bool](v.Value, v.Error) + return + }, "atlassian.jira.user.group.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianJiraUserGroup).__id, ok = v.Value.(string) return @@ -1101,6 +1150,13 @@ type mqlAtlassianJiraProject struct { // optional: if you define mqlAtlassianJiraProjectInternal it will be used here Id plugin.TValue[string] Name plugin.TValue[string] + Uuid plugin.TValue[string] + Key plugin.TValue[string] + Url plugin.TValue[string] + Email plugin.TValue[string] + Private plugin.TValue[bool] + Deleted plugin.TValue[bool] + Archived plugin.TValue[bool] } // createAtlassianJiraProject creates a new instance of this resource @@ -1148,6 +1204,34 @@ func (c *mqlAtlassianJiraProject) GetName() *plugin.TValue[string] { return &c.Name } +func (c *mqlAtlassianJiraProject) GetUuid() *plugin.TValue[string] { + return &c.Uuid +} + +func (c *mqlAtlassianJiraProject) GetKey() *plugin.TValue[string] { + return &c.Key +} + +func (c *mqlAtlassianJiraProject) GetUrl() *plugin.TValue[string] { + return &c.Url +} + +func (c *mqlAtlassianJiraProject) GetEmail() *plugin.TValue[string] { + return &c.Email +} + +func (c *mqlAtlassianJiraProject) GetPrivate() *plugin.TValue[bool] { + return &c.Private +} + +func (c *mqlAtlassianJiraProject) GetDeleted() *plugin.TValue[bool] { + return &c.Deleted +} + +func (c *mqlAtlassianJiraProject) GetArchived() *plugin.TValue[bool] { + return &c.Archived +} + // mqlAtlassianJiraUserGroup for the atlassian.jira.user.group resource type mqlAtlassianJiraUserGroup struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index ed39647809..54751a1c54 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -85,8 +85,15 @@ resources: min_mondoo_version: latest atlassian.jira.project: fields: + archived: {} + deleted: {} + email: {} id: {} + key: {} name: {} + private: {} + url: {} + uuid: {} min_mondoo_version: latest atlassian.jira.user: fields: diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index b83f38fc84..cca6cb44b8 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -80,8 +80,15 @@ func (a *mqlAtlassianJira) projects() ([]interface{}, error) { for _, project := range projects.Values { mqlAtlassianJiraProject, err := CreateResource(a.MqlRuntime, "atlassian.jira.project", map[string]*llx.RawData{ - "id": llx.StringData(project.ID), - "name": llx.StringData(project.Name), + "id": llx.StringData(project.ID), + "name": llx.StringData(project.Name), + "uuid": llx.StringData(project.UUID), + "key": llx.StringData(project.Key), + "url": llx.StringData(project.URL), + "email": llx.StringData(project.Email), + "private": llx.BoolData(project.IsPrivate), + "deleted": llx.BoolData(project.Deleted), + "archived": llx.BoolData(project.Archived), }) if err != nil { log.Fatal().Err(err) From db7bf6b302da8eeafe04a990feb168b612522cbb Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 9 Oct 2023 10:54:25 +0200 Subject: [PATCH 25/90] make scan work --- providers/atlassian/config/config.go | 12 ++++++++---- providers/atlassian/provider/provider.go | 5 +++++ providers/defaults.go | 12 ++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/providers/atlassian/config/config.go b/providers/atlassian/config/config.go index 4599ea3795..57dc121afa 100644 --- a/providers/atlassian/config/config.go +++ b/providers/atlassian/config/config.go @@ -1,11 +1,15 @@ package config -import "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin" +import ( + "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin" + "go.mondoo.com/cnquery/v9/providers/atlassian/provider" +) var Config = plugin.Provider{ - Name: "atlassian", - ID: "go.mondoo.com/cnquery/providers/atlassian", - Version: "9.0.0", + Name: "atlassian", + ID: "go.mondoo.com/cnquery/providers/atlassian", + Version: "9.0.0", + ConnectionTypes: []string{provider.DefaultConnectionType}, Connectors: []plugin.Connector{ { Name: "atlassian", diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index 4caeaddfbe..c84eef9701 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -12,6 +12,11 @@ import ( "go.mondoo.com/cnquery/v9/providers/atlassian/resources" ) +const ( + defaultConnection uint32 = 1 + DefaultConnectionType = "atlassian" +) + type Service struct { runtimes map[uint32]*plugin.Runtime lastConnectionID uint32 diff --git a/providers/defaults.go b/providers/defaults.go index 7b8d6f96f0..d682e5d96d 100644 --- a/providers/defaults.go +++ b/providers/defaults.go @@ -46,6 +46,18 @@ var DefaultProviders Providers = map[string]*Provider{ }, }, }, + "atlassian": { + Provider: &plugin.Provider{ + Name: "atlassian", + ConnectionTypes: []string{"atlassian"}, + Connectors: []plugin.Connector{ + { + Name: "atlassian", + Short: "atlassian cloud", + }, + }, + }, + }, "aws": { Provider: &plugin.Provider{ Name: "aws", From b2ab7c6e2e5c612c0b7c0892437062b72fee5794 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 9 Oct 2023 15:17:04 +0200 Subject: [PATCH 26/90] fix platform id --- providers/atlassian/provider/provider.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index c84eef9701..0ba4fa65e6 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -66,11 +66,17 @@ func (s *Service) Connect(req *plugin.ConnectReq, callback plugin.ProviderCallba } } + inventory := &inventory.Inventory{ + Spec: &inventory.InventorySpec{ + Assets: []*inventory.Asset{req.Asset}, + }, + } + return &plugin.ConnectRes{ Id: conn.ID(), Name: conn.Name(), Asset: req.Asset, - Inventory: nil, + Inventory: inventory, }, nil } @@ -134,8 +140,7 @@ func (s *Service) detect(asset *inventory.Asset, conn *connection.AtlassianConne Title: "Atlassian", } - // TODO: Add platform IDs - asset.PlatformIds = []string{"//platformid.api.mondoo.app/runtime/oci/"} + asset.PlatformIds = []string{"//platformid.api.mondoo.app/runtime/atlassian"} return nil } From 592c3ac6cd383ae411b3ed041dc694c23fd6de6d Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Tue, 10 Oct 2023 10:23:26 +0200 Subject: [PATCH 27/90] fix groups and add applicationRoles --- providers/atlassian/resources/atlassian.lr | 15 +- providers/atlassian/resources/atlassian.lr.go | 149 +++++++++++++++--- .../resources/atlassian.lr.manifest.yaml | 18 +++ .../atlassian/resources/atlassian_jira.go | 36 ++++- 4 files changed, 192 insertions(+), 26 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 2d4ec4b7c0..7158f7cba7 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -83,7 +83,16 @@ atlassian.jira.user @defaults("id") { // Picture of the user picture string // Groups - groups() []atlassian.jira.user.group + groups() []atlassian.jira.group + // Roles + applicationRoles() []atlassian.jira.applicatonRole +} + +atlassian.jira.applicatonRole @defaults("id") { + // Role ID + id string + // Role Name + name string } atlassian.jira.project @defaults("id") { @@ -107,9 +116,11 @@ atlassian.jira.project @defaults("id") { archived bool } -atlassian.jira.user.group @defaults("id") { +atlassian.jira.group @defaults("id") { // GroupID id string + // Group Name + name string } atlassian.confluence { diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 1a34cc4583..9a994953c1 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -53,13 +53,17 @@ func init() { // to override args, implement: initAtlassianJiraUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianJiraUser, }, + "atlassian.jira.applicatonRole": { + // to override args, implement: initAtlassianJiraApplicatonRole(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianJiraApplicatonRole, + }, "atlassian.jira.project": { // to override args, implement: initAtlassianJiraProject(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianJiraProject, }, - "atlassian.jira.user.group": { - // to override args, implement: initAtlassianJiraUserGroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) - Create: createAtlassianJiraUserGroup, + "atlassian.jira.group": { + // to override args, implement: initAtlassianJiraGroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianJiraGroup, }, "atlassian.confluence": { // to override args, implement: initAtlassianConfluence(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) @@ -222,7 +226,16 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ return (r.(*mqlAtlassianJiraUser).GetPicture()).ToDataRes(types.String) }, "atlassian.jira.user.groups": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianJiraUser).GetGroups()).ToDataRes(types.Array(types.Resource("atlassian.jira.user.group"))) + return (r.(*mqlAtlassianJiraUser).GetGroups()).ToDataRes(types.Array(types.Resource("atlassian.jira.group"))) + }, + "atlassian.jira.user.applicationRoles": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraUser).GetApplicationRoles()).ToDataRes(types.Array(types.Resource("atlassian.jira.applicatonRole"))) + }, + "atlassian.jira.applicatonRole.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraApplicatonRole).GetId()).ToDataRes(types.String) + }, + "atlassian.jira.applicatonRole.name": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraApplicatonRole).GetName()).ToDataRes(types.String) }, "atlassian.jira.project.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraProject).GetId()).ToDataRes(types.String) @@ -251,8 +264,11 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.jira.project.archived": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraProject).GetArchived()).ToDataRes(types.Bool) }, - "atlassian.jira.user.group.id": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianJiraUserGroup).GetId()).ToDataRes(types.String) + "atlassian.jira.group.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraGroup).GetId()).ToDataRes(types.String) + }, + "atlassian.jira.group.name": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraGroup).GetName()).ToDataRes(types.String) }, "atlassian.confluence.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianConfluence).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.confluence.user"))) @@ -430,6 +446,22 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJiraUser).Groups, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "atlassian.jira.user.applicationRoles": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraUser).ApplicationRoles, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, + "atlassian.jira.applicatonRole.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraApplicatonRole).__id, ok = v.Value.(string) + return + }, + "atlassian.jira.applicatonRole.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraApplicatonRole).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.jira.applicatonRole.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraApplicatonRole).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.jira.project.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianJiraProject).__id, ok = v.Value.(string) return @@ -470,12 +502,16 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJiraProject).Archived, ok = plugin.RawToTValue[bool](v.Value, v.Error) return }, - "atlassian.jira.user.group.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianJiraUserGroup).__id, ok = v.Value.(string) + "atlassian.jira.group.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraGroup).__id, ok = v.Value.(string) return }, - "atlassian.jira.user.group.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianJiraUserGroup).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + "atlassian.jira.group.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraGroup).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.jira.group.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraGroup).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, "atlassian.confluence.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { @@ -1072,6 +1108,7 @@ type mqlAtlassianJiraUser struct { Type plugin.TValue[string] Picture plugin.TValue[string] Groups plugin.TValue[[]interface{}] + ApplicationRoles plugin.TValue[[]interface{}] } // createAtlassianJiraUser creates a new instance of this resource @@ -1143,6 +1180,71 @@ func (c *mqlAtlassianJiraUser) GetGroups() *plugin.TValue[[]interface{}] { }) } +func (c *mqlAtlassianJiraUser) GetApplicationRoles() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.ApplicationRoles, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.jira.user", c.__id, "applicationRoles") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.applicationRoles() + }) +} + +// mqlAtlassianJiraApplicatonRole for the atlassian.jira.applicatonRole resource +type mqlAtlassianJiraApplicatonRole struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianJiraApplicatonRoleInternal it will be used here + Id plugin.TValue[string] + Name plugin.TValue[string] +} + +// createAtlassianJiraApplicatonRole creates a new instance of this resource +func createAtlassianJiraApplicatonRole(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianJiraApplicatonRole{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + // to override __id implement: id() (string, error) + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.jira.applicatonRole", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianJiraApplicatonRole) MqlName() string { + return "atlassian.jira.applicatonRole" +} + +func (c *mqlAtlassianJiraApplicatonRole) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianJiraApplicatonRole) GetId() *plugin.TValue[string] { + return &c.Id +} + +func (c *mqlAtlassianJiraApplicatonRole) GetName() *plugin.TValue[string] { + return &c.Name +} + // mqlAtlassianJiraProject for the atlassian.jira.project resource type mqlAtlassianJiraProject struct { MqlRuntime *plugin.Runtime @@ -1232,17 +1334,18 @@ func (c *mqlAtlassianJiraProject) GetArchived() *plugin.TValue[bool] { return &c.Archived } -// mqlAtlassianJiraUserGroup for the atlassian.jira.user.group resource -type mqlAtlassianJiraUserGroup struct { +// mqlAtlassianJiraGroup for the atlassian.jira.group resource +type mqlAtlassianJiraGroup struct { MqlRuntime *plugin.Runtime __id string - // optional: if you define mqlAtlassianJiraUserGroupInternal it will be used here + // optional: if you define mqlAtlassianJiraGroupInternal it will be used here Id plugin.TValue[string] + Name plugin.TValue[string] } -// createAtlassianJiraUserGroup creates a new instance of this resource -func createAtlassianJiraUserGroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { - res := &mqlAtlassianJiraUserGroup{ +// createAtlassianJiraGroup creates a new instance of this resource +func createAtlassianJiraGroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianJiraGroup{ MqlRuntime: runtime, } @@ -1259,7 +1362,7 @@ func createAtlassianJiraUserGroup(runtime *plugin.Runtime, args map[string]*llx. } if runtime.HasRecording { - args, err = runtime.ResourceFromRecording("atlassian.jira.user.group", res.__id) + args, err = runtime.ResourceFromRecording("atlassian.jira.group", res.__id) if err != nil || args == nil { return res, err } @@ -1269,18 +1372,22 @@ func createAtlassianJiraUserGroup(runtime *plugin.Runtime, args map[string]*llx. return res, nil } -func (c *mqlAtlassianJiraUserGroup) MqlName() string { - return "atlassian.jira.user.group" +func (c *mqlAtlassianJiraGroup) MqlName() string { + return "atlassian.jira.group" } -func (c *mqlAtlassianJiraUserGroup) MqlID() string { +func (c *mqlAtlassianJiraGroup) MqlID() string { return c.__id } -func (c *mqlAtlassianJiraUserGroup) GetId() *plugin.TValue[string] { +func (c *mqlAtlassianJiraGroup) GetId() *plugin.TValue[string] { return &c.Id } +func (c *mqlAtlassianJiraGroup) GetName() *plugin.TValue[string] { + return &c.Name +} + // mqlAtlassianConfluence for the atlassian.confluence resource type mqlAtlassianConfluence struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 54751a1c54..a8167fcc5b 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -79,6 +79,16 @@ resources: projects: {} users: {} min_mondoo_version: latest + atlassian.jira.applicatonRole: + fields: + id: {} + name: {} + min_mondoo_version: latest + atlassian.jira.group: + fields: + id: {} + name: {} + min_mondoo_version: latest atlassian.jira.groups: fields: id: {} @@ -97,10 +107,13 @@ resources: min_mondoo_version: latest atlassian.jira.user: fields: + applicationRoles: {} + applicatonRoles: {} groups: {} id: {} name: {} picture: {} + roles: {} type: {} min_mondoo_version: latest atlassian.jira.user.group: @@ -111,3 +124,8 @@ resources: fields: id: {} min_mondoo_version: latest + atlassian.jira.user.role: + fields: + id: {} + name: {} + min_mondoo_version: latest diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index cca6cb44b8..cdc5b3c152 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -2,6 +2,7 @@ package resources import ( "context" + "fmt" "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/llx" @@ -40,6 +41,34 @@ func (a *mqlAtlassianJira) users() ([]interface{}, error) { return res, nil } +func (a *mqlAtlassianJiraUser) applicationRoles() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + jira := conn.Jira() + expands := []string{"groups", "applicationRoles"} + user, response, err := jira.User.Get(context.Background(), a.Id.Data, expands) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + roles := user.ApplicationRoles + + res := []interface{}{} + for _, role := range roles.Items { + mqlAtlassianJiraUserRole, err := CreateResource(a.MqlRuntime, "atlassian.jira.applicationRole", + map[string]*llx.RawData{ + "id": llx.StringData(role.Key), + "name": llx.StringData(role.Name), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianJiraUserRole) + } + return res, nil +} + func (a *mqlAtlassianJiraUser) groups() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) jira := conn.Jira() @@ -53,9 +82,10 @@ func (a *mqlAtlassianJiraUser) groups() ([]interface{}, error) { res := []interface{}{} for _, group := range groups.Values { - mqlAtlassianJiraUserGroup, err := CreateResource(a.MqlRuntime, "atlassian.jira.user.group", + mqlAtlassianJiraUserGroup, err := CreateResource(a.MqlRuntime, "atlassian.jira.group", map[string]*llx.RawData{ - "id": llx.StringData(group.GroupID), + "id": llx.StringData(group.GroupID), + "name": llx.StringData(group.Name), }) if err != nil { log.Fatal().Err(err) @@ -102,7 +132,7 @@ func (a *mqlAtlassianJiraUser) id() (string, error) { return a.Id.Data, nil } -func (a *mqlAtlassianJiraUserGroup) id() (string, error) { +func (a *mqlAtlassianJiraGroup) id() (string, error) { return a.Id.Data, nil } From 009749184e09d98e058eaf9a5e1b7b58ece2bf96 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Tue, 10 Oct 2023 10:28:49 +0200 Subject: [PATCH 28/90] add platform --- providers/atlassian/connection/connection.go | 13 +++++----- providers/atlassian/connection/platform.go | 24 +++++++++++++++++++ .../atlassian/resources/atlassian_jira.go | 1 - 3 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 providers/atlassian/connection/platform.go diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index e69df0fbe5..826aa11f3f 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -12,12 +12,13 @@ import ( ) type AtlassianConnection struct { - id uint32 - Conf *inventory.Config - asset *inventory.Asset - admin *admin.Client - jira *v2.Client - confluece *confluence.Client + id uint32 + Conf *inventory.Config + asset *inventory.Asset + admin *admin.Client + jira *v2.Client + confluece *confluence.Client + PlatformOverride string // Add custom connection fields here } diff --git a/providers/atlassian/connection/platform.go b/providers/atlassian/connection/platform.go new file mode 100644 index 0000000000..1f95f4e13a --- /dev/null +++ b/providers/atlassian/connection/platform.go @@ -0,0 +1,24 @@ +package connection + +import "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" + +func (a *AtlassianConnection) PlatformInfo() *inventory.Platform { + return GetPlatformForObject(a.PlatformOverride) +} + +func GetPlatformForObject(platformName string) *inventory.Platform { + if platformName != "atlassian" && platformName != "" { + return &inventory.Platform{ + Name: platformName, + Title: "atlassian cloud", + Kind: "atlassian", + Runtime: "atlassian", + } + } + return &inventory.Platform{ + Name: "atlassian", + Title: "atlassian cloud", + Kind: "api", + Runtime: "atlassian", + } +} diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index cdc5b3c152..6a24d503cd 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -2,7 +2,6 @@ package resources import ( "context" - "fmt" "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/llx" From 1086cc1cfe1a3a95e22494a58cbb11607e7e0390 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 11 Oct 2023 08:37:26 +0200 Subject: [PATCH 29/90] groups and serverinfo --- providers/atlassian/resources/atlassian.lr | 16 ++ providers/atlassian/resources/atlassian.lr.go | 145 ++++++++++++++++++ .../resources/atlassian.lr.manifest.yaml | 9 ++ .../atlassian/resources/atlassian_jira.go | 53 +++++++ 4 files changed, 223 insertions(+) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 7158f7cba7..a3d6233720 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -71,6 +71,21 @@ atlassian.jira { users() []atlassian.jira.user // Jira projects projects() []atlassian.jira.project + // Jira groups + groups() []atlassian.jira.group + // Jira server info + serverInfo() atlassian.jira.serverInfo +} + +atlassian.jira.serverInfo @defaults("serverTitle") { + // baseUrl + baseUrl string + // buildNumber + buildNumber string + // serverTitle + serverTitle string + // deploymentType + deploymentType string } atlassian.jira.user @defaults("id") { @@ -88,6 +103,7 @@ atlassian.jira.user @defaults("id") { applicationRoles() []atlassian.jira.applicatonRole } + atlassian.jira.applicatonRole @defaults("id") { // Role ID id string diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 9a994953c1..2ed4782232 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -7,6 +7,7 @@ package resources import ( "errors" + "fmt" "go.mondoo.com/cnquery/v9/llx" "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin" @@ -49,6 +50,10 @@ func init() { // to override args, implement: initAtlassianJira(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianJira, }, + "atlassian.jira.serverInfo": { + // to override args, implement: initAtlassianJiraServerInfo(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianJiraServerInfo, + }, "atlassian.jira.user": { // to override args, implement: initAtlassianJiraUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianJiraUser, @@ -213,6 +218,24 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.jira.projects": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJira).GetProjects()).ToDataRes(types.Array(types.Resource("atlassian.jira.project"))) }, + "atlassian.jira.groups": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJira).GetGroups()).ToDataRes(types.Array(types.Resource("atlassian.jira.group"))) + }, + "atlassian.jira.serverInfo": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJira).GetServerInfo()).ToDataRes(types.Resource("atlassian.jira.serverInfo")) + }, + "atlassian.jira.serverInfo.baseUrl": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraServerInfo).GetBaseUrl()).ToDataRes(types.String) + }, + "atlassian.jira.serverInfo.buildNumber": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraServerInfo).GetBuildNumber()).ToDataRes(types.String) + }, + "atlassian.jira.serverInfo.serverTitle": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraServerInfo).GetServerTitle()).ToDataRes(types.String) + }, + "atlassian.jira.serverInfo.deploymentType": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraServerInfo).GetDeploymentType()).ToDataRes(types.String) + }, "atlassian.jira.user.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraUser).GetId()).ToDataRes(types.String) }, @@ -422,6 +445,34 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJira).Projects, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "atlassian.jira.groups": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJira).Groups, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, + "atlassian.jira.serverInfo": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJira).ServerInfo, ok = plugin.RawToTValue[*mqlAtlassianJiraServerInfo](v.Value, v.Error) + return + }, + "atlassian.jira.serverInfo.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraServerInfo).__id, ok = v.Value.(string) + return + }, + "atlassian.jira.serverInfo.baseUrl": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraServerInfo).BaseUrl, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.jira.serverInfo.buildNumber": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraServerInfo).BuildNumber, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.jira.serverInfo.serverTitle": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraServerInfo).ServerTitle, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.jira.serverInfo.deploymentType": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraServerInfo).DeploymentType, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.jira.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianJiraUser).__id, ok = v.Value.(string) return @@ -1027,6 +1078,8 @@ type mqlAtlassianJira struct { // optional: if you define mqlAtlassianJiraInternal it will be used here Users plugin.TValue[[]interface{}] Projects plugin.TValue[[]interface{}] + Groups plugin.TValue[[]interface{}] + ServerInfo plugin.TValue[*mqlAtlassianJiraServerInfo] } // createAtlassianJira creates a new instance of this resource @@ -1098,6 +1151,98 @@ func (c *mqlAtlassianJira) GetProjects() *plugin.TValue[[]interface{}] { }) } +func (c *mqlAtlassianJira) GetGroups() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Groups, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.jira", c.__id, "groups") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.groups() + }) +} + +func (c *mqlAtlassianJira) GetServerInfo() *plugin.TValue[*mqlAtlassianJiraServerInfo] { + fmt.Println("GetServerInfo") + return plugin.GetOrCompute[*mqlAtlassianJiraServerInfo](&c.ServerInfo, func() (*mqlAtlassianJiraServerInfo, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.jira", c.__id, "serverInfo") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.(*mqlAtlassianJiraServerInfo), nil + } + } + + return c.serverInfo() + }) +} + +// mqlAtlassianJiraServerInfo for the atlassian.jira.serverInfo resource +type mqlAtlassianJiraServerInfo struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianJiraServerInfoInternal it will be used here + BaseUrl plugin.TValue[string] + BuildNumber plugin.TValue[string] + ServerTitle plugin.TValue[string] + DeploymentType plugin.TValue[string] +} + +// createAtlassianJiraServerInfo creates a new instance of this resource +func createAtlassianJiraServerInfo(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianJiraServerInfo{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + // to override __id implement: id() (string, error) + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.jira.serverInfo", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianJiraServerInfo) MqlName() string { + return "atlassian.jira.serverInfo" +} + +func (c *mqlAtlassianJiraServerInfo) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianJiraServerInfo) GetBaseUrl() *plugin.TValue[string] { + return &c.BaseUrl +} + +func (c *mqlAtlassianJiraServerInfo) GetBuildNumber() *plugin.TValue[string] { + return &c.BuildNumber +} + +func (c *mqlAtlassianJiraServerInfo) GetServerTitle() *plugin.TValue[string] { + return &c.ServerTitle +} + +func (c *mqlAtlassianJiraServerInfo) GetDeploymentType() *plugin.TValue[string] { + return &c.DeploymentType +} + // mqlAtlassianJiraUser for the atlassian.jira.user resource type mqlAtlassianJiraUser struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index a8167fcc5b..7ad3be9df2 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -76,7 +76,9 @@ resources: min_mondoo_version: latest atlassian.jira: fields: + groups: {} projects: {} + serverInfo: {} users: {} min_mondoo_version: latest atlassian.jira.applicatonRole: @@ -105,6 +107,13 @@ resources: url: {} uuid: {} min_mondoo_version: latest + atlassian.jira.serverInfo: + fields: + baseUrl: {} + buildNumber: {} + deploymentType: {} + serverTitle: {} + min_mondoo_version: latest atlassian.jira.user: fields: applicationRoles: {} diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index 6a24d503cd..f506f75749 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -2,6 +2,7 @@ package resources import ( "context" + "fmt" "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/llx" @@ -94,6 +95,58 @@ func (a *mqlAtlassianJiraUser) groups() ([]interface{}, error) { return res, nil } +func (a *mqlAtlassianJira) groups() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + jira := conn.Jira() + groups, response, err := jira.Group.Bulk(context.Background(), nil, 0, 1000) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + + res := []interface{}{} + for _, group := range groups.Values { + mqlAtlassianJiraUserGroup, err := CreateResource(a.MqlRuntime, "atlassian.jira.group", + map[string]*llx.RawData{ + "id": llx.StringData(group.GroupID), + "name": llx.StringData(group.Name), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianJiraUserGroup) + } + return res, nil +} + +func (a *mqlAtlassianJira) serverInfo() (*mqlAtlassianJiraServerInfo, error) { + fmt.Println("Hello serverInfo") + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + jira := conn.Jira() + info, response, err := jira.Server.Info(context.Background()) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + fmt.Println(info.BaseURL) + fmt.Println(info.ServerTitle) + res, err := CreateResource(a.MqlRuntime, "atlassian.jira.serverInfo", + map[string]*llx.RawData{ + "baseUrl": llx.StringData(info.BaseURL), + "buildNumber": llx.IntData(int64(info.BuildNumber)), + "serverTitle": llx.StringData(info.ServerTitle), + "deploymentType": llx.StringData(info.DeploymentType), + }) + if err != nil { + log.Fatal().Err(err) + } + return res.(*mqlAtlassianJiraServerInfo), nil +} + func (a *mqlAtlassianJira) projects() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) jira := conn.Jira() From 81432935e5aa0449adf91820eb9cc078e937c800 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 11 Oct 2023 09:12:59 +0200 Subject: [PATCH 30/90] fix serverinfo --- providers/atlassian/resources/atlassian.lr | 4 +-- providers/atlassian/resources/atlassian.lr.go | 28 +++++++++---------- .../resources/atlassian.lr.manifest.yaml | 2 ++ .../atlassian/resources/atlassian_jira.go | 12 ++------ 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index a3d6233720..349076d2b6 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -74,14 +74,14 @@ atlassian.jira { // Jira groups groups() []atlassian.jira.group // Jira server info - serverInfo() atlassian.jira.serverInfo + serverInfos() atlassian.jira.serverInfo } atlassian.jira.serverInfo @defaults("serverTitle") { // baseUrl baseUrl string // buildNumber - buildNumber string + buildNumber int // serverTitle serverTitle string // deploymentType diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 2ed4782232..32a2ee283c 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -7,7 +7,6 @@ package resources import ( "errors" - "fmt" "go.mondoo.com/cnquery/v9/llx" "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin" @@ -221,14 +220,14 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.jira.groups": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJira).GetGroups()).ToDataRes(types.Array(types.Resource("atlassian.jira.group"))) }, - "atlassian.jira.serverInfo": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianJira).GetServerInfo()).ToDataRes(types.Resource("atlassian.jira.serverInfo")) + "atlassian.jira.serverInfos": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJira).GetServerInfos()).ToDataRes(types.Resource("atlassian.jira.serverInfo")) }, "atlassian.jira.serverInfo.baseUrl": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraServerInfo).GetBaseUrl()).ToDataRes(types.String) }, "atlassian.jira.serverInfo.buildNumber": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianJiraServerInfo).GetBuildNumber()).ToDataRes(types.String) + return (r.(*mqlAtlassianJiraServerInfo).GetBuildNumber()).ToDataRes(types.Int) }, "atlassian.jira.serverInfo.serverTitle": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraServerInfo).GetServerTitle()).ToDataRes(types.String) @@ -449,8 +448,8 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJira).Groups, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, - "atlassian.jira.serverInfo": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianJira).ServerInfo, ok = plugin.RawToTValue[*mqlAtlassianJiraServerInfo](v.Value, v.Error) + "atlassian.jira.serverInfos": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJira).ServerInfos, ok = plugin.RawToTValue[*mqlAtlassianJiraServerInfo](v.Value, v.Error) return }, "atlassian.jira.serverInfo.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { @@ -462,7 +461,7 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { return }, "atlassian.jira.serverInfo.buildNumber": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianJiraServerInfo).BuildNumber, ok = plugin.RawToTValue[string](v.Value, v.Error) + r.(*mqlAtlassianJiraServerInfo).BuildNumber, ok = plugin.RawToTValue[int64](v.Value, v.Error) return }, "atlassian.jira.serverInfo.serverTitle": func(r plugin.Resource, v *llx.RawData) (ok bool) { @@ -1079,7 +1078,7 @@ type mqlAtlassianJira struct { Users plugin.TValue[[]interface{}] Projects plugin.TValue[[]interface{}] Groups plugin.TValue[[]interface{}] - ServerInfo plugin.TValue[*mqlAtlassianJiraServerInfo] + ServerInfos plugin.TValue[*mqlAtlassianJiraServerInfo] } // createAtlassianJira creates a new instance of this resource @@ -1167,11 +1166,10 @@ func (c *mqlAtlassianJira) GetGroups() *plugin.TValue[[]interface{}] { }) } -func (c *mqlAtlassianJira) GetServerInfo() *plugin.TValue[*mqlAtlassianJiraServerInfo] { - fmt.Println("GetServerInfo") - return plugin.GetOrCompute[*mqlAtlassianJiraServerInfo](&c.ServerInfo, func() (*mqlAtlassianJiraServerInfo, error) { +func (c *mqlAtlassianJira) GetServerInfos() *plugin.TValue[*mqlAtlassianJiraServerInfo] { + return plugin.GetOrCompute[*mqlAtlassianJiraServerInfo](&c.ServerInfos, func() (*mqlAtlassianJiraServerInfo, error) { if c.MqlRuntime.HasRecording { - d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.jira", c.__id, "serverInfo") + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.jira", c.__id, "serverInfos") if err != nil { return nil, err } @@ -1180,7 +1178,7 @@ func (c *mqlAtlassianJira) GetServerInfo() *plugin.TValue[*mqlAtlassianJiraServe } } - return c.serverInfo() + return c.serverInfos() }) } @@ -1190,7 +1188,7 @@ type mqlAtlassianJiraServerInfo struct { __id string // optional: if you define mqlAtlassianJiraServerInfoInternal it will be used here BaseUrl plugin.TValue[string] - BuildNumber plugin.TValue[string] + BuildNumber plugin.TValue[int64] ServerTitle plugin.TValue[string] DeploymentType plugin.TValue[string] } @@ -1231,7 +1229,7 @@ func (c *mqlAtlassianJiraServerInfo) GetBaseUrl() *plugin.TValue[string] { return &c.BaseUrl } -func (c *mqlAtlassianJiraServerInfo) GetBuildNumber() *plugin.TValue[string] { +func (c *mqlAtlassianJiraServerInfo) GetBuildNumber() *plugin.TValue[int64] { return &c.BuildNumber } diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 7ad3be9df2..94201871b3 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -79,6 +79,8 @@ resources: groups: {} projects: {} serverInfo: {} + serverInfos: {} + serverinfo: {} users: {} min_mondoo_version: latest atlassian.jira.applicatonRole: diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index f506f75749..df72600d2c 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -121,8 +121,7 @@ func (a *mqlAtlassianJira) groups() ([]interface{}, error) { return res, nil } -func (a *mqlAtlassianJira) serverInfo() (*mqlAtlassianJiraServerInfo, error) { - fmt.Println("Hello serverInfo") +func (a *mqlAtlassianJira) serverInfos() (*mqlAtlassianJiraServerInfo, error) { conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) jira := conn.Jira() info, response, err := jira.Server.Info(context.Background()) @@ -132,19 +131,14 @@ func (a *mqlAtlassianJira) serverInfo() (*mqlAtlassianJiraServerInfo, error) { if response.Status != "200 OK" { log.Fatal().Msgf("Received response: %s\n", response.Status) } - fmt.Println(info.BaseURL) - fmt.Println(info.ServerTitle) res, err := CreateResource(a.MqlRuntime, "atlassian.jira.serverInfo", map[string]*llx.RawData{ "baseUrl": llx.StringData(info.BaseURL), - "buildNumber": llx.IntData(int64(info.BuildNumber)), "serverTitle": llx.StringData(info.ServerTitle), + "buildNumber": llx.IntData(int64(info.BuildNumber)), "deploymentType": llx.StringData(info.DeploymentType), }) - if err != nil { - log.Fatal().Err(err) - } - return res.(*mqlAtlassianJiraServerInfo), nil + return res.(*mqlAtlassianJiraServerInfo), err } func (a *mqlAtlassianJira) projects() ([]interface{}, error) { From 4f8e6a0d299be8f2715dac0f4fce2e3da50be224 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 11 Oct 2023 09:18:45 +0200 Subject: [PATCH 31/90] fixup --- providers/atlassian/resources/atlassian_jira.go | 1 - 1 file changed, 1 deletion(-) diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index df72600d2c..aafd886d62 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -2,7 +2,6 @@ package resources import ( "context" - "fmt" "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/llx" From 8589585ffaf40eddac14bf3b95fd9447dc46cb1b Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 11 Oct 2023 09:23:32 +0200 Subject: [PATCH 32/90] comments --- providers/atlassian/resources/atlassian.lr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 349076d2b6..7df24394bd 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -78,13 +78,13 @@ atlassian.jira { } atlassian.jira.serverInfo @defaults("serverTitle") { - // baseUrl + // BaseUrl baseUrl string - // buildNumber + // BuildNumber buildNumber int - // serverTitle + // ServerTitle serverTitle string - // deploymentType + // DeploymentType deploymentType string } From 376ab894e7e046050b589dd552d62a29c1160533 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 11 Oct 2023 11:34:42 +0200 Subject: [PATCH 33/90] atlassian admin users --- providers/atlassian/resources/atlassian.lr | 7 ++ providers/atlassian/resources/atlassian.lr.go | 95 ++++++++++++++++++- .../resources/atlassian.lr.manifest.yaml | 5 + .../atlassian/resources/atlassian_admin.go | 67 ++++++++++++- .../atlassian/resources/atlassian_jira.go | 31 ++++++ 5 files changed, 200 insertions(+), 5 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 7df24394bd..1154b27683 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -130,6 +130,13 @@ atlassian.jira.project @defaults("id") { deleted bool // Archived archived bool + // Properties + properties() []atlassian.jira.project.property +} + +atlassian.jira.project.property @defaults("id") { + // Property Key + id string } atlassian.jira.group @defaults("id") { diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 32a2ee283c..a869e7dcd2 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -65,6 +65,10 @@ func init() { // to override args, implement: initAtlassianJiraProject(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianJiraProject, }, + "atlassian.jira.project.property": { + // to override args, implement: initAtlassianJiraProjectProperty(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianJiraProjectProperty, + }, "atlassian.jira.group": { // to override args, implement: initAtlassianJiraGroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianJiraGroup, @@ -286,6 +290,12 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.jira.project.archived": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraProject).GetArchived()).ToDataRes(types.Bool) }, + "atlassian.jira.project.properties": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraProject).GetProperties()).ToDataRes(types.Array(types.Resource("atlassian.jira.project.property"))) + }, + "atlassian.jira.project.property.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraProjectProperty).GetId()).ToDataRes(types.String) + }, "atlassian.jira.group.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraGroup).GetId()).ToDataRes(types.String) }, @@ -552,6 +562,18 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJiraProject).Archived, ok = plugin.RawToTValue[bool](v.Value, v.Error) return }, + "atlassian.jira.project.properties": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraProject).Properties, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, + "atlassian.jira.project.property.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraProjectProperty).__id, ok = v.Value.(string) + return + }, + "atlassian.jira.project.property.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraProjectProperty).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.jira.group.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianJiraGroup).__id, ok = v.Value.(string) return @@ -1017,7 +1039,12 @@ func createAtlassianAdminOrganizationUser(runtime *plugin.Runtime, args map[stri return res, err } - // to override __id implement: id() (string, error) + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } if runtime.HasRecording { args, err = runtime.ResourceFromRecording("atlassian.admin.organization.user", res.__id) @@ -1402,6 +1429,7 @@ type mqlAtlassianJiraProject struct { Private plugin.TValue[bool] Deleted plugin.TValue[bool] Archived plugin.TValue[bool] + Properties plugin.TValue[[]interface{}] } // createAtlassianJiraProject creates a new instance of this resource @@ -1477,6 +1505,71 @@ func (c *mqlAtlassianJiraProject) GetArchived() *plugin.TValue[bool] { return &c.Archived } +func (c *mqlAtlassianJiraProject) GetProperties() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Properties, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.jira.project", c.__id, "properties") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.properties() + }) +} + +// mqlAtlassianJiraProjectProperty for the atlassian.jira.project.property resource +type mqlAtlassianJiraProjectProperty struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianJiraProjectPropertyInternal it will be used here + Id plugin.TValue[string] +} + +// createAtlassianJiraProjectProperty creates a new instance of this resource +func createAtlassianJiraProjectProperty(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianJiraProjectProperty{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.jira.project.property", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianJiraProjectProperty) MqlName() string { + return "atlassian.jira.project.property" +} + +func (c *mqlAtlassianJiraProjectProperty) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianJiraProjectProperty) GetId() *plugin.TValue[string] { + return &c.Id +} + // mqlAtlassianJiraGroup for the atlassian.jira.group resource type mqlAtlassianJiraGroup struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 94201871b3..793f3acd4b 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -106,9 +106,14 @@ resources: key: {} name: {} private: {} + properties: {} url: {} uuid: {} min_mondoo_version: latest + atlassian.jira.project.property: + fields: + id: {} + min_mondoo_version: latest atlassian.jira.serverInfo: fields: baseUrl: {} diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index 63d37ea6a3..127817340b 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -37,11 +37,65 @@ func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { return res, nil } +type atlassianUser struct { + AccountID string + Name string + Type string +} + func (a *mqlAtlassianAdminOrganization) users() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - admin := conn.Admin() - orgId := a.Id.Data - users, response, err := admin.Organization.Users(context.Background(), orgId, "") + + jira := conn.Jira() + confluence := conn.Confluence() + + jiraUsers, response, err := jira.User.Search.Do(context.Background(), "", " ", 0, 1000) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + + cql := "type = user" + confluenceUsers, response, err := confluence.Search.Users(context.Background(), cql, 0, 1000, nil) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + var atlassianUsers []atlassianUser + for _, jiraUser := range jiraUsers { + user := atlassianUser{ + AccountID: jiraUser.AccountID, + Name: jiraUser.DisplayName, + Type: jiraUser.AccountType, + } + atlassianUsers = append(atlassianUsers, user) + } + for _, confluenceUser := range confluenceUsers.Results { + user := atlassianUser{ + AccountID: confluenceUser.User.AccountID, + Name: confluenceUser.User.DisplayName, + Type: confluenceUser.User.AccountType, + } + atlassianUsers = append(atlassianUsers, user) + } + + //TODO: is there a better way to get unique users? + var uniqueAtlassianUsers []atlassianUser +loopMark: + for _, v := range atlassianUsers { + for i, u := range uniqueAtlassianUsers { + if v.AccountID == u.AccountID { + uniqueAtlassianUsers[i] = v + continue loopMark + } + } + uniqueAtlassianUsers = append(uniqueAtlassianUsers, v) + } + if err != nil { log.Fatal().Err(err) } @@ -49,11 +103,12 @@ func (a *mqlAtlassianAdminOrganization) users() ([]interface{}, error) { log.Fatal().Msgf("Received response: %s\n", response.Status) } res := []interface{}{} - for _, user := range users.Data { + for _, user := range uniqueAtlassianUsers { mqlAtlassianAdminUser, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.user", map[string]*llx.RawData{ "id": llx.StringData(user.AccountID), "name": llx.StringData(user.Name), + "type": llx.StringData(user.Type), }) if err != nil { log.Fatal().Err(err) @@ -63,6 +118,10 @@ func (a *mqlAtlassianAdminOrganization) users() ([]interface{}, error) { return res, nil } +func (a *mqlAtlassianAdminOrganizationUser) id() (string, error) { + return a.Id.Data, nil +} + func (a *mqlAtlassianAdminOrganization) policies() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) admin := conn.Admin() diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index aafd886d62..316cc55773 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -2,6 +2,7 @@ package resources import ( "context" + "fmt" "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/llx" @@ -173,6 +174,36 @@ func (a *mqlAtlassianJira) projects() ([]interface{}, error) { return res, nil } +func (a *mqlAtlassianJiraProject) properties() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + jira := conn.Jira() + properties, response, err := jira.Project.Property.Gets(context.Background(), a.Id.Data) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + + res := []interface{}{} + for _, property := range properties.Keys { + fmt.Println(property.Key) + mqlAtlassianJiraProjectProperty, err := CreateResource(a.MqlRuntime, "atlassian.jira.project.property", + map[string]*llx.RawData{ + "id": llx.StringData(property.Key), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianJiraProjectProperty) + } + return res, nil +} + +func (a *mqlAtlassianJiraProjectProperty) id() (string, error) { + return a.Id.Data, nil +} + func (a *mqlAtlassianJiraUser) id() (string, error) { return a.Id.Data, nil } From 5d321b77a194a840583e6af08e3ac79fdd291814 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 11 Oct 2023 11:48:45 +0200 Subject: [PATCH 34/90] last active --- providers/atlassian/resources/atlassian.lr | 7 +- providers/atlassian/resources/atlassian.lr.go | 81 +++++++++++++++++-- .../resources/atlassian.lr.manifest.yaml | 4 + .../atlassian/resources/atlassian_admin.go | 37 ++++++++- 4 files changed, 120 insertions(+), 9 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 1154b27683..59c822a7e8 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -50,6 +50,8 @@ atlassian.admin.organization.event @defaults("id") { atlassian.admin.organization.user { // Account ID id string + // Organization ID + orgId string // Account type type string // Account status @@ -63,7 +65,10 @@ atlassian.admin.organization.user { // Billable accessBillable bool // Time when the user was last active - lastActive string + lastActive() []atlassian.admin.organization.user.lastActive +} + +atlassian.admin.organization.user.lastActive { } atlassian.jira { diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index a869e7dcd2..c219a5f3a6 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -45,6 +45,10 @@ func init() { // to override args, implement: initAtlassianAdminOrganizationUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganizationUser, }, + "atlassian.admin.organization.user.lastActive": { + // to override args, implement: initAtlassianAdminOrganizationUserLastActive(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianAdminOrganizationUserLastActive, + }, "atlassian.jira": { // to override args, implement: initAtlassianJira(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianJira, @@ -194,6 +198,9 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.user.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationUser).GetId()).ToDataRes(types.String) }, + "atlassian.admin.organization.user.orgId": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationUser).GetOrgId()).ToDataRes(types.String) + }, "atlassian.admin.organization.user.type": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationUser).GetType()).ToDataRes(types.String) }, @@ -213,7 +220,7 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ return (r.(*mqlAtlassianAdminOrganizationUser).GetAccessBillable()).ToDataRes(types.Bool) }, "atlassian.admin.organization.user.lastActive": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationUser).GetLastActive()).ToDataRes(types.String) + return (r.(*mqlAtlassianAdminOrganizationUser).GetLastActive()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.user.lastActive"))) }, "atlassian.jira.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJira).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.jira.user"))) @@ -414,6 +421,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganizationUser).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.admin.organization.user.orgId": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationUser).OrgId, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.admin.organization.user.type": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganizationUser).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) return @@ -439,9 +450,13 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { return }, "atlassian.admin.organization.user.lastActive": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUser).LastActive, ok = plugin.RawToTValue[string](v.Value, v.Error) + r.(*mqlAtlassianAdminOrganizationUser).LastActive, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "atlassian.admin.organization.user.lastActive.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationUserLastActive).__id, ok = v.Value.(string) + return + }, "atlassian.jira.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianJira).__id, ok = v.Value.(string) return @@ -1019,13 +1034,14 @@ type mqlAtlassianAdminOrganizationUser struct { __id string // optional: if you define mqlAtlassianAdminOrganizationUserInternal it will be used here Id plugin.TValue[string] + OrgId plugin.TValue[string] Type plugin.TValue[string] Status plugin.TValue[string] Name plugin.TValue[string] Picture plugin.TValue[string] Email plugin.TValue[string] AccessBillable plugin.TValue[bool] - LastActive plugin.TValue[string] + LastActive plugin.TValue[[]interface{}] } // createAtlassianAdminOrganizationUser creates a new instance of this resource @@ -1069,6 +1085,10 @@ func (c *mqlAtlassianAdminOrganizationUser) GetId() *plugin.TValue[string] { return &c.Id } +func (c *mqlAtlassianAdminOrganizationUser) GetOrgId() *plugin.TValue[string] { + return &c.OrgId +} + func (c *mqlAtlassianAdminOrganizationUser) GetType() *plugin.TValue[string] { return &c.Type } @@ -1093,8 +1113,59 @@ func (c *mqlAtlassianAdminOrganizationUser) GetAccessBillable() *plugin.TValue[b return &c.AccessBillable } -func (c *mqlAtlassianAdminOrganizationUser) GetLastActive() *plugin.TValue[string] { - return &c.LastActive +func (c *mqlAtlassianAdminOrganizationUser) GetLastActive() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.LastActive, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization.user", c.__id, "lastActive") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.lastActive() + }) +} + +// mqlAtlassianAdminOrganizationUserLastActive for the atlassian.admin.organization.user.lastActive resource +type mqlAtlassianAdminOrganizationUserLastActive struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianAdminOrganizationUserLastActiveInternal it will be used here +} + +// createAtlassianAdminOrganizationUserLastActive creates a new instance of this resource +func createAtlassianAdminOrganizationUserLastActive(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianAdminOrganizationUserLastActive{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + // to override __id implement: id() (string, error) + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.admin.organization.user.lastActive", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianAdminOrganizationUserLastActive) MqlName() string { + return "atlassian.admin.organization.user.lastActive" +} + +func (c *mqlAtlassianAdminOrganizationUserLastActive) MqlID() string { + return c.__id } // mqlAtlassianJira for the atlassian.jira resource diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 793f3acd4b..688693b4d1 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -44,10 +44,14 @@ resources: id: {} lastActive: {} name: {} + orgId: {} picture: {} status: {} type: {} min_mondoo_version: latest + atlassian.admin.organization.user.lastActive: + fields: {} + min_mondoo_version: latest atlassian.admin.user: fields: accessBillable: {} diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index 127817340b..c5d36d1423 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -41,6 +41,7 @@ type atlassianUser struct { AccountID string Name string Type string + OrgID string } func (a *mqlAtlassianAdminOrganization) users() ([]interface{}, error) { @@ -71,6 +72,7 @@ func (a *mqlAtlassianAdminOrganization) users() ([]interface{}, error) { AccountID: jiraUser.AccountID, Name: jiraUser.DisplayName, Type: jiraUser.AccountType, + OrgID: a.Id.Data, } atlassianUsers = append(atlassianUsers, user) } @@ -79,6 +81,7 @@ func (a *mqlAtlassianAdminOrganization) users() ([]interface{}, error) { AccountID: confluenceUser.User.AccountID, Name: confluenceUser.User.DisplayName, Type: confluenceUser.User.AccountType, + OrgID: a.Id.Data, } atlassianUsers = append(atlassianUsers, user) } @@ -106,9 +109,10 @@ loopMark: for _, user := range uniqueAtlassianUsers { mqlAtlassianAdminUser, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.user", map[string]*llx.RawData{ - "id": llx.StringData(user.AccountID), - "name": llx.StringData(user.Name), - "type": llx.StringData(user.Type), + "id": llx.StringData(user.AccountID), + "name": llx.StringData(user.Name), + "type": llx.StringData(user.Type), + "orgId": llx.StringData(user.OrgID), }) if err != nil { log.Fatal().Err(err) @@ -118,6 +122,33 @@ loopMark: return res, nil } +func (a *mqlAtlassianAdminOrganizationUser) lastActive() ([]interface{}, error) { + //conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + //admin := conn.Admin() + //accountId := a.Id.Data + //organizations, response, err := admin.Organization.Directory.Activity(context.Background(), a.Id.Data) + //if err != nil { + // log.Fatal().Err(err) + //} + //if response.Status != "200 OK" { + // log.Fatal().Msgf("Received response: %s\n", response.Status) + //} + res := []interface{}{} + //for _, org := range organizations.Data { + // mqlAtlassianAdminOrg, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization", + // map[string]*llx.RawData{ + // "id": llx.StringData(org.ID), + // "type": llx.StringData(org.Type), + // }) + // if err != nil { + // log.Fatal().Err(err) + // } + // res = append(res, mqlAtlassianAdminOrg) + //} + return res, nil + +} + func (a *mqlAtlassianAdminOrganizationUser) id() (string, error) { return a.Id.Data, nil } From ff9bdfe7d3a331ed09d3a22526eb06ef409cd297 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Wed, 11 Oct 2023 17:08:19 +0200 Subject: [PATCH 35/90] last active --- providers/atlassian/resources/atlassian.lr | 8 ++++ providers/atlassian/resources/atlassian.lr.go | 48 +++++++++++++++++++ .../resources/atlassian.lr.manifest.yaml | 6 ++- .../atlassian/resources/atlassian_admin.go | 46 ++++++++++-------- 4 files changed, 86 insertions(+), 22 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 59c822a7e8..34f4b73d9f 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -69,6 +69,14 @@ atlassian.admin.organization.user { } atlassian.admin.organization.user.lastActive { + // ID + id string + // URL + url string + // Key + key string + // LastActive + lastActive string } atlassian.jira { diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index c219a5f3a6..ee7a7fdf9c 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -222,6 +222,18 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.user.lastActive": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationUser).GetLastActive()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.user.lastActive"))) }, + "atlassian.admin.organization.user.lastActive.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationUserLastActive).GetId()).ToDataRes(types.String) + }, + "atlassian.admin.organization.user.lastActive.url": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationUserLastActive).GetUrl()).ToDataRes(types.String) + }, + "atlassian.admin.organization.user.lastActive.key": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationUserLastActive).GetKey()).ToDataRes(types.String) + }, + "atlassian.admin.organization.user.lastActive.lastActive": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationUserLastActive).GetLastActive()).ToDataRes(types.String) + }, "atlassian.jira.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJira).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.jira.user"))) }, @@ -457,6 +469,22 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganizationUserLastActive).__id, ok = v.Value.(string) return }, + "atlassian.admin.organization.user.lastActive.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationUserLastActive).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.organization.user.lastActive.url": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationUserLastActive).Url, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.organization.user.lastActive.key": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationUserLastActive).Key, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.organization.user.lastActive.lastActive": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationUserLastActive).LastActive, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.jira.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianJira).__id, ok = v.Value.(string) return @@ -1134,6 +1162,10 @@ type mqlAtlassianAdminOrganizationUserLastActive struct { MqlRuntime *plugin.Runtime __id string // optional: if you define mqlAtlassianAdminOrganizationUserLastActiveInternal it will be used here + Id plugin.TValue[string] + Url plugin.TValue[string] + Key plugin.TValue[string] + LastActive plugin.TValue[string] } // createAtlassianAdminOrganizationUserLastActive creates a new instance of this resource @@ -1168,6 +1200,22 @@ func (c *mqlAtlassianAdminOrganizationUserLastActive) MqlID() string { return c.__id } +func (c *mqlAtlassianAdminOrganizationUserLastActive) GetId() *plugin.TValue[string] { + return &c.Id +} + +func (c *mqlAtlassianAdminOrganizationUserLastActive) GetUrl() *plugin.TValue[string] { + return &c.Url +} + +func (c *mqlAtlassianAdminOrganizationUserLastActive) GetKey() *plugin.TValue[string] { + return &c.Key +} + +func (c *mqlAtlassianAdminOrganizationUserLastActive) GetLastActive() *plugin.TValue[string] { + return &c.LastActive +} + // mqlAtlassianJira for the atlassian.jira resource type mqlAtlassianJira struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 688693b4d1..fd4bd59ec1 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -50,7 +50,11 @@ resources: type: {} min_mondoo_version: latest atlassian.admin.organization.user.lastActive: - fields: {} + fields: + id: {} + key: {} + lastActive: {} + url: {} min_mondoo_version: latest atlassian.admin.user: fields: diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index c5d36d1423..f840de0dea 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -123,28 +123,32 @@ loopMark: } func (a *mqlAtlassianAdminOrganizationUser) lastActive() ([]interface{}, error) { - //conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - //admin := conn.Admin() - //accountId := a.Id.Data - //organizations, response, err := admin.Organization.Directory.Activity(context.Background(), a.Id.Data) - //if err != nil { - // log.Fatal().Err(err) - //} - //if response.Status != "200 OK" { - // log.Fatal().Msgf("Received response: %s\n", response.Status) - //} + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + admin := conn.Admin() + accountId := a.Id.Data + orgId := a.OrgId.Data + lastActive, response, err := admin.Organization.Directory.Activity(context.Background(), orgId, accountId) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + res := []interface{}{} - //for _, org := range organizations.Data { - // mqlAtlassianAdminOrg, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization", - // map[string]*llx.RawData{ - // "id": llx.StringData(org.ID), - // "type": llx.StringData(org.Type), - // }) - // if err != nil { - // log.Fatal().Err(err) - // } - // res = append(res, mqlAtlassianAdminOrg) - //} + for _, access := range lastActive.Data.ProductAccess { + mqlAtlassianAdminUserLastActive, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.user.lastActive", + map[string]*llx.RawData{ + "id": llx.StringData(access.Id), + "url": llx.StringData(access.Url), + "key": llx.StringData(access.Key), + "lastActive": llx.StringData(access.LastActive), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianAdminUserLastActive) + } return res, nil } From f3648b4ded3e84094d362adbf41c1148d9aee810 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Thu, 12 Oct 2023 08:55:19 +0200 Subject: [PATCH 36/90] add ids to last active --- providers/atlassian/resources/atlassian.lr | 2 +- providers/atlassian/resources/atlassian.lr.go | 7 ++++++- providers/atlassian/resources/atlassian_admin.go | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 34f4b73d9f..3ff753a823 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -68,7 +68,7 @@ atlassian.admin.organization.user { lastActive() []atlassian.admin.organization.user.lastActive } -atlassian.admin.organization.user.lastActive { +atlassian.admin.organization.user.lastActive @defaults("id") { // ID id string // URL diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index ee7a7fdf9c..2f3c09de85 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -1179,7 +1179,12 @@ func createAtlassianAdminOrganizationUserLastActive(runtime *plugin.Runtime, arg return res, err } - // to override __id implement: id() (string, error) + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } if runtime.HasRecording { args, err = runtime.ResourceFromRecording("atlassian.admin.organization.user.lastActive", res.__id) diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index f840de0dea..a4a8d7bc55 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -153,6 +153,10 @@ func (a *mqlAtlassianAdminOrganizationUser) lastActive() ([]interface{}, error) } +func (a *mqlAtlassianAdminOrganizationUserLastActive) id() (string, error) { + return a.Id.Data, nil +} + func (a *mqlAtlassianAdminOrganizationUser) id() (string, error) { return a.Id.Data, nil } From d0414eb0157d9fa6a4e2ece3a00da588b2557250 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Thu, 12 Oct 2023 09:07:26 +0200 Subject: [PATCH 37/90] add issues --- providers/atlassian/resources/atlassian.lr | 7 ++ providers/atlassian/resources/atlassian.lr.go | 88 +++++++++++++++++++ .../resources/atlassian.lr.manifest.yaml | 5 ++ .../atlassian/resources/atlassian_jira.go | 33 +++++++ 4 files changed, 133 insertions(+) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 3ff753a823..2df9cfc7d6 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -85,11 +85,18 @@ atlassian.jira { // Jira projects projects() []atlassian.jira.project // Jira groups + issues() []atlassian.jira.issue + // Jira groups groups() []atlassian.jira.group // Jira server info serverInfos() atlassian.jira.serverInfo } +atlassian.jira.issue @defaults("id") { + // ID + id string +} + atlassian.jira.serverInfo @defaults("serverTitle") { // BaseUrl baseUrl string diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 2f3c09de85..f6ad1f604f 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -53,6 +53,10 @@ func init() { // to override args, implement: initAtlassianJira(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianJira, }, + "atlassian.jira.issue": { + // to override args, implement: initAtlassianJiraIssue(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianJiraIssue, + }, "atlassian.jira.serverInfo": { // to override args, implement: initAtlassianJiraServerInfo(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianJiraServerInfo, @@ -240,12 +244,18 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.jira.projects": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJira).GetProjects()).ToDataRes(types.Array(types.Resource("atlassian.jira.project"))) }, + "atlassian.jira.issues": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJira).GetIssues()).ToDataRes(types.Array(types.Resource("atlassian.jira.issue"))) + }, "atlassian.jira.groups": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJira).GetGroups()).ToDataRes(types.Array(types.Resource("atlassian.jira.group"))) }, "atlassian.jira.serverInfos": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJira).GetServerInfos()).ToDataRes(types.Resource("atlassian.jira.serverInfo")) }, + "atlassian.jira.issue.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraIssue).GetId()).ToDataRes(types.String) + }, "atlassian.jira.serverInfo.baseUrl": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraServerInfo).GetBaseUrl()).ToDataRes(types.String) }, @@ -497,6 +507,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJira).Projects, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "atlassian.jira.issues": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJira).Issues, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, "atlassian.jira.groups": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianJira).Groups, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return @@ -505,6 +519,14 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJira).ServerInfos, ok = plugin.RawToTValue[*mqlAtlassianJiraServerInfo](v.Value, v.Error) return }, + "atlassian.jira.issue.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraIssue).__id, ok = v.Value.(string) + return + }, + "atlassian.jira.issue.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraIssue).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.jira.serverInfo.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianJiraServerInfo).__id, ok = v.Value.(string) return @@ -1228,6 +1250,7 @@ type mqlAtlassianJira struct { // optional: if you define mqlAtlassianJiraInternal it will be used here Users plugin.TValue[[]interface{}] Projects plugin.TValue[[]interface{}] + Issues plugin.TValue[[]interface{}] Groups plugin.TValue[[]interface{}] ServerInfos plugin.TValue[*mqlAtlassianJiraServerInfo] } @@ -1301,6 +1324,22 @@ func (c *mqlAtlassianJira) GetProjects() *plugin.TValue[[]interface{}] { }) } +func (c *mqlAtlassianJira) GetIssues() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Issues, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.jira", c.__id, "issues") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.issues() + }) +} + func (c *mqlAtlassianJira) GetGroups() *plugin.TValue[[]interface{}] { return plugin.GetOrCompute[[]interface{}](&c.Groups, func() ([]interface{}, error) { if c.MqlRuntime.HasRecording { @@ -1333,6 +1372,55 @@ func (c *mqlAtlassianJira) GetServerInfos() *plugin.TValue[*mqlAtlassianJiraServ }) } +// mqlAtlassianJiraIssue for the atlassian.jira.issue resource +type mqlAtlassianJiraIssue struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianJiraIssueInternal it will be used here + Id plugin.TValue[string] +} + +// createAtlassianJiraIssue creates a new instance of this resource +func createAtlassianJiraIssue(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianJiraIssue{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.jira.issue", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianJiraIssue) MqlName() string { + return "atlassian.jira.issue" +} + +func (c *mqlAtlassianJiraIssue) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianJiraIssue) GetId() *plugin.TValue[string] { + return &c.Id +} + // mqlAtlassianJiraServerInfo for the atlassian.jira.serverInfo resource type mqlAtlassianJiraServerInfo struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index fd4bd59ec1..52e729e8d3 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -85,6 +85,7 @@ resources: atlassian.jira: fields: groups: {} + issues: {} projects: {} serverInfo: {} serverInfos: {} @@ -105,6 +106,10 @@ resources: fields: id: {} min_mondoo_version: latest + atlassian.jira.issue: + fields: + id: {} + min_mondoo_version: latest atlassian.jira.project: fields: archived: {} diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index 316cc55773..d5d3fbe33b 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -174,6 +174,39 @@ func (a *mqlAtlassianJira) projects() ([]interface{}, error) { return res, nil } +func (a *mqlAtlassianJira) issues() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + jira := conn.Jira() + validate := "" + jql := "order by created DESC" + fields := []string{"status"} + expands := []string{"changelog", "renderedFields", "names", "schema", "transitions", "operations", "editmeta"} + issues, response, err := jira.Issue.Search.Get(context.Background(), jql, fields, expands, 0, 1000, validate) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + + res := []interface{}{} + for _, issue := range issues.Issues { + mqlAtlassianJiraIssue, err := CreateResource(a.MqlRuntime, "atlassian.jira.issue", + map[string]*llx.RawData{ + "id": llx.StringData(issue.ID), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianJiraIssue) + } + return res, nil +} + +func (a *mqlAtlassianJiraIssue) id() (string, error) { + return a.Id.Data, nil +} + func (a *mqlAtlassianJiraProject) properties() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) jira := conn.Jira() From 05a8404b127e8f016c17fa742b0339617bf79d5c Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Thu, 12 Oct 2023 09:14:57 +0200 Subject: [PATCH 38/90] add fields to issue --- providers/atlassian/resources/atlassian.lr | 4 ++++ providers/atlassian/resources/atlassian.lr.go | 24 +++++++++++++++++++ .../resources/atlassian.lr.manifest.yaml | 2 ++ .../atlassian/resources/atlassian_jira.go | 6 +++-- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 2df9cfc7d6..fe9f459615 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -95,6 +95,10 @@ atlassian.jira { atlassian.jira.issue @defaults("id") { // ID id string + // Project + project string + // Status + status string } atlassian.jira.serverInfo @defaults("serverTitle") { diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index f6ad1f604f..3fdf06d3ae 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -256,6 +256,12 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.jira.issue.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraIssue).GetId()).ToDataRes(types.String) }, + "atlassian.jira.issue.project": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraIssue).GetProject()).ToDataRes(types.String) + }, + "atlassian.jira.issue.status": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraIssue).GetStatus()).ToDataRes(types.String) + }, "atlassian.jira.serverInfo.baseUrl": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraServerInfo).GetBaseUrl()).ToDataRes(types.String) }, @@ -527,6 +533,14 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJiraIssue).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.jira.issue.project": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraIssue).Project, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.jira.issue.status": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraIssue).Status, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.jira.serverInfo.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianJiraServerInfo).__id, ok = v.Value.(string) return @@ -1378,6 +1392,8 @@ type mqlAtlassianJiraIssue struct { __id string // optional: if you define mqlAtlassianJiraIssueInternal it will be used here Id plugin.TValue[string] + Project plugin.TValue[string] + Status plugin.TValue[string] } // createAtlassianJiraIssue creates a new instance of this resource @@ -1421,6 +1437,14 @@ func (c *mqlAtlassianJiraIssue) GetId() *plugin.TValue[string] { return &c.Id } +func (c *mqlAtlassianJiraIssue) GetProject() *plugin.TValue[string] { + return &c.Project +} + +func (c *mqlAtlassianJiraIssue) GetStatus() *plugin.TValue[string] { + return &c.Status +} + // mqlAtlassianJiraServerInfo for the atlassian.jira.serverInfo resource type mqlAtlassianJiraServerInfo struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 52e729e8d3..5cb98cb140 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -109,6 +109,8 @@ resources: atlassian.jira.issue: fields: id: {} + project: {} + status: {} min_mondoo_version: latest atlassian.jira.project: fields: diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index d5d3fbe33b..81eb99a5a9 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -179,7 +179,7 @@ func (a *mqlAtlassianJira) issues() ([]interface{}, error) { jira := conn.Jira() validate := "" jql := "order by created DESC" - fields := []string{"status"} + fields := []string{"status", "project"} expands := []string{"changelog", "renderedFields", "names", "schema", "transitions", "operations", "editmeta"} issues, response, err := jira.Issue.Search.Get(context.Background(), jql, fields, expands, 0, 1000, validate) if err != nil { @@ -193,7 +193,9 @@ func (a *mqlAtlassianJira) issues() ([]interface{}, error) { for _, issue := range issues.Issues { mqlAtlassianJiraIssue, err := CreateResource(a.MqlRuntime, "atlassian.jira.issue", map[string]*llx.RawData{ - "id": llx.StringData(issue.ID), + "id": llx.StringData(issue.ID), + "project": llx.StringData(issue.Fields.Project.Name), + "status": llx.StringData(issue.Fields.Status.Name), }) if err != nil { log.Fatal().Err(err) From 635df0248e79fa839f97943ccfebf8862ece5231 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Thu, 12 Oct 2023 11:44:43 +0200 Subject: [PATCH 39/90] clean up --- providers/atlassian/connection/connection.go | 13 ++++++------- providers/atlassian/connection/platform.go | 8 ++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index 826aa11f3f..e69df0fbe5 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -12,13 +12,12 @@ import ( ) type AtlassianConnection struct { - id uint32 - Conf *inventory.Config - asset *inventory.Asset - admin *admin.Client - jira *v2.Client - confluece *confluence.Client - PlatformOverride string + id uint32 + Conf *inventory.Config + asset *inventory.Asset + admin *admin.Client + jira *v2.Client + confluece *confluence.Client // Add custom connection fields here } diff --git a/providers/atlassian/connection/platform.go b/providers/atlassian/connection/platform.go index 1f95f4e13a..c99f1ae7d9 100644 --- a/providers/atlassian/connection/platform.go +++ b/providers/atlassian/connection/platform.go @@ -3,21 +3,21 @@ package connection import "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" func (a *AtlassianConnection) PlatformInfo() *inventory.Platform { - return GetPlatformForObject(a.PlatformOverride) + return GetPlatformForObject("atlassian") } func GetPlatformForObject(platformName string) *inventory.Platform { if platformName != "atlassian" && platformName != "" { return &inventory.Platform{ Name: platformName, - Title: "atlassian cloud", - Kind: "atlassian", + Title: "atlassian", + Kind: "api", Runtime: "atlassian", } } return &inventory.Platform{ Name: "atlassian", - Title: "atlassian cloud", + Title: "atlassian", Kind: "api", Runtime: "atlassian", } From 0ee78a4049492e78f3d92695f7bb95025bea9cdd Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Thu, 12 Oct 2023 15:36:56 +0200 Subject: [PATCH 40/90] fix asset name and add scim --- providers/atlassian/connection/connection.go | 2 + providers/atlassian/provider/provider.go | 11 +- providers/atlassian/resources/atlassian.lr | 12 ++ providers/atlassian/resources/atlassian.lr.go | 154 ++++++++++++++++++ .../resources/atlassian.lr.manifest.yaml | 9 + .../atlassian/resources/atlassian_admin.go | 33 ++++ 6 files changed, 212 insertions(+), 9 deletions(-) diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index e69df0fbe5..783e821dd1 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -18,6 +18,7 @@ type AtlassianConnection struct { admin *admin.Client jira *v2.Client confluece *confluence.Client + Host string // Add custom connection fields here } @@ -51,6 +52,7 @@ func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.C conn := &AtlassianConnection{ Conf: conf, + Host: host, id: id, asset: asset, admin: admin, diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index 0ba4fa65e6..89b01bd3de 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -129,17 +129,10 @@ func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallba } func (s *Service) detect(asset *inventory.Asset, conn *connection.AtlassianConnection) error { - // TODO: adjust asset detection asset.Id = conn.Conf.Type - asset.Name = conn.Conf.Host - - asset.Platform = &inventory.Platform{ - Name: "atlassian", - Family: []string{"atlassian"}, - Kind: "api", - Title: "Atlassian", - } + asset.Name = conn.Host + asset.Platform = conn.PlatformInfo() asset.PlatformIds = []string{"//platformid.api.mondoo.app/runtime/atlassian"} return nil } diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index fe9f459615..abfb0a4242 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -22,6 +22,18 @@ atlassian.admin.organization @defaults("id") { domains() []atlassian.admin.organization.domain // Events events() []atlassian.admin.organization.event + // SCIM + scim() atlassian.admin.organization.scim +} + +atlassian.admin.organization.scim { + // SCIM users + users() []atlassian.admin.organization.scim.user +} + +atlassian.admin.organization.scim.user { + // ID + id string } atlassian.admin.organization.policy @defaults("id") { diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 3fdf06d3ae..be95b63f6f 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -29,6 +29,14 @@ func init() { // to override args, implement: initAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganization, }, + "atlassian.admin.organization.scim": { + // to override args, implement: initAtlassianAdminOrganizationScim(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianAdminOrganizationScim, + }, + "atlassian.admin.organization.scim.user": { + // to override args, implement: initAtlassianAdminOrganizationScimUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianAdminOrganizationScimUser, + }, "atlassian.admin.organization.policy": { // to override args, implement: initAtlassianAdminOrganizationPolicy(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganizationPolicy, @@ -178,6 +186,15 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.events": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganization).GetEvents()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.event"))) }, + "atlassian.admin.organization.scim": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganization).GetScim()).ToDataRes(types.Resource("atlassian.admin.organization.scim")) + }, + "atlassian.admin.organization.scim.users": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationScim).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.scim.user"))) + }, + "atlassian.admin.organization.scim.user.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationScimUser).GetId()).ToDataRes(types.String) + }, "atlassian.admin.organization.policy.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationPolicy).GetId()).ToDataRes(types.String) }, @@ -401,6 +418,26 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganization).Events, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "atlassian.admin.organization.scim": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganization).Scim, ok = plugin.RawToTValue[*mqlAtlassianAdminOrganizationScim](v.Value, v.Error) + return + }, + "atlassian.admin.organization.scim.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationScim).__id, ok = v.Value.(string) + return + }, + "atlassian.admin.organization.scim.users": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationScim).Users, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, + "atlassian.admin.organization.scim.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationScimUser).__id, ok = v.Value.(string) + return + }, + "atlassian.admin.organization.scim.user.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationScimUser).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.admin.organization.policy.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganizationPolicy).__id, ok = v.Value.(string) return @@ -829,6 +866,7 @@ type mqlAtlassianAdminOrganization struct { Policies plugin.TValue[[]interface{}] Domains plugin.TValue[[]interface{}] Events plugin.TValue[[]interface{}] + Scim plugin.TValue[*mqlAtlassianAdminOrganizationScim] } // createAtlassianAdminOrganization creates a new instance of this resource @@ -935,6 +973,122 @@ func (c *mqlAtlassianAdminOrganization) GetEvents() *plugin.TValue[[]interface{} }) } +func (c *mqlAtlassianAdminOrganization) GetScim() *plugin.TValue[*mqlAtlassianAdminOrganizationScim] { + return plugin.GetOrCompute[*mqlAtlassianAdminOrganizationScim](&c.Scim, func() (*mqlAtlassianAdminOrganizationScim, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization", c.__id, "scim") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.(*mqlAtlassianAdminOrganizationScim), nil + } + } + + return c.scim() + }) +} + +// mqlAtlassianAdminOrganizationScim for the atlassian.admin.organization.scim resource +type mqlAtlassianAdminOrganizationScim struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianAdminOrganizationScimInternal it will be used here + Users plugin.TValue[[]interface{}] +} + +// createAtlassianAdminOrganizationScim creates a new instance of this resource +func createAtlassianAdminOrganizationScim(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianAdminOrganizationScim{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + // to override __id implement: id() (string, error) + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.admin.organization.scim", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianAdminOrganizationScim) MqlName() string { + return "atlassian.admin.organization.scim" +} + +func (c *mqlAtlassianAdminOrganizationScim) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianAdminOrganizationScim) GetUsers() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Users, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization.scim", c.__id, "users") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.users() + }) +} + +// mqlAtlassianAdminOrganizationScimUser for the atlassian.admin.organization.scim.user resource +type mqlAtlassianAdminOrganizationScimUser struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianAdminOrganizationScimUserInternal it will be used here + Id plugin.TValue[string] +} + +// createAtlassianAdminOrganizationScimUser creates a new instance of this resource +func createAtlassianAdminOrganizationScimUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianAdminOrganizationScimUser{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + // to override __id implement: id() (string, error) + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.admin.organization.scim.user", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianAdminOrganizationScimUser) MqlName() string { + return "atlassian.admin.organization.scim.user" +} + +func (c *mqlAtlassianAdminOrganizationScimUser) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianAdminOrganizationScimUser) GetId() *plugin.TValue[string] { + return &c.Id +} + // mqlAtlassianAdminOrganizationPolicy for the atlassian.admin.organization.policy resource type mqlAtlassianAdminOrganizationPolicy struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 5cb98cb140..e986a479ef 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -18,6 +18,7 @@ resources: events: {} id: {} policies: {} + scim: {} type: {} users: {} min_mondoo_version: latest @@ -37,6 +38,14 @@ resources: status: {} type: {} min_mondoo_version: latest + atlassian.admin.organization.scim: + fields: + users: {} + min_mondoo_version: latest + atlassian.admin.organization.scim.user: + fields: + id: {} + min_mondoo_version: latest atlassian.admin.organization.user: fields: accessBillable: {} diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index a4a8d7bc55..e50a762142 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -37,6 +37,39 @@ func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { return res, nil } +func (a *mqlAtlassianAdminOrganization) scim() (*mqlAtlassianAdminOrganizationScim, error) { + mqlAtlassianAdminSCIM, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.scim", + map[string]*llx.RawData{}) + if err != nil { + log.Fatal().Err(err) + } + return mqlAtlassianAdminSCIM.(*mqlAtlassianAdminOrganizationScim), nil +} + +func (a *mqlAtlassianAdminOrganizationScim) users() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + admin := conn.Admin() + scimUsers, response, err := admin.SCIM.User.Gets(context.Background(), "786d6a74-k7b3-14jk-7863-5b83a48k8c43", nil, 0, 1000) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + res := []interface{}{} + for _, scimUser := range scimUsers.Resources { + mqlAtlassianAdminSCIMuser, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.scim.user", + map[string]*llx.RawData{ + "id": llx.StringData(scimUser.ID), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianAdminSCIMuser) + } + return res, nil +} + type atlassianUser struct { AccountID string Name string From e10758be4225560320f51a74365cc8401c37780c Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Thu, 12 Oct 2023 16:41:21 +0200 Subject: [PATCH 41/90] scim groups --- providers/atlassian/resources/atlassian.lr | 9 +- providers/atlassian/resources/atlassian.lr.go | 95 ++++++++++++++++++- .../resources/atlassian.lr.manifest.yaml | 5 + .../atlassian/resources/atlassian_admin.go | 32 +++++++ 4 files changed, 139 insertions(+), 2 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index abfb0a4242..b563a38f20 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -29,9 +29,16 @@ atlassian.admin.organization @defaults("id") { atlassian.admin.organization.scim { // SCIM users users() []atlassian.admin.organization.scim.user + // SCIM groups + groups() []atlassian.admin.organization.scim.group } -atlassian.admin.organization.scim.user { +atlassian.admin.organization.scim.user @defaults("id") { + // ID + id string +} + +atlassian.admin.organization.scim.group @defaults("id") { // ID id string } diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index be95b63f6f..846ef65abc 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -37,6 +37,10 @@ func init() { // to override args, implement: initAtlassianAdminOrganizationScimUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganizationScimUser, }, + "atlassian.admin.organization.scim.group": { + // to override args, implement: initAtlassianAdminOrganizationScimGroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianAdminOrganizationScimGroup, + }, "atlassian.admin.organization.policy": { // to override args, implement: initAtlassianAdminOrganizationPolicy(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganizationPolicy, @@ -192,9 +196,15 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.scim.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationScim).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.scim.user"))) }, + "atlassian.admin.organization.scim.groups": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationScim).GetGroups()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.scim.group"))) + }, "atlassian.admin.organization.scim.user.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationScimUser).GetId()).ToDataRes(types.String) }, + "atlassian.admin.organization.scim.group.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationScimGroup).GetId()).ToDataRes(types.String) + }, "atlassian.admin.organization.policy.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationPolicy).GetId()).ToDataRes(types.String) }, @@ -430,6 +440,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganizationScim).Users, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "atlassian.admin.organization.scim.groups": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationScim).Groups, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, "atlassian.admin.organization.scim.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganizationScimUser).__id, ok = v.Value.(string) return @@ -438,6 +452,14 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganizationScimUser).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.admin.organization.scim.group.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationScimGroup).__id, ok = v.Value.(string) + return + }, + "atlassian.admin.organization.scim.group.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationScimGroup).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.admin.organization.policy.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganizationPolicy).__id, ok = v.Value.(string) return @@ -995,6 +1017,7 @@ type mqlAtlassianAdminOrganizationScim struct { __id string // optional: if you define mqlAtlassianAdminOrganizationScimInternal it will be used here Users plugin.TValue[[]interface{}] + Groups plugin.TValue[[]interface{}] } // createAtlassianAdminOrganizationScim creates a new instance of this resource @@ -1045,6 +1068,22 @@ func (c *mqlAtlassianAdminOrganizationScim) GetUsers() *plugin.TValue[[]interfac }) } +func (c *mqlAtlassianAdminOrganizationScim) GetGroups() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Groups, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization.scim", c.__id, "groups") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.groups() + }) +} + // mqlAtlassianAdminOrganizationScimUser for the atlassian.admin.organization.scim.user resource type mqlAtlassianAdminOrganizationScimUser struct { MqlRuntime *plugin.Runtime @@ -1064,7 +1103,12 @@ func createAtlassianAdminOrganizationScimUser(runtime *plugin.Runtime, args map[ return res, err } - // to override __id implement: id() (string, error) + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } if runtime.HasRecording { args, err = runtime.ResourceFromRecording("atlassian.admin.organization.scim.user", res.__id) @@ -1089,6 +1133,55 @@ func (c *mqlAtlassianAdminOrganizationScimUser) GetId() *plugin.TValue[string] { return &c.Id } +// mqlAtlassianAdminOrganizationScimGroup for the atlassian.admin.organization.scim.group resource +type mqlAtlassianAdminOrganizationScimGroup struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianAdminOrganizationScimGroupInternal it will be used here + Id plugin.TValue[string] +} + +// createAtlassianAdminOrganizationScimGroup creates a new instance of this resource +func createAtlassianAdminOrganizationScimGroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianAdminOrganizationScimGroup{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.admin.organization.scim.group", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianAdminOrganizationScimGroup) MqlName() string { + return "atlassian.admin.organization.scim.group" +} + +func (c *mqlAtlassianAdminOrganizationScimGroup) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianAdminOrganizationScimGroup) GetId() *plugin.TValue[string] { + return &c.Id +} + // mqlAtlassianAdminOrganizationPolicy for the atlassian.admin.organization.policy resource type mqlAtlassianAdminOrganizationPolicy struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index e986a479ef..23f32eaf22 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -40,8 +40,13 @@ resources: min_mondoo_version: latest atlassian.admin.organization.scim: fields: + groups: {} users: {} min_mondoo_version: latest + atlassian.admin.organization.scim.group: + fields: + id: {} + min_mondoo_version: latest atlassian.admin.organization.scim.user: fields: id: {} diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index e50a762142..81e8b9594a 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -70,6 +70,38 @@ func (a *mqlAtlassianAdminOrganizationScim) users() ([]interface{}, error) { return res, nil } +func (a *mqlAtlassianAdminOrganizationScim) groups() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + admin := conn.Admin() + scimGroup, response, err := admin.SCIM.Group.Gets(context.Background(), "786d6a74-k7b3-14jk-7863-5b83a48k8c43", "", 0, 1000) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + res := []interface{}{} + for _, scimGroup := range scimGroup.Resources { + mqlAtlassianAdminSCIMgroup, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.scim.group", + map[string]*llx.RawData{ + "id": llx.StringData(scimGroup.ID), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianAdminSCIMgroup) + } + return res, nil +} + +func (a *mqlAtlassianAdminOrganizationScimUser) id() (string, error) { + return a.Id.Data, nil +} + +func (a *mqlAtlassianAdminOrganizationScimGroup) id() (string, error) { + return a.Id.Data, nil +} + type atlassianUser struct { AccountID string Name string From fe063fa1b9676fc457c9aa084851e03fece09218 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Fri, 13 Oct 2023 07:25:52 +0200 Subject: [PATCH 42/90] managed users --- providers/atlassian/resources/atlassian.lr | 11 ++ providers/atlassian/resources/atlassian.lr.go | 107 ++++++++++++++++++ .../resources/atlassian.lr.manifest.yaml | 7 ++ .../atlassian/resources/atlassian_admin.go | 28 +++++ 4 files changed, 153 insertions(+) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index b563a38f20..effbec8e93 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -24,6 +24,17 @@ atlassian.admin.organization @defaults("id") { events() []atlassian.admin.organization.event // SCIM scim() atlassian.admin.organization.scim + // Managed Users + managedUsers() []atlassian.admin.organization.managedUsers +} + +atlassian.admin.organization.managedUsers { + // ID + id string + // Name + name string + // Type + type string } atlassian.admin.organization.scim { diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 846ef65abc..8a8fb9d473 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -29,6 +29,10 @@ func init() { // to override args, implement: initAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganization, }, + "atlassian.admin.organization.managedUsers": { + // to override args, implement: initAtlassianAdminOrganizationManagedUsers(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianAdminOrganizationManagedUsers, + }, "atlassian.admin.organization.scim": { // to override args, implement: initAtlassianAdminOrganizationScim(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganizationScim, @@ -193,6 +197,18 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.scim": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganization).GetScim()).ToDataRes(types.Resource("atlassian.admin.organization.scim")) }, + "atlassian.admin.organization.managedUsers": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganization).GetManagedUsers()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.managedUsers"))) + }, + "atlassian.admin.organization.managedUsers.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationManagedUsers).GetId()).ToDataRes(types.String) + }, + "atlassian.admin.organization.managedUsers.name": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationManagedUsers).GetName()).ToDataRes(types.String) + }, + "atlassian.admin.organization.managedUsers.type": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationManagedUsers).GetType()).ToDataRes(types.String) + }, "atlassian.admin.organization.scim.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationScim).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.scim.user"))) }, @@ -432,6 +448,26 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganization).Scim, ok = plugin.RawToTValue[*mqlAtlassianAdminOrganizationScim](v.Value, v.Error) return }, + "atlassian.admin.organization.managedUsers": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganization).ManagedUsers, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, + "atlassian.admin.organization.managedUsers.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationManagedUsers).__id, ok = v.Value.(string) + return + }, + "atlassian.admin.organization.managedUsers.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationManagedUsers).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.organization.managedUsers.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationManagedUsers).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.organization.managedUsers.type": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationManagedUsers).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.admin.organization.scim.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganizationScim).__id, ok = v.Value.(string) return @@ -889,6 +925,7 @@ type mqlAtlassianAdminOrganization struct { Domains plugin.TValue[[]interface{}] Events plugin.TValue[[]interface{}] Scim plugin.TValue[*mqlAtlassianAdminOrganizationScim] + ManagedUsers plugin.TValue[[]interface{}] } // createAtlassianAdminOrganization creates a new instance of this resource @@ -1011,6 +1048,76 @@ func (c *mqlAtlassianAdminOrganization) GetScim() *plugin.TValue[*mqlAtlassianAd }) } +func (c *mqlAtlassianAdminOrganization) GetManagedUsers() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.ManagedUsers, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization", c.__id, "managedUsers") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } + } + + return c.managedUsers() + }) +} + +// mqlAtlassianAdminOrganizationManagedUsers for the atlassian.admin.organization.managedUsers resource +type mqlAtlassianAdminOrganizationManagedUsers struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianAdminOrganizationManagedUsersInternal it will be used here + Id plugin.TValue[string] + Name plugin.TValue[string] + Type plugin.TValue[string] +} + +// createAtlassianAdminOrganizationManagedUsers creates a new instance of this resource +func createAtlassianAdminOrganizationManagedUsers(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianAdminOrganizationManagedUsers{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + // to override __id implement: id() (string, error) + + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.admin.organization.managedUsers", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil +} + +func (c *mqlAtlassianAdminOrganizationManagedUsers) MqlName() string { + return "atlassian.admin.organization.managedUsers" +} + +func (c *mqlAtlassianAdminOrganizationManagedUsers) MqlID() string { + return c.__id +} + +func (c *mqlAtlassianAdminOrganizationManagedUsers) GetId() *plugin.TValue[string] { + return &c.Id +} + +func (c *mqlAtlassianAdminOrganizationManagedUsers) GetName() *plugin.TValue[string] { + return &c.Name +} + +func (c *mqlAtlassianAdminOrganizationManagedUsers) GetType() *plugin.TValue[string] { + return &c.Type +} + // mqlAtlassianAdminOrganizationScim for the atlassian.admin.organization.scim resource type mqlAtlassianAdminOrganizationScim struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 23f32eaf22..4dbb5ac8da 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -17,6 +17,7 @@ resources: domains: {} events: {} id: {} + managedUsers: {} policies: {} scim: {} type: {} @@ -30,6 +31,12 @@ resources: fields: id: {} min_mondoo_version: latest + atlassian.admin.organization.managedUsers: + fields: + id: {} + name: {} + type: {} + min_mondoo_version: latest atlassian.admin.organization.policy: fields: id: {} diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index 81e8b9594a..740fa60fd3 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -109,6 +109,34 @@ type atlassianUser struct { OrgID string } +func (a *mqlAtlassianAdminOrganization) managedUsers() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + + admin := conn.Admin() + + managedUsers, response, err := admin.Organization.Users(context.Background(), a.Id.Data, "") + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + res := []interface{}{} + for _, user := range managedUsers.Data { + mqlAtlassianAdminManagedUser, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.managedUser", + map[string]*llx.RawData{ + "id": llx.StringData(user.AccountID), + "name": llx.StringData(user.Name), + "type": llx.StringData(user.AccountType), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianAdminManagedUser) + } + return res, nil +} + func (a *mqlAtlassianAdminOrganization) users() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) From fe2f1b6f239af4d08bdfe65666bba7c2c6f301d6 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Fri, 13 Oct 2023 09:05:59 +0200 Subject: [PATCH 43/90] better naming + error handling --- providers/atlassian/connection/connection.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index 783e821dd1..b060186b7f 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -1,6 +1,7 @@ package connection import ( + "errors" "os" "github.com/ctreminiom/go-atlassian/admin" @@ -23,7 +24,12 @@ type AtlassianConnection struct { } func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AtlassianConnection, error) { - apiKey := os.Getenv("ATLASSIAN_KEY") + apiKey := os.Getenv("ATLASSIAN_ADMIN_TOKEN") + + if apiKey == "" { + return nil, errors.New("you need to provide atlassian admin token e.g. via ATLASSIAN_ADMIN_TOKEN env") + } + token := os.Getenv("ATLASSIAN_TOKEN") host := "https://lunalectric.atlassian.net" mail := "marius@mondoo.com" @@ -39,6 +45,7 @@ func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.C log.Fatal().Err(err) } + //jira.Auth.SetBearerToken(apiKey) jira.Auth.SetBasicAuth(mail, token) jira.Auth.SetUserAgent("curl/7.54.0") @@ -47,6 +54,7 @@ func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.C log.Fatal().Err(err) } + //confluence.Auth.SetBearerToken(apiKey) confluence.Auth.SetBasicAuth(mail, token) confluence.Auth.SetUserAgent("curl/7.54.0") From 2fe64af32afd8d1c8497f72d0e7c16c5218321fb Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Fri, 13 Oct 2023 09:17:06 +0200 Subject: [PATCH 44/90] remove hardcoded host and user --- providers/atlassian/connection/connection.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index b060186b7f..8b6c60654a 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -25,14 +25,21 @@ type AtlassianConnection struct { func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AtlassianConnection, error) { apiKey := os.Getenv("ATLASSIAN_ADMIN_TOKEN") - if apiKey == "" { - return nil, errors.New("you need to provide atlassian admin token e.g. via ATLASSIAN_ADMIN_TOKEN env") + return nil, errors.New("you need to provide atlassian admin token via ATLASSIAN_ADMIN_TOKEN env") + } + + host := os.Getenv("ATLASSIAN_HOST") + if host == "" { + log.Warn().Msg("ATLASSIAN_HOST not set") + } + + mail := os.Getenv("ATLASSIAN_USER") + if mail == "" { + log.Warn().Msg("ATLASSIAN_USER not set") } token := os.Getenv("ATLASSIAN_TOKEN") - host := "https://lunalectric.atlassian.net" - mail := "marius@mondoo.com" admin, err := admin.New(nil) if err != nil { log.Fatal().Err(err) From beee2fea2bf98f6f33879118119cadb763c19c63 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Fri, 13 Oct 2023 12:49:22 +0200 Subject: [PATCH 45/90] split --- .../atlassian/connection/admin/connection.go | 72 ++++++++++++ .../connection/{ => admin}/platform.go | 2 +- .../connection/confluence/connection.go | 88 +++++++++++++++ .../connection/confluence/platform.go | 24 ++++ providers/atlassian/connection/connection.go | 103 ------------------ .../atlassian/connection/jira/connection.go | 88 +++++++++++++++ .../atlassian/connection/jira/platform.go | 24 ++++ .../atlassian/connection/scim/connection.go | 72 ++++++++++++ .../atlassian/connection/scim/platform.go | 24 ++++ .../atlassian/connection/shared/shared.go | 17 +++ 10 files changed, 410 insertions(+), 104 deletions(-) create mode 100644 providers/atlassian/connection/admin/connection.go rename providers/atlassian/connection/{ => admin}/platform.go (88%) create mode 100644 providers/atlassian/connection/confluence/connection.go create mode 100644 providers/atlassian/connection/confluence/platform.go delete mode 100644 providers/atlassian/connection/connection.go create mode 100644 providers/atlassian/connection/jira/connection.go create mode 100644 providers/atlassian/connection/jira/platform.go create mode 100644 providers/atlassian/connection/scim/connection.go create mode 100644 providers/atlassian/connection/scim/platform.go create mode 100644 providers/atlassian/connection/shared/shared.go diff --git a/providers/atlassian/connection/admin/connection.go b/providers/atlassian/connection/admin/connection.go new file mode 100644 index 0000000000..95e0cdcd8e --- /dev/null +++ b/providers/atlassian/connection/admin/connection.go @@ -0,0 +1,72 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +package connection + +import ( + "errors" + "os" + + "github.com/ctreminiom/go-atlassian/admin" + "github.com/rs/zerolog/log" + "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/shared" +) + +const ( + Admin shared.ConnectionType = "admin" +) + +type AdminConnection struct { + id uint32 + Conf *inventory.Config + asset *inventory.Asset + client *admin.Client +} + +func NewAdminConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AdminConnection, error) { + adminToken := conf.Options["admintoken"] + if adminToken == "" { + adminToken = os.Getenv("ATLASSIAN_ADMIN_TOKEN") + } + if adminToken == "" { + return nil, errors.New("you need to provide atlassian admin token via ATLASSIAN_ADMIN_TOKEN env") + } + + client, err := admin.New(nil) + if err != nil { + log.Fatal().Err(err) + } + + client.Auth.SetBearerToken(adminToken) + client.Auth.SetUserAgent("curl/7.54.0") + + conn := &AdminConnection{ + Conf: conf, + id: id, + asset: asset, + client: client, + } + + return conn, nil +} + +func (c *AdminConnection) Name() string { + return "atlassian" +} + +func (c *AdminConnection) ID() uint32 { + return c.id +} + +func (c *AdminConnection) Asset() *inventory.Asset { + return c.asset +} + +func (c *AdminConnection) Client() *admin.Client { + return c.client +} + +func (p *AdminConnection) Type() shared.ConnectionType { + return Admin +} diff --git a/providers/atlassian/connection/platform.go b/providers/atlassian/connection/admin/platform.go similarity index 88% rename from providers/atlassian/connection/platform.go rename to providers/atlassian/connection/admin/platform.go index c99f1ae7d9..38b8057657 100644 --- a/providers/atlassian/connection/platform.go +++ b/providers/atlassian/connection/admin/platform.go @@ -2,7 +2,7 @@ package connection import "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" -func (a *AtlassianConnection) PlatformInfo() *inventory.Platform { +func (a *AdminConnection) PlatformInfo() *inventory.Platform { return GetPlatformForObject("atlassian") } diff --git a/providers/atlassian/connection/confluence/connection.go b/providers/atlassian/connection/confluence/connection.go new file mode 100644 index 0000000000..48762d44d1 --- /dev/null +++ b/providers/atlassian/connection/confluence/connection.go @@ -0,0 +1,88 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +package connection + +import ( + "errors" + "os" + + "github.com/ctreminiom/go-atlassian/confluence" + "github.com/rs/zerolog/log" + "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/shared" +) + +const ( + Confluence shared.ConnectionType = "confluece" +) + +type ConfluenceConnection struct { + id uint32 + Conf *inventory.Config + asset *inventory.Asset + client *confluence.Client +} + +func NewConfluenceConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*ConfluenceConnection, error) { + host := conf.Options["host"] + if host == "" { + host = os.Getenv("ATLASSIAN_HOST") + } + if host == "" { + return nil, errors.New("you need to provide atlassian hostname via ATLASSIAN_HOST env") + } + + user := conf.Options["user"] + if user == "" { + user = os.Getenv("ATLASSIAN_USER") + } + if user == "" { + return nil, errors.New("you need to provide atlassian username via ATLASSIAN_USER env") + } + + token := conf.Options["usertoken"] + if token == "" { + token = os.Getenv("ATLASSIAN_USER_TOKEN") + } + if token == "" { + return nil, errors.New("you need to provide atlassian user token via ATLASSIAN_USER_TOKEN env") + } + + client, err := confluence.New(nil, host) + if err != nil { + log.Fatal().Err(err) + } + + client.Auth.SetBasicAuth(user, token) + client.Auth.SetUserAgent("curl/7.54.0") + + conn := &ConfluenceConnection{ + Conf: conf, + id: id, + asset: asset, + client: client, + } + + return conn, nil +} + +func (c *ConfluenceConnection) Name() string { + return "atlassian" +} + +func (c *ConfluenceConnection) ID() uint32 { + return c.id +} + +func (c *ConfluenceConnection) Asset() *inventory.Asset { + return c.asset +} + +func (c *ConfluenceConnection) Client() *confluence.Client { + return c.client +} + +func (p *ConfluenceConnection) Type() shared.ConnectionType { + return Confluence +} diff --git a/providers/atlassian/connection/confluence/platform.go b/providers/atlassian/connection/confluence/platform.go new file mode 100644 index 0000000000..287be2a2e3 --- /dev/null +++ b/providers/atlassian/connection/confluence/platform.go @@ -0,0 +1,24 @@ +package connection + +import "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" + +func (a *ConfluenceConnection) PlatformInfo() *inventory.Platform { + return GetPlatformForObject("atlassian") +} + +func GetPlatformForObject(platformName string) *inventory.Platform { + if platformName != "atlassian" && platformName != "" { + return &inventory.Platform{ + Name: platformName, + Title: "atlassian", + Kind: "api", + Runtime: "atlassian", + } + } + return &inventory.Platform{ + Name: "atlassian", + Title: "atlassian", + Kind: "api", + Runtime: "atlassian", + } +} diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go deleted file mode 100644 index 8b6c60654a..0000000000 --- a/providers/atlassian/connection/connection.go +++ /dev/null @@ -1,103 +0,0 @@ -package connection - -import ( - "errors" - "os" - - "github.com/ctreminiom/go-atlassian/admin" - "github.com/ctreminiom/go-atlassian/confluence" - "github.com/ctreminiom/go-atlassian/jira/v2" - _ "github.com/ctreminiom/go-atlassian/jira/v3" - "github.com/rs/zerolog/log" - "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" -) - -type AtlassianConnection struct { - id uint32 - Conf *inventory.Config - asset *inventory.Asset - admin *admin.Client - jira *v2.Client - confluece *confluence.Client - Host string - // Add custom connection fields here -} - -func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AtlassianConnection, error) { - apiKey := os.Getenv("ATLASSIAN_ADMIN_TOKEN") - if apiKey == "" { - return nil, errors.New("you need to provide atlassian admin token via ATLASSIAN_ADMIN_TOKEN env") - } - - host := os.Getenv("ATLASSIAN_HOST") - if host == "" { - log.Warn().Msg("ATLASSIAN_HOST not set") - } - - mail := os.Getenv("ATLASSIAN_USER") - if mail == "" { - log.Warn().Msg("ATLASSIAN_USER not set") - } - - token := os.Getenv("ATLASSIAN_TOKEN") - admin, err := admin.New(nil) - if err != nil { - log.Fatal().Err(err) - } - admin.Auth.SetBearerToken(apiKey) - admin.Auth.SetUserAgent("curl/7.54.0") - - jira, err := v2.New(nil, host) - if err != nil { - log.Fatal().Err(err) - } - - //jira.Auth.SetBearerToken(apiKey) - jira.Auth.SetBasicAuth(mail, token) - jira.Auth.SetUserAgent("curl/7.54.0") - - confluence, err := confluence.New(nil, host) - if err != nil { - log.Fatal().Err(err) - } - - //confluence.Auth.SetBearerToken(apiKey) - confluence.Auth.SetBasicAuth(mail, token) - confluence.Auth.SetUserAgent("curl/7.54.0") - - conn := &AtlassianConnection{ - Conf: conf, - Host: host, - id: id, - asset: asset, - admin: admin, - jira: jira, - confluece: confluence, - } - - return conn, nil -} - -func (c *AtlassianConnection) Name() string { - return "atlassian" -} - -func (c *AtlassianConnection) ID() uint32 { - return c.id -} - -func (c *AtlassianConnection) Asset() *inventory.Asset { - return c.asset -} - -func (c *AtlassianConnection) Admin() *admin.Client { - return c.admin -} - -func (c *AtlassianConnection) Jira() *v2.Client { - return c.jira -} - -func (c *AtlassianConnection) Confluence() *confluence.Client { - return c.confluece -} diff --git a/providers/atlassian/connection/jira/connection.go b/providers/atlassian/connection/jira/connection.go new file mode 100644 index 0000000000..db498ead78 --- /dev/null +++ b/providers/atlassian/connection/jira/connection.go @@ -0,0 +1,88 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +package connection + +import ( + "errors" + "os" + + v2 "github.com/ctreminiom/go-atlassian/jira/v2" + "github.com/rs/zerolog/log" + "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/shared" +) + +const ( + Jira shared.ConnectionType = "jira" +) + +type JiraConnection struct { + id uint32 + Conf *inventory.Config + asset *inventory.Asset + client *v2.Client +} + +func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*JiraConnection, error) { + host := conf.Options["host"] + if host == "" { + host = os.Getenv("ATLASSIAN_HOST") + } + if host == "" { + return nil, errors.New("you need to provide atlassian host via ATLASSIAN_HOST env") + } + + user := conf.Options["user"] + if user == "" { + user = os.Getenv("ATLASSIAN_USER") + } + if user == "" { + return nil, errors.New("you need to provide atlassian user via ATLASSIAN_USER env") + } + + userToken := conf.Options["usertoken"] + if userToken == "" { + userToken = os.Getenv("ATLASSIAN_USER_TOKEN") + } + if userToken == "" { + return nil, errors.New("you need to provide atlassian user token via ATLASSIAN_USER_TOKEN env") + } + + client, err := v2.New(nil, host) + if err != nil { + log.Fatal().Err(err) + } + + client.Auth.SetBasicAuth(user, userToken) + client.Auth.SetUserAgent("curl/7.54.0") + + conn := &JiraConnection{ + Conf: conf, + id: id, + asset: asset, + client: client, + } + + return conn, nil +} + +func (c *JiraConnection) Name() string { + return "jira" +} + +func (c *JiraConnection) ID() uint32 { + return c.id +} + +func (c *JiraConnection) Asset() *inventory.Asset { + return c.asset +} + +func (c *JiraConnection) Client() *v2.Client { + return c.client +} + +func (p *JiraConnection) Type() shared.ConnectionType { + return Jira +} diff --git a/providers/atlassian/connection/jira/platform.go b/providers/atlassian/connection/jira/platform.go new file mode 100644 index 0000000000..b10a51acf9 --- /dev/null +++ b/providers/atlassian/connection/jira/platform.go @@ -0,0 +1,24 @@ +package connection + +import "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" + +func (a *JiraConnection) PlatformInfo() *inventory.Platform { + return GetPlatformForObject("atlassian") +} + +func GetPlatformForObject(platformName string) *inventory.Platform { + if platformName != "atlassian" && platformName != "" { + return &inventory.Platform{ + Name: platformName, + Title: "atlassian", + Kind: "api", + Runtime: "atlassian", + } + } + return &inventory.Platform{ + Name: "atlassian", + Title: "atlassian", + Kind: "api", + Runtime: "atlassian", + } +} diff --git a/providers/atlassian/connection/scim/connection.go b/providers/atlassian/connection/scim/connection.go new file mode 100644 index 0000000000..5d56f3bdf7 --- /dev/null +++ b/providers/atlassian/connection/scim/connection.go @@ -0,0 +1,72 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +package connection + +import ( + "errors" + "os" + + "github.com/ctreminiom/go-atlassian/admin" + "github.com/rs/zerolog/log" + "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/shared" +) + +const ( + Scim shared.ConnectionType = "jira" +) + +type ScimConnection struct { + id uint32 + Conf *inventory.Config + asset *inventory.Asset + client *admin.Client +} + +func NewAdminConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*ScimConnection, error) { + token := conf.Options["token"] + if token == "" { + token = os.Getenv("ATLASSIAN_SCIM_TOKEN") + } + if token == "" { + return nil, errors.New("you need to provide atlassian admin token via ATLASSIAN_SCIM_TOKEN env") + } + + client, err := admin.New(nil) + if err != nil { + log.Fatal().Err(err) + } + + client.Auth.SetBearerToken(token) + client.Auth.SetUserAgent("curl/7.54.0") + + conn := &ScimConnection{ + Conf: conf, + id: id, + asset: asset, + client: client, + } + + return conn, nil +} + +func (c *ScimConnection) Name() string { + return "jira" +} + +func (c *ScimConnection) ID() uint32 { + return c.id +} + +func (c *ScimConnection) Asset() *inventory.Asset { + return c.asset +} + +func (c *ScimConnection) Client() *admin.Client { + return c.client +} + +func (p *ScimConnection) Type() shared.ConnectionType { + return Scim +} diff --git a/providers/atlassian/connection/scim/platform.go b/providers/atlassian/connection/scim/platform.go new file mode 100644 index 0000000000..abab9fd3b7 --- /dev/null +++ b/providers/atlassian/connection/scim/platform.go @@ -0,0 +1,24 @@ +package connection + +import "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" + +func (a *ScimConnection) PlatformInfo() *inventory.Platform { + return GetPlatformForObject("atlassian") +} + +func GetPlatformForObject(platformName string) *inventory.Platform { + if platformName != "atlassian" && platformName != "" { + return &inventory.Platform{ + Name: platformName, + Title: "atlassian", + Kind: "api", + Runtime: "atlassian", + } + } + return &inventory.Platform{ + Name: "atlassian", + Title: "atlassian", + Kind: "api", + Runtime: "atlassian", + } +} diff --git a/providers/atlassian/connection/shared/shared.go b/providers/atlassian/connection/shared/shared.go new file mode 100644 index 0000000000..147cac23b2 --- /dev/null +++ b/providers/atlassian/connection/shared/shared.go @@ -0,0 +1,17 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +package shared + +import ( + "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" +) + +type ConnectionType string + +type Connection interface { + ID() uint32 + Name() string + Type() ConnectionType + Asset() *inventory.Asset +} From 46f61893b09439fec7dfc10d9e4869068ff4642f Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Fri, 13 Oct 2023 13:04:14 +0200 Subject: [PATCH 46/90] fixes --- providers/atlassian/connection/admin/connection.go | 12 +++++++++--- providers/atlassian/connection/admin/platform.go | 2 +- .../atlassian/connection/confluence/connection.go | 12 +++++++++--- .../atlassian/connection/confluence/platform.go | 2 +- providers/atlassian/connection/jira/connection.go | 10 ++++++++-- providers/atlassian/connection/jira/platform.go | 2 +- providers/atlassian/connection/scim/connection.go | 10 ++++++++-- providers/atlassian/connection/scim/platform.go | 2 +- providers/atlassian/connection/shared/shared.go | 1 + providers/atlassian/provider/provider.go | 14 +++++++++----- 10 files changed, 48 insertions(+), 19 deletions(-) diff --git a/providers/atlassian/connection/admin/connection.go b/providers/atlassian/connection/admin/connection.go index 95e0cdcd8e..b558a5dd95 100644 --- a/providers/atlassian/connection/admin/connection.go +++ b/providers/atlassian/connection/admin/connection.go @@ -1,7 +1,7 @@ // Copyright (c) Mondoo, Inc. // SPDX-License-Identifier: BUSL-1.1 -package connection +package admin import ( "errors" @@ -22,9 +22,10 @@ type AdminConnection struct { Conf *inventory.Config asset *inventory.Asset client *admin.Client + host string } -func NewAdminConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AdminConnection, error) { +func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AdminConnection, error) { adminToken := conf.Options["admintoken"] if adminToken == "" { adminToken = os.Getenv("ATLASSIAN_ADMIN_TOKEN") @@ -46,6 +47,7 @@ func NewAdminConnection(id uint32, asset *inventory.Asset, conf *inventory.Confi id: id, asset: asset, client: client, + host: "admin.atlassian.com", } return conn, nil @@ -67,6 +69,10 @@ func (c *AdminConnection) Client() *admin.Client { return c.client } -func (p *AdminConnection) Type() shared.ConnectionType { +func (c *AdminConnection) Type() shared.ConnectionType { return Admin } + +func (c *AdminConnection) Host() string { + return c.host +} diff --git a/providers/atlassian/connection/admin/platform.go b/providers/atlassian/connection/admin/platform.go index 38b8057657..bee2a5387f 100644 --- a/providers/atlassian/connection/admin/platform.go +++ b/providers/atlassian/connection/admin/platform.go @@ -1,4 +1,4 @@ -package connection +package admin import "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" diff --git a/providers/atlassian/connection/confluence/connection.go b/providers/atlassian/connection/confluence/connection.go index 48762d44d1..194980dfe1 100644 --- a/providers/atlassian/connection/confluence/connection.go +++ b/providers/atlassian/connection/confluence/connection.go @@ -1,7 +1,7 @@ // Copyright (c) Mondoo, Inc. // SPDX-License-Identifier: BUSL-1.1 -package connection +package confluence import ( "errors" @@ -22,9 +22,10 @@ type ConfluenceConnection struct { Conf *inventory.Config asset *inventory.Asset client *confluence.Client + host string } -func NewConfluenceConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*ConfluenceConnection, error) { +func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*ConfluenceConnection, error) { host := conf.Options["host"] if host == "" { host = os.Getenv("ATLASSIAN_HOST") @@ -62,6 +63,7 @@ func NewConfluenceConnection(id uint32, asset *inventory.Asset, conf *inventory. id: id, asset: asset, client: client, + host: host, } return conn, nil @@ -83,6 +85,10 @@ func (c *ConfluenceConnection) Client() *confluence.Client { return c.client } -func (p *ConfluenceConnection) Type() shared.ConnectionType { +func (c *ConfluenceConnection) Type() shared.ConnectionType { return Confluence } + +func (c *ConfluenceConnection) Host() string { + return c.host +} diff --git a/providers/atlassian/connection/confluence/platform.go b/providers/atlassian/connection/confluence/platform.go index 287be2a2e3..b92c312885 100644 --- a/providers/atlassian/connection/confluence/platform.go +++ b/providers/atlassian/connection/confluence/platform.go @@ -1,4 +1,4 @@ -package connection +package confluence import "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" diff --git a/providers/atlassian/connection/jira/connection.go b/providers/atlassian/connection/jira/connection.go index db498ead78..7cdabb35be 100644 --- a/providers/atlassian/connection/jira/connection.go +++ b/providers/atlassian/connection/jira/connection.go @@ -1,7 +1,7 @@ // Copyright (c) Mondoo, Inc. // SPDX-License-Identifier: BUSL-1.1 -package connection +package jira import ( "errors" @@ -22,9 +22,10 @@ type JiraConnection struct { Conf *inventory.Config asset *inventory.Asset client *v2.Client + host string } -func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*JiraConnection, error) { +func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*JiraConnection, error) { host := conf.Options["host"] if host == "" { host = os.Getenv("ATLASSIAN_HOST") @@ -62,6 +63,7 @@ func NewAtlassianConnection(id uint32, asset *inventory.Asset, conf *inventory.C id: id, asset: asset, client: client, + host: host, } return conn, nil @@ -86,3 +88,7 @@ func (c *JiraConnection) Client() *v2.Client { func (p *JiraConnection) Type() shared.ConnectionType { return Jira } + +func (c *JiraConnection) Host() string { + return c.host +} diff --git a/providers/atlassian/connection/jira/platform.go b/providers/atlassian/connection/jira/platform.go index b10a51acf9..c1076ae647 100644 --- a/providers/atlassian/connection/jira/platform.go +++ b/providers/atlassian/connection/jira/platform.go @@ -1,4 +1,4 @@ -package connection +package jira import "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" diff --git a/providers/atlassian/connection/scim/connection.go b/providers/atlassian/connection/scim/connection.go index 5d56f3bdf7..c0b9b54fc1 100644 --- a/providers/atlassian/connection/scim/connection.go +++ b/providers/atlassian/connection/scim/connection.go @@ -1,7 +1,7 @@ // Copyright (c) Mondoo, Inc. // SPDX-License-Identifier: BUSL-1.1 -package connection +package scim import ( "errors" @@ -22,9 +22,10 @@ type ScimConnection struct { Conf *inventory.Config asset *inventory.Asset client *admin.Client + host string } -func NewAdminConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*ScimConnection, error) { +func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*ScimConnection, error) { token := conf.Options["token"] if token == "" { token = os.Getenv("ATLASSIAN_SCIM_TOKEN") @@ -46,6 +47,7 @@ func NewAdminConnection(id uint32, asset *inventory.Asset, conf *inventory.Confi id: id, asset: asset, client: client, + host: "admin.atlassian.com", } return conn, nil @@ -70,3 +72,7 @@ func (c *ScimConnection) Client() *admin.Client { func (p *ScimConnection) Type() shared.ConnectionType { return Scim } + +func (c *ScimConnection) Host() string { + return c.host +} diff --git a/providers/atlassian/connection/scim/platform.go b/providers/atlassian/connection/scim/platform.go index abab9fd3b7..e60a7a78d6 100644 --- a/providers/atlassian/connection/scim/platform.go +++ b/providers/atlassian/connection/scim/platform.go @@ -1,4 +1,4 @@ -package connection +package scim import "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" diff --git a/providers/atlassian/connection/shared/shared.go b/providers/atlassian/connection/shared/shared.go index 147cac23b2..faa1901a66 100644 --- a/providers/atlassian/connection/shared/shared.go +++ b/providers/atlassian/connection/shared/shared.go @@ -14,4 +14,5 @@ type Connection interface { Name() string Type() ConnectionType Asset() *inventory.Asset + Host() string } diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index 89b01bd3de..4fc8e9cd6d 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -8,7 +8,11 @@ import ( "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin" "go.mondoo.com/cnquery/v9/providers-sdk/v1/upstream" - "go.mondoo.com/cnquery/v9/providers/atlassian/connection" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/admin" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/confluence" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/jira" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/scim" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/shared" "go.mondoo.com/cnquery/v9/providers/atlassian/resources" ) @@ -87,20 +91,20 @@ func (s *Service) Shutdown(req *plugin.ShutdownReq) (*plugin.ShutdownRes, error) return &plugin.ShutdownRes{}, nil } -func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallback) (*connection.AtlassianConnection, error) { +func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallback) (shared.Connection, error) { if len(req.Asset.Connections) == 0 { return nil, errors.New("no connection options for asset") } asset := req.Asset conf := asset.Connections[0] - var conn *connection.AtlassianConnection + var conn shared.Connection var err error switch conf.Type { default: s.lastConnectionID++ - conn, err = connection.NewAtlassianConnection(s.lastConnectionID, asset, conf) + conn, err = admin.NewConnection(s.lastConnectionID, asset, conf) } if err != nil { @@ -128,7 +132,7 @@ func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallba return conn, err } -func (s *Service) detect(asset *inventory.Asset, conn *connection.AtlassianConnection) error { +func (s *Service) detect(asset *inventory.Asset, conn shared.Connection) error { asset.Id = conn.Conf.Type asset.Name = conn.Host From 48ef3474ace7f08ad176bc128642658bc7cc17bd Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Fri, 13 Oct 2023 13:22:53 +0200 Subject: [PATCH 47/90] fixes --- .../atlassian/connection/shared/shared.go | 1 + providers/atlassian/provider/provider.go | 16 +- providers/atlassian/resources/atlassian.lr | 32 -- providers/atlassian/resources/atlassian.lr.go | 296 ------------------ .../atlassian/resources/atlassian_admin.go | 147 +-------- .../resources/atlassian_confluence.go | 6 +- .../atlassian/resources/atlassian_jira.go | 34 +- 7 files changed, 50 insertions(+), 482 deletions(-) diff --git a/providers/atlassian/connection/shared/shared.go b/providers/atlassian/connection/shared/shared.go index faa1901a66..da81207b9b 100644 --- a/providers/atlassian/connection/shared/shared.go +++ b/providers/atlassian/connection/shared/shared.go @@ -15,4 +15,5 @@ type Connection interface { Type() ConnectionType Asset() *inventory.Asset Host() string + PlatformInfo() *inventory.Platform } diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index 4fc8e9cd6d..18daabb29e 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -102,6 +102,18 @@ func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallba var err error switch conf.Type { + case "admin": + s.lastConnectionID++ + conn, err = admin.NewConnection(s.lastConnectionID, asset, conf) + case "scim": + s.lastConnectionID++ + conn, err = scim.NewConnection(s.lastConnectionID, asset, conf) + case "jira": + s.lastConnectionID++ + conn, err = jira.NewConnection(s.lastConnectionID, asset, conf) + case "confluence": + s.lastConnectionID++ + conn, err = confluence.NewConnection(s.lastConnectionID, asset, conf) default: s.lastConnectionID++ conn, err = admin.NewConnection(s.lastConnectionID, asset, conf) @@ -133,8 +145,8 @@ func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallba } func (s *Service) detect(asset *inventory.Asset, conn shared.Connection) error { - asset.Id = conn.Conf.Type - asset.Name = conn.Host + asset.Id = string(conn.Type()) + asset.Name = conn.Host() asset.Platform = conn.PlatformInfo() asset.PlatformIds = []string{"//platformid.api.mondoo.app/runtime/atlassian"} diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index effbec8e93..cbbd3289b8 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -14,8 +14,6 @@ atlassian.admin.organization @defaults("id") { id string // Organization type type string - // Organization users - users() []atlassian.admin.organization.user // Policies policies() []atlassian.admin.organization.policy // Domains @@ -77,37 +75,7 @@ atlassian.admin.organization.event @defaults("id") { id string } -atlassian.admin.organization.user { - // Account ID - id string - // Organization ID - orgId string - // Account type - type string - // Account status - status string - // Name of the user - name string - // Picture of the user - picture string - // Email of the user - email string - // Billable - accessBillable bool - // Time when the user was last active - lastActive() []atlassian.admin.organization.user.lastActive -} -atlassian.admin.organization.user.lastActive @defaults("id") { - // ID - id string - // URL - url string - // Key - key string - // LastActive - lastActive string -} atlassian.jira { // Jira users diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 8a8fb9d473..8986d978bd 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -57,14 +57,6 @@ func init() { // to override args, implement: initAtlassianAdminOrganizationEvent(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganizationEvent, }, - "atlassian.admin.organization.user": { - // to override args, implement: initAtlassianAdminOrganizationUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) - Create: createAtlassianAdminOrganizationUser, - }, - "atlassian.admin.organization.user.lastActive": { - // to override args, implement: initAtlassianAdminOrganizationUserLastActive(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) - Create: createAtlassianAdminOrganizationUserLastActive, - }, "atlassian.jira": { // to override args, implement: initAtlassianJira(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianJira, @@ -182,9 +174,6 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.type": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganization).GetType()).ToDataRes(types.String) }, - "atlassian.admin.organization.users": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganization).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.user"))) - }, "atlassian.admin.organization.policies": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganization).GetPolicies()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.policy"))) }, @@ -242,45 +231,6 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.event.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationEvent).GetId()).ToDataRes(types.String) }, - "atlassian.admin.organization.user.id": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationUser).GetId()).ToDataRes(types.String) - }, - "atlassian.admin.organization.user.orgId": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationUser).GetOrgId()).ToDataRes(types.String) - }, - "atlassian.admin.organization.user.type": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationUser).GetType()).ToDataRes(types.String) - }, - "atlassian.admin.organization.user.status": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationUser).GetStatus()).ToDataRes(types.String) - }, - "atlassian.admin.organization.user.name": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationUser).GetName()).ToDataRes(types.String) - }, - "atlassian.admin.organization.user.picture": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationUser).GetPicture()).ToDataRes(types.String) - }, - "atlassian.admin.organization.user.email": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationUser).GetEmail()).ToDataRes(types.String) - }, - "atlassian.admin.organization.user.accessBillable": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationUser).GetAccessBillable()).ToDataRes(types.Bool) - }, - "atlassian.admin.organization.user.lastActive": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationUser).GetLastActive()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.user.lastActive"))) - }, - "atlassian.admin.organization.user.lastActive.id": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationUserLastActive).GetId()).ToDataRes(types.String) - }, - "atlassian.admin.organization.user.lastActive.url": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationUserLastActive).GetUrl()).ToDataRes(types.String) - }, - "atlassian.admin.organization.user.lastActive.key": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationUserLastActive).GetKey()).ToDataRes(types.String) - }, - "atlassian.admin.organization.user.lastActive.lastActive": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationUserLastActive).GetLastActive()).ToDataRes(types.String) - }, "atlassian.jira.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJira).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.jira.user"))) }, @@ -428,10 +378,6 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganization).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, - "atlassian.admin.organization.users": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganization).Users, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) - return - }, "atlassian.admin.organization.policies": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganization).Policies, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return @@ -536,66 +482,6 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganizationEvent).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, - "atlassian.admin.organization.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUser).__id, ok = v.Value.(string) - return - }, - "atlassian.admin.organization.user.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUser).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, - "atlassian.admin.organization.user.orgId": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUser).OrgId, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, - "atlassian.admin.organization.user.type": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUser).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, - "atlassian.admin.organization.user.status": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUser).Status, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, - "atlassian.admin.organization.user.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUser).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, - "atlassian.admin.organization.user.picture": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUser).Picture, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, - "atlassian.admin.organization.user.email": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUser).Email, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, - "atlassian.admin.organization.user.accessBillable": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUser).AccessBillable, ok = plugin.RawToTValue[bool](v.Value, v.Error) - return - }, - "atlassian.admin.organization.user.lastActive": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUser).LastActive, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) - return - }, - "atlassian.admin.organization.user.lastActive.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUserLastActive).__id, ok = v.Value.(string) - return - }, - "atlassian.admin.organization.user.lastActive.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUserLastActive).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, - "atlassian.admin.organization.user.lastActive.url": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUserLastActive).Url, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, - "atlassian.admin.organization.user.lastActive.key": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUserLastActive).Key, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, - "atlassian.admin.organization.user.lastActive.lastActive": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationUserLastActive).LastActive, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, "atlassian.jira.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianJira).__id, ok = v.Value.(string) return @@ -920,7 +806,6 @@ type mqlAtlassianAdminOrganization struct { // optional: if you define mqlAtlassianAdminOrganizationInternal it will be used here Id plugin.TValue[string] Type plugin.TValue[string] - Users plugin.TValue[[]interface{}] Policies plugin.TValue[[]interface{}] Domains plugin.TValue[[]interface{}] Events plugin.TValue[[]interface{}] @@ -968,22 +853,6 @@ func (c *mqlAtlassianAdminOrganization) GetType() *plugin.TValue[string] { return &c.Type } -func (c *mqlAtlassianAdminOrganization) GetUsers() *plugin.TValue[[]interface{}] { - return plugin.GetOrCompute[[]interface{}](&c.Users, func() ([]interface{}, error) { - if c.MqlRuntime.HasRecording { - d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization", c.__id, "users") - if err != nil { - return nil, err - } - if d != nil { - return d.Value.([]interface{}), nil - } - } - - return c.users() - }) -} - func (c *mqlAtlassianAdminOrganization) GetPolicies() *plugin.TValue[[]interface{}] { return plugin.GetOrCompute[[]interface{}](&c.Policies, func() ([]interface{}, error) { if c.MqlRuntime.HasRecording { @@ -1446,171 +1315,6 @@ func (c *mqlAtlassianAdminOrganizationEvent) GetId() *plugin.TValue[string] { return &c.Id } -// mqlAtlassianAdminOrganizationUser for the atlassian.admin.organization.user resource -type mqlAtlassianAdminOrganizationUser struct { - MqlRuntime *plugin.Runtime - __id string - // optional: if you define mqlAtlassianAdminOrganizationUserInternal it will be used here - Id plugin.TValue[string] - OrgId plugin.TValue[string] - Type plugin.TValue[string] - Status plugin.TValue[string] - Name plugin.TValue[string] - Picture plugin.TValue[string] - Email plugin.TValue[string] - AccessBillable plugin.TValue[bool] - LastActive plugin.TValue[[]interface{}] -} - -// createAtlassianAdminOrganizationUser creates a new instance of this resource -func createAtlassianAdminOrganizationUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { - res := &mqlAtlassianAdminOrganizationUser{ - MqlRuntime: runtime, - } - - err := SetAllData(res, args) - if err != nil { - return res, err - } - - if res.__id == "" { - res.__id, err = res.id() - if err != nil { - return nil, err - } - } - - if runtime.HasRecording { - args, err = runtime.ResourceFromRecording("atlassian.admin.organization.user", res.__id) - if err != nil || args == nil { - return res, err - } - return res, SetAllData(res, args) - } - - return res, nil -} - -func (c *mqlAtlassianAdminOrganizationUser) MqlName() string { - return "atlassian.admin.organization.user" -} - -func (c *mqlAtlassianAdminOrganizationUser) MqlID() string { - return c.__id -} - -func (c *mqlAtlassianAdminOrganizationUser) GetId() *plugin.TValue[string] { - return &c.Id -} - -func (c *mqlAtlassianAdminOrganizationUser) GetOrgId() *plugin.TValue[string] { - return &c.OrgId -} - -func (c *mqlAtlassianAdminOrganizationUser) GetType() *plugin.TValue[string] { - return &c.Type -} - -func (c *mqlAtlassianAdminOrganizationUser) GetStatus() *plugin.TValue[string] { - return &c.Status -} - -func (c *mqlAtlassianAdminOrganizationUser) GetName() *plugin.TValue[string] { - return &c.Name -} - -func (c *mqlAtlassianAdminOrganizationUser) GetPicture() *plugin.TValue[string] { - return &c.Picture -} - -func (c *mqlAtlassianAdminOrganizationUser) GetEmail() *plugin.TValue[string] { - return &c.Email -} - -func (c *mqlAtlassianAdminOrganizationUser) GetAccessBillable() *plugin.TValue[bool] { - return &c.AccessBillable -} - -func (c *mqlAtlassianAdminOrganizationUser) GetLastActive() *plugin.TValue[[]interface{}] { - return plugin.GetOrCompute[[]interface{}](&c.LastActive, func() ([]interface{}, error) { - if c.MqlRuntime.HasRecording { - d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization.user", c.__id, "lastActive") - if err != nil { - return nil, err - } - if d != nil { - return d.Value.([]interface{}), nil - } - } - - return c.lastActive() - }) -} - -// mqlAtlassianAdminOrganizationUserLastActive for the atlassian.admin.organization.user.lastActive resource -type mqlAtlassianAdminOrganizationUserLastActive struct { - MqlRuntime *plugin.Runtime - __id string - // optional: if you define mqlAtlassianAdminOrganizationUserLastActiveInternal it will be used here - Id plugin.TValue[string] - Url plugin.TValue[string] - Key plugin.TValue[string] - LastActive plugin.TValue[string] -} - -// createAtlassianAdminOrganizationUserLastActive creates a new instance of this resource -func createAtlassianAdminOrganizationUserLastActive(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { - res := &mqlAtlassianAdminOrganizationUserLastActive{ - MqlRuntime: runtime, - } - - err := SetAllData(res, args) - if err != nil { - return res, err - } - - if res.__id == "" { - res.__id, err = res.id() - if err != nil { - return nil, err - } - } - - if runtime.HasRecording { - args, err = runtime.ResourceFromRecording("atlassian.admin.organization.user.lastActive", res.__id) - if err != nil || args == nil { - return res, err - } - return res, SetAllData(res, args) - } - - return res, nil -} - -func (c *mqlAtlassianAdminOrganizationUserLastActive) MqlName() string { - return "atlassian.admin.organization.user.lastActive" -} - -func (c *mqlAtlassianAdminOrganizationUserLastActive) MqlID() string { - return c.__id -} - -func (c *mqlAtlassianAdminOrganizationUserLastActive) GetId() *plugin.TValue[string] { - return &c.Id -} - -func (c *mqlAtlassianAdminOrganizationUserLastActive) GetUrl() *plugin.TValue[string] { - return &c.Url -} - -func (c *mqlAtlassianAdminOrganizationUserLastActive) GetKey() *plugin.TValue[string] { - return &c.Key -} - -func (c *mqlAtlassianAdminOrganizationUserLastActive) GetLastActive() *plugin.TValue[string] { - return &c.LastActive -} - // mqlAtlassianJira for the atlassian.jira resource type mqlAtlassianJira struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index 740fa60fd3..b40df90939 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -5,7 +5,7 @@ import ( "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/llx" - "go.mondoo.com/cnquery/v9/providers/atlassian/connection" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/admin" ) func (a *mqlAtlassianAdmin) id() (string, error) { @@ -13,8 +13,8 @@ func (a *mqlAtlassianAdmin) id() (string, error) { } func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - admin := conn.Admin() + conn := a.MqlRuntime.Connection.(*admin.AdminConnection) + admin := conn.Client() organizations, response, err := admin.Organization.Gets(context.Background(), "") if err != nil { log.Fatal().Err(err) @@ -47,8 +47,8 @@ func (a *mqlAtlassianAdminOrganization) scim() (*mqlAtlassianAdminOrganizationSc } func (a *mqlAtlassianAdminOrganizationScim) users() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - admin := conn.Admin() + conn := a.MqlRuntime.Connection.(*admin.AdminConnection) + admin := conn.Client() scimUsers, response, err := admin.SCIM.User.Gets(context.Background(), "786d6a74-k7b3-14jk-7863-5b83a48k8c43", nil, 0, 1000) if err != nil { log.Fatal().Err(err) @@ -71,8 +71,8 @@ func (a *mqlAtlassianAdminOrganizationScim) users() ([]interface{}, error) { } func (a *mqlAtlassianAdminOrganizationScim) groups() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - admin := conn.Admin() + conn := a.MqlRuntime.Connection.(*admin.AdminConnection) + admin := conn.Client() scimGroup, response, err := admin.SCIM.Group.Gets(context.Background(), "786d6a74-k7b3-14jk-7863-5b83a48k8c43", "", 0, 1000) if err != nil { log.Fatal().Err(err) @@ -110,9 +110,9 @@ type atlassianUser struct { } func (a *mqlAtlassianAdminOrganization) managedUsers() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) + conn := a.MqlRuntime.Connection.(*admin.AdminConnection) - admin := conn.Admin() + admin := conn.Client() managedUsers, response, err := admin.Organization.Users(context.Background(), a.Id.Data, "") if err != nil { @@ -137,126 +137,9 @@ func (a *mqlAtlassianAdminOrganization) managedUsers() ([]interface{}, error) { return res, nil } -func (a *mqlAtlassianAdminOrganization) users() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - - jira := conn.Jira() - confluence := conn.Confluence() - - jiraUsers, response, err := jira.User.Search.Do(context.Background(), "", " ", 0, 1000) - if err != nil { - log.Fatal().Err(err) - } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } - - cql := "type = user" - confluenceUsers, response, err := confluence.Search.Users(context.Background(), cql, 0, 1000, nil) - if err != nil { - log.Fatal().Err(err) - } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } - var atlassianUsers []atlassianUser - for _, jiraUser := range jiraUsers { - user := atlassianUser{ - AccountID: jiraUser.AccountID, - Name: jiraUser.DisplayName, - Type: jiraUser.AccountType, - OrgID: a.Id.Data, - } - atlassianUsers = append(atlassianUsers, user) - } - for _, confluenceUser := range confluenceUsers.Results { - user := atlassianUser{ - AccountID: confluenceUser.User.AccountID, - Name: confluenceUser.User.DisplayName, - Type: confluenceUser.User.AccountType, - OrgID: a.Id.Data, - } - atlassianUsers = append(atlassianUsers, user) - } - - //TODO: is there a better way to get unique users? - var uniqueAtlassianUsers []atlassianUser -loopMark: - for _, v := range atlassianUsers { - for i, u := range uniqueAtlassianUsers { - if v.AccountID == u.AccountID { - uniqueAtlassianUsers[i] = v - continue loopMark - } - } - uniqueAtlassianUsers = append(uniqueAtlassianUsers, v) - } - - if err != nil { - log.Fatal().Err(err) - } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } - res := []interface{}{} - for _, user := range uniqueAtlassianUsers { - mqlAtlassianAdminUser, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.user", - map[string]*llx.RawData{ - "id": llx.StringData(user.AccountID), - "name": llx.StringData(user.Name), - "type": llx.StringData(user.Type), - "orgId": llx.StringData(user.OrgID), - }) - if err != nil { - log.Fatal().Err(err) - } - res = append(res, mqlAtlassianAdminUser) - } - return res, nil -} - -func (a *mqlAtlassianAdminOrganizationUser) lastActive() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - admin := conn.Admin() - accountId := a.Id.Data - orgId := a.OrgId.Data - lastActive, response, err := admin.Organization.Directory.Activity(context.Background(), orgId, accountId) - if err != nil { - log.Fatal().Err(err) - } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } - - res := []interface{}{} - for _, access := range lastActive.Data.ProductAccess { - mqlAtlassianAdminUserLastActive, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.user.lastActive", - map[string]*llx.RawData{ - "id": llx.StringData(access.Id), - "url": llx.StringData(access.Url), - "key": llx.StringData(access.Key), - "lastActive": llx.StringData(access.LastActive), - }) - if err != nil { - log.Fatal().Err(err) - } - res = append(res, mqlAtlassianAdminUserLastActive) - } - return res, nil - -} - -func (a *mqlAtlassianAdminOrganizationUserLastActive) id() (string, error) { - return a.Id.Data, nil -} - -func (a *mqlAtlassianAdminOrganizationUser) id() (string, error) { - return a.Id.Data, nil -} - func (a *mqlAtlassianAdminOrganization) policies() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - admin := conn.Admin() + conn := a.MqlRuntime.Connection.(*admin.AdminConnection) + admin := conn.Client() orgId := a.Id.Data policies, response, err := admin.Organization.Policy.Gets(context.Background(), orgId, "", "") if err != nil { @@ -284,8 +167,8 @@ func (a *mqlAtlassianAdminOrganization) policies() ([]interface{}, error) { } func (a *mqlAtlassianAdminOrganization) domains() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - admin := conn.Admin() + conn := a.MqlRuntime.Connection.(*admin.AdminConnection) + admin := conn.Client() orgId := a.Id.Data domains, response, err := admin.Organization.Domains(context.Background(), orgId, "") if err != nil { @@ -309,8 +192,8 @@ func (a *mqlAtlassianAdminOrganization) domains() ([]interface{}, error) { } func (a *mqlAtlassianAdminOrganization) events() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - admin := conn.Admin() + conn := a.MqlRuntime.Connection.(*admin.AdminConnection) + admin := conn.Client() orgId := a.Id.Data events, response, err := admin.Organization.Events(context.Background(), orgId, nil, "") if err != nil { diff --git a/providers/atlassian/resources/atlassian_confluence.go b/providers/atlassian/resources/atlassian_confluence.go index 609c5e6a00..b9cb2f216b 100644 --- a/providers/atlassian/resources/atlassian_confluence.go +++ b/providers/atlassian/resources/atlassian_confluence.go @@ -5,7 +5,7 @@ import ( "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/llx" - "go.mondoo.com/cnquery/v9/providers/atlassian/connection" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/confluence" ) func (a *mqlAtlassianConfluence) id() (string, error) { @@ -13,8 +13,8 @@ func (a *mqlAtlassianConfluence) id() (string, error) { } func (a *mqlAtlassianConfluence) users() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - confluence := conn.Confluence() + conn := a.MqlRuntime.Connection.(*confluence.ConfluenceConnection) + confluence := conn.Client() cql := "type = user" users, response, err := confluence.Search.Users(context.Background(), cql, 0, 1000, nil) if err != nil { diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index 81eb99a5a9..95315a4f15 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -6,7 +6,7 @@ import ( "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/llx" - "go.mondoo.com/cnquery/v9/providers/atlassian/connection" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/jira" ) func (a *mqlAtlassianJira) id() (string, error) { @@ -14,8 +14,8 @@ func (a *mqlAtlassianJira) id() (string, error) { } func (a *mqlAtlassianJira) users() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - jira := conn.Jira() + conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + jira := conn.Client() users, response, err := jira.User.Search.Do(context.Background(), "", " ", 0, 1000) if err != nil { log.Fatal().Err(err) @@ -42,8 +42,8 @@ func (a *mqlAtlassianJira) users() ([]interface{}, error) { } func (a *mqlAtlassianJiraUser) applicationRoles() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - jira := conn.Jira() + conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + jira := conn.Client() expands := []string{"groups", "applicationRoles"} user, response, err := jira.User.Get(context.Background(), a.Id.Data, expands) if err != nil { @@ -70,8 +70,8 @@ func (a *mqlAtlassianJiraUser) applicationRoles() ([]interface{}, error) { } func (a *mqlAtlassianJiraUser) groups() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - jira := conn.Jira() + conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + jira := conn.Client() groups, response, err := jira.Group.Bulk(context.Background(), nil, 0, 1000) if err != nil { log.Fatal().Err(err) @@ -96,8 +96,8 @@ func (a *mqlAtlassianJiraUser) groups() ([]interface{}, error) { } func (a *mqlAtlassianJira) groups() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - jira := conn.Jira() + conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + jira := conn.Client() groups, response, err := jira.Group.Bulk(context.Background(), nil, 0, 1000) if err != nil { log.Fatal().Err(err) @@ -122,8 +122,8 @@ func (a *mqlAtlassianJira) groups() ([]interface{}, error) { } func (a *mqlAtlassianJira) serverInfos() (*mqlAtlassianJiraServerInfo, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - jira := conn.Jira() + conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + jira := conn.Client() info, response, err := jira.Server.Info(context.Background()) if err != nil { log.Fatal().Err(err) @@ -142,8 +142,8 @@ func (a *mqlAtlassianJira) serverInfos() (*mqlAtlassianJiraServerInfo, error) { } func (a *mqlAtlassianJira) projects() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - jira := conn.Jira() + conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + jira := conn.Client() projects, response, err := jira.Project.Search(context.Background(), nil, 0, 1000) if err != nil { log.Fatal().Err(err) @@ -175,8 +175,8 @@ func (a *mqlAtlassianJira) projects() ([]interface{}, error) { } func (a *mqlAtlassianJira) issues() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - jira := conn.Jira() + conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + jira := conn.Client() validate := "" jql := "order by created DESC" fields := []string{"status", "project"} @@ -210,8 +210,8 @@ func (a *mqlAtlassianJiraIssue) id() (string, error) { } func (a *mqlAtlassianJiraProject) properties() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*connection.AtlassianConnection) - jira := conn.Jira() + conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + jira := conn.Client() properties, response, err := jira.Project.Property.Gets(context.Background(), a.Id.Data) if err != nil { log.Fatal().Err(err) From 3477401c371239af61238085efaedec8d2b8a8b0 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Fri, 13 Oct 2023 13:46:40 +0200 Subject: [PATCH 48/90] fixes --- providers/atlassian/config/config.go | 23 +++++++++++++++---- .../atlassian/connection/scim/connection.go | 2 +- providers/atlassian/provider/provider.go | 14 ++++++++++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/providers/atlassian/config/config.go b/providers/atlassian/config/config.go index 57dc121afa..5c92193e2f 100644 --- a/providers/atlassian/config/config.go +++ b/providers/atlassian/config/config.go @@ -6,15 +6,28 @@ import ( ) var Config = plugin.Provider{ - Name: "atlassian", - ID: "go.mondoo.com/cnquery/providers/atlassian", - Version: "9.0.0", - ConnectionTypes: []string{provider.DefaultConnectionType}, + Name: "atlassian", + ID: "go.mondoo.com/cnquery/providers/atlassian", + Version: "9.0.0", + ConnectionTypes: []string{ + provider.DefaultConnectionType, + "jira", + "admin", + "confluence", + "scim", + }, Connectors: []plugin.Connector{ { Name: "atlassian", Use: "atlassian", - Short: "Atlassian", + Short: "atlassian", + Discovery: []string{}, + Flags: []plugin.Flag{}, + }, + { + Name: "admin", + Use: "admin", + Short: "admin", Discovery: []string{}, Flags: []plugin.Flag{}, }, diff --git a/providers/atlassian/connection/scim/connection.go b/providers/atlassian/connection/scim/connection.go index c0b9b54fc1..2047d5dbe2 100644 --- a/providers/atlassian/connection/scim/connection.go +++ b/providers/atlassian/connection/scim/connection.go @@ -14,7 +14,7 @@ import ( ) const ( - Scim shared.ConnectionType = "jira" + Scim shared.ConnectionType = "scim" ) type ScimConnection struct { diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index 18daabb29e..b7347d0fc0 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -2,6 +2,7 @@ package provider import ( "errors" + "fmt" "strconv" "go.mondoo.com/cnquery/v9/llx" @@ -44,7 +45,17 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) Options: map[string]string{}, } - // Do custom flag parsing here + fmt.Println("req.connector: ", req.Connector) + switch req.Connector { + case "jira": + conf.Type = "jira" + case "confluence": + conf.Type = "confluece" + case "admin": + conf.Type = "admin" + case "scim": + conf.Type = "scim" + } asset := inventory.Asset{ Connections: []*inventory.Config{conf}, @@ -101,6 +112,7 @@ func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallba var conn shared.Connection var err error + fmt.Println("type: ", conf.Type) switch conf.Type { case "admin": s.lastConnectionID++ From 458736a74305a1400551c6ba63318c2eab2f7e8a Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Fri, 13 Oct 2023 13:54:19 +0200 Subject: [PATCH 49/90] add jira --- providers/atlassian/config/config.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/providers/atlassian/config/config.go b/providers/atlassian/config/config.go index 5c92193e2f..1125dd3fb1 100644 --- a/providers/atlassian/config/config.go +++ b/providers/atlassian/config/config.go @@ -31,5 +31,12 @@ var Config = plugin.Provider{ Discovery: []string{}, Flags: []plugin.Flag{}, }, + { + Name: "jira", + Use: "jira", + Short: "jira", + Discovery: []string{}, + Flags: []plugin.Flag{}, + }, }, } From 591561af963cbdc5a351d0f0304efb888f84187c Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Fri, 13 Oct 2023 16:34:21 +0200 Subject: [PATCH 50/90] add flags --- providers/atlassian/config/config.go | 37 ++++++++++++++----- .../atlassian/connection/jira/connection.go | 8 ++-- providers/atlassian/provider/provider.go | 27 ++++++++++++-- 3 files changed, 56 insertions(+), 16 deletions(-) diff --git a/providers/atlassian/config/config.go b/providers/atlassian/config/config.go index 1125dd3fb1..1ec9124fbf 100644 --- a/providers/atlassian/config/config.go +++ b/providers/atlassian/config/config.go @@ -17,26 +17,45 @@ var Config = plugin.Provider{ "scim", }, Connectors: []plugin.Connector{ - { - Name: "atlassian", - Use: "atlassian", - Short: "atlassian", - Discovery: []string{}, - Flags: []plugin.Flag{}, - }, { Name: "admin", Use: "admin", Short: "admin", Discovery: []string{}, - Flags: []plugin.Flag{}, + Flags: []plugin.Flag{ + { + Long: "token", + Type: plugin.FlagType_String, + Default: "", + Desc: "admin api token", + }, + }, }, { Name: "jira", Use: "jira", Short: "jira", Discovery: []string{}, - Flags: []plugin.Flag{}, + Flags: []plugin.Flag{ + { + Long: "host", + Type: plugin.FlagType_String, + Default: "", + Desc: "hostname of the jira instance", + }, + { + Long: "user", + Type: plugin.FlagType_String, + Default: "", + Desc: "email address of the user", + }, + { + Long: "token", + Type: plugin.FlagType_String, + Default: "", + Desc: "token of the user", + }, + }, }, }, } diff --git a/providers/atlassian/connection/jira/connection.go b/providers/atlassian/connection/jira/connection.go index 7cdabb35be..a10c149d3d 100644 --- a/providers/atlassian/connection/jira/connection.go +++ b/providers/atlassian/connection/jira/connection.go @@ -31,7 +31,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* host = os.Getenv("ATLASSIAN_HOST") } if host == "" { - return nil, errors.New("you need to provide atlassian host via ATLASSIAN_HOST env") + return nil, errors.New("you need to provide atlassian host e.g. via ATLASSIAN_HOST env") } user := conf.Options["user"] @@ -39,15 +39,15 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* user = os.Getenv("ATLASSIAN_USER") } if user == "" { - return nil, errors.New("you need to provide atlassian user via ATLASSIAN_USER env") + return nil, errors.New("you need to provide atlassian user e.g. via ATLASSIAN_USER env") } - userToken := conf.Options["usertoken"] + userToken := conf.Options["token"] if userToken == "" { userToken = os.Getenv("ATLASSIAN_USER_TOKEN") } if userToken == "" { - return nil, errors.New("you need to provide atlassian user token via ATLASSIAN_USER_TOKEN env") + return nil, errors.New("you need to provide atlassian user token e.g. via ATLASSIAN_USER_TOKEN env") } client, err := v2.New(nil, host) diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index b7347d0fc0..23d5a1618d 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -2,7 +2,6 @@ package provider import ( "errors" - "fmt" "strconv" "go.mondoo.com/cnquery/v9/llx" @@ -45,16 +44,39 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) Options: map[string]string{}, } - fmt.Println("req.connector: ", req.Connector) switch req.Connector { case "jira": conf.Type = "jira" + if x, ok := flags["host"]; ok && len(x.Value) != 0 { + conf.Options["host"] = string(x.Value) + } + if x, ok := flags["user"]; ok && len(x.Value) != 0 { + conf.Options["user"] = string(x.Value) + } + if x, ok := flags["token"]; ok && len(x.Value) != 0 { + conf.Options["token"] = string(x.Value) + } case "confluence": conf.Type = "confluece" + if x, ok := flags["host"]; ok && len(x.Value) != 0 { + conf.Options["host"] = string(x.Value) + } + if x, ok := flags["user"]; ok && len(x.Value) != 0 { + conf.Options["user"] = string(x.Value) + } + if x, ok := flags["token"]; ok && len(x.Value) != 0 { + conf.Options["token"] = string(x.Value) + } case "admin": conf.Type = "admin" + if x, ok := flags["token"]; ok && len(x.Value) != 0 { + conf.Options["token"] = string(x.Value) + } case "scim": conf.Type = "scim" + if x, ok := flags["token"]; ok && len(x.Value) != 0 { + conf.Options["token"] = string(x.Value) + } } asset := inventory.Asset{ @@ -112,7 +134,6 @@ func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallba var conn shared.Connection var err error - fmt.Println("type: ", conf.Type) switch conf.Type { case "admin": s.lastConnectionID++ From 1629b868f4fa740e74c9219f6ab9e1cefc17941d Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Fri, 13 Oct 2023 17:17:19 +0200 Subject: [PATCH 51/90] fixes --- providers/atlassian/connection/jira/connection.go | 10 +++++----- providers/atlassian/resources/atlassian_jira.go | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/providers/atlassian/connection/jira/connection.go b/providers/atlassian/connection/jira/connection.go index a10c149d3d..f9abe9e74d 100644 --- a/providers/atlassian/connection/jira/connection.go +++ b/providers/atlassian/connection/jira/connection.go @@ -42,11 +42,11 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* return nil, errors.New("you need to provide atlassian user e.g. via ATLASSIAN_USER env") } - userToken := conf.Options["token"] - if userToken == "" { - userToken = os.Getenv("ATLASSIAN_USER_TOKEN") + token := conf.Options["token"] + if token == "" { + token = os.Getenv("ATLASSIAN_USER_TOKEN") } - if userToken == "" { + if token == "" { return nil, errors.New("you need to provide atlassian user token e.g. via ATLASSIAN_USER_TOKEN env") } @@ -55,7 +55,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* log.Fatal().Err(err) } - client.Auth.SetBasicAuth(user, userToken) + client.Auth.SetBasicAuth(user, token) client.Auth.SetUserAgent("curl/7.54.0") conn := &JiraConnection{ diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index 95315a4f15..a663b1965b 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -23,7 +23,6 @@ func (a *mqlAtlassianJira) users() ([]interface{}, error) { if response.Status != "200 OK" { log.Fatal().Msgf("Received response: %s\n", response.Status) } - res := []interface{}{} for _, user := range users { mqlAtlassianJiraUser, err := CreateResource(a.MqlRuntime, "atlassian.jira.user", From ac261389ab5cfff74c23315285ae481b1dd76655 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Fri, 13 Oct 2023 17:20:48 +0200 Subject: [PATCH 52/90] clean up --- providers/atlassian/resources/atlassian_admin.go | 2 +- providers/atlassian/resources/atlassian_confluence.go | 2 +- providers/atlassian/resources/atlassian_jira.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index b40df90939..ab60e5bc7d 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -9,7 +9,7 @@ import ( ) func (a *mqlAtlassianAdmin) id() (string, error) { - return "wip", nil + return "admin", nil } func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { diff --git a/providers/atlassian/resources/atlassian_confluence.go b/providers/atlassian/resources/atlassian_confluence.go index b9cb2f216b..d0f6194c73 100644 --- a/providers/atlassian/resources/atlassian_confluence.go +++ b/providers/atlassian/resources/atlassian_confluence.go @@ -9,7 +9,7 @@ import ( ) func (a *mqlAtlassianConfluence) id() (string, error) { - return "wip", nil + return "confluence", nil } func (a *mqlAtlassianConfluence) users() ([]interface{}, error) { diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index a663b1965b..0e86af3962 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -10,7 +10,7 @@ import ( ) func (a *mqlAtlassianJira) id() (string, error) { - return "wip", nil + return "jira", nil } func (a *mqlAtlassianJira) users() ([]interface{}, error) { From 2d413026bc333a82658911460c6cd6876954ab3e Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 08:09:44 +0200 Subject: [PATCH 53/90] use subcommands --- providers/atlassian/config/config.go | 42 ++----------- providers/atlassian/connection/connection.go | 47 +++++++++++++++ providers/atlassian/provider/provider.go | 63 ++++---------------- 3 files changed, 64 insertions(+), 88 deletions(-) create mode 100644 providers/atlassian/connection/connection.go diff --git a/providers/atlassian/config/config.go b/providers/atlassian/config/config.go index 1ec9124fbf..46bf23c97f 100644 --- a/providers/atlassian/config/config.go +++ b/providers/atlassian/config/config.go @@ -18,44 +18,12 @@ var Config = plugin.Provider{ }, Connectors: []plugin.Connector{ { - Name: "admin", - Use: "admin", - Short: "admin", + Name: "atlassian", + Use: "atlassian", + Short: "atlassian", + MaxArgs: 2, Discovery: []string{}, - Flags: []plugin.Flag{ - { - Long: "token", - Type: plugin.FlagType_String, - Default: "", - Desc: "admin api token", - }, - }, - }, - { - Name: "jira", - Use: "jira", - Short: "jira", - Discovery: []string{}, - Flags: []plugin.Flag{ - { - Long: "host", - Type: plugin.FlagType_String, - Default: "", - Desc: "hostname of the jira instance", - }, - { - Long: "user", - Type: plugin.FlagType_String, - Default: "", - Desc: "email address of the user", - }, - { - Long: "token", - Type: plugin.FlagType_String, - Default: "", - Desc: "token of the user", - }, - }, + Flags: []plugin.Flag{}, }, }, } diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go new file mode 100644 index 0000000000..3e05348952 --- /dev/null +++ b/providers/atlassian/connection/connection.go @@ -0,0 +1,47 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +package connection + +import ( + "log" + + "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/admin" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/confluence" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/jira" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/scim" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/shared" +) + +const ( + Admin shared.ConnectionType = "atlassian" +) + +func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (shared.Connection, error) { + var conn shared.Connection + var err error + switch conf.Options["product"] { + case "admin": + conn, err = admin.NewConnection(id, asset, conf) + if err != nil { + log.Fatal("Failed to create admin connection") + } + case "jira": + conn, err = jira.NewConnection(id, asset, conf) + if err != nil { + log.Fatal("Failed to create jira connection") + } + case "confluence": + conn, err = confluence.NewConnection(id, asset, conf) + if err != nil { + log.Fatal("Failed to create confluence connection") + } + case "scim": + conn, err = scim.NewConnection(id, asset, conf) + if err != nil { + log.Fatal("Failed to create scim connection") + } + } + return conn, nil +} diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index 23d5a1618d..bcb1047fe9 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -8,10 +8,7 @@ import ( "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin" "go.mondoo.com/cnquery/v9/providers-sdk/v1/upstream" - "go.mondoo.com/cnquery/v9/providers/atlassian/connection/admin" - "go.mondoo.com/cnquery/v9/providers/atlassian/connection/confluence" - "go.mondoo.com/cnquery/v9/providers/atlassian/connection/jira" - "go.mondoo.com/cnquery/v9/providers/atlassian/connection/scim" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection" "go.mondoo.com/cnquery/v9/providers/atlassian/connection/shared" "go.mondoo.com/cnquery/v9/providers/atlassian/resources" ) @@ -39,44 +36,24 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) flags = map[string]*llx.Primitive{} } + if len(req.Args) != 1 { + return nil, errors.New("missing argument, use `atlassian jira`, `atlassian admin`, `atlassian confluence`, or `atlassian scim`") + } + conf := &inventory.Config{ Type: req.Connector, Options: map[string]string{}, } - switch req.Connector { + switch req.Args[0] { + case "admin": + conf.Options["product"] = req.Args[0] case "jira": - conf.Type = "jira" - if x, ok := flags["host"]; ok && len(x.Value) != 0 { - conf.Options["host"] = string(x.Value) - } - if x, ok := flags["user"]; ok && len(x.Value) != 0 { - conf.Options["user"] = string(x.Value) - } - if x, ok := flags["token"]; ok && len(x.Value) != 0 { - conf.Options["token"] = string(x.Value) - } + conf.Options["product"] = req.Args[0] case "confluence": - conf.Type = "confluece" - if x, ok := flags["host"]; ok && len(x.Value) != 0 { - conf.Options["host"] = string(x.Value) - } - if x, ok := flags["user"]; ok && len(x.Value) != 0 { - conf.Options["user"] = string(x.Value) - } - if x, ok := flags["token"]; ok && len(x.Value) != 0 { - conf.Options["token"] = string(x.Value) - } - case "admin": - conf.Type = "admin" - if x, ok := flags["token"]; ok && len(x.Value) != 0 { - conf.Options["token"] = string(x.Value) - } + conf.Options["product"] = req.Args[0] case "scim": - conf.Type = "scim" - if x, ok := flags["token"]; ok && len(x.Value) != 0 { - conf.Options["token"] = string(x.Value) - } + conf.Options["product"] = req.Args[0] } asset := inventory.Asset{ @@ -134,23 +111,7 @@ func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallba var conn shared.Connection var err error - switch conf.Type { - case "admin": - s.lastConnectionID++ - conn, err = admin.NewConnection(s.lastConnectionID, asset, conf) - case "scim": - s.lastConnectionID++ - conn, err = scim.NewConnection(s.lastConnectionID, asset, conf) - case "jira": - s.lastConnectionID++ - conn, err = jira.NewConnection(s.lastConnectionID, asset, conf) - case "confluence": - s.lastConnectionID++ - conn, err = confluence.NewConnection(s.lastConnectionID, asset, conf) - default: - s.lastConnectionID++ - conn, err = admin.NewConnection(s.lastConnectionID, asset, conf) - } + conn, err = connection.NewConnection(s.lastConnectionID, asset, conf) if err != nil { return nil, err From a4d3a27f01907b7100ae6e21d8e54b0d8e428d2d Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 08:12:14 +0200 Subject: [PATCH 54/90] better errors --- providers/atlassian/connection/connection.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index 3e05348952..58844e4791 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -6,6 +6,7 @@ package connection import ( "log" + "github.com/pkg/errors" "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" "go.mondoo.com/cnquery/v9/providers/atlassian/connection/admin" "go.mondoo.com/cnquery/v9/providers/atlassian/connection/confluence" @@ -25,22 +26,22 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (s case "admin": conn, err = admin.NewConnection(id, asset, conf) if err != nil { - log.Fatal("Failed to create admin connection") + return nil, errors.Wrap(err, "Failed to create admin connection") } case "jira": conn, err = jira.NewConnection(id, asset, conf) if err != nil { - log.Fatal("Failed to create jira connection") + return nil, errors.Wrap(err, "Failed to create jira connection") } case "confluence": conn, err = confluence.NewConnection(id, asset, conf) if err != nil { - log.Fatal("Failed to create confluence connection") + return nil, errors.Wrap(err, "Failed to create confluence connection") } case "scim": conn, err = scim.NewConnection(id, asset, conf) if err != nil { - log.Fatal("Failed to create scim connection") + return nil, errors.Wrap(err, "Failed to create scim connection") } } return conn, nil From 1838aef737126020bba931060d07e5fc22262a6c Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 09:08:17 +0200 Subject: [PATCH 55/90] scim and clean up --- providers/atlassian/connection/connection.go | 3 +- .../atlassian/connection/scim/connection.go | 4 +- providers/atlassian/resources/atlassian.lr | 45 +- providers/atlassian/resources/atlassian.lr.go | 502 +++++++----------- .../resources/atlassian.lr.manifest.yaml | 33 ++ .../atlassian/resources/atlassian_admin.go | 90 ---- .../atlassian/resources/atlassian_scim.go | 71 +++ 7 files changed, 325 insertions(+), 423 deletions(-) create mode 100644 providers/atlassian/resources/atlassian_scim.go diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index 58844e4791..b9acffa419 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -4,7 +4,7 @@ package connection import ( - "log" + "fmt" "github.com/pkg/errors" "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" @@ -22,6 +22,7 @@ const ( func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (shared.Connection, error) { var conn shared.Connection var err error + fmt.Println("Product: ", conf.Options["product"]) switch conf.Options["product"] { case "admin": conn, err = admin.NewConnection(id, asset, conf) diff --git a/providers/atlassian/connection/scim/connection.go b/providers/atlassian/connection/scim/connection.go index 2047d5dbe2..bb95bdd712 100644 --- a/providers/atlassian/connection/scim/connection.go +++ b/providers/atlassian/connection/scim/connection.go @@ -31,7 +31,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* token = os.Getenv("ATLASSIAN_SCIM_TOKEN") } if token == "" { - return nil, errors.New("you need to provide atlassian admin token via ATLASSIAN_SCIM_TOKEN env") + return nil, errors.New("you need to provide atlassian scim token via ATLASSIAN_SCIM_TOKEN env") } client, err := admin.New(nil) @@ -54,7 +54,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* } func (c *ScimConnection) Name() string { - return "jira" + return "scim" } func (c *ScimConnection) ID() uint32 { diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index cbbd3289b8..b70472e9ba 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -9,6 +9,23 @@ atlassian.admin { organizations() []atlassian.admin.organization } +atlassian.scim { + // SCIM users + users() []atlassian.scim.organization.scim.user + // SCIM groups + groups() []atlassian.scim.organization.scim.group +} + +atlassian.scim.user @defaults("id") { + // ID + id string +} + +atlassian.scim.group @defaults("id") { + // ID + id string +} + atlassian.admin.organization @defaults("id") { // Organization ID id string @@ -18,10 +35,6 @@ atlassian.admin.organization @defaults("id") { policies() []atlassian.admin.organization.policy // Domains domains() []atlassian.admin.organization.domain - // Events - events() []atlassian.admin.organization.event - // SCIM - scim() atlassian.admin.organization.scim // Managed Users managedUsers() []atlassian.admin.organization.managedUsers } @@ -35,23 +48,6 @@ atlassian.admin.organization.managedUsers { type string } -atlassian.admin.organization.scim { - // SCIM users - users() []atlassian.admin.organization.scim.user - // SCIM groups - groups() []atlassian.admin.organization.scim.group -} - -atlassian.admin.organization.scim.user @defaults("id") { - // ID - id string -} - -atlassian.admin.organization.scim.group @defaults("id") { - // ID - id string -} - atlassian.admin.organization.policy @defaults("id") { // Policy ID id string @@ -70,13 +66,6 @@ atlassian.admin.organization.domain @defaults("id") { id string } -atlassian.admin.organization.event @defaults("id") { - // Event ID - id string -} - - - atlassian.jira { // Jira users users() []atlassian.jira.user diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 8986d978bd..dff64d4dea 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -25,6 +25,18 @@ func init() { // to override args, implement: initAtlassianAdmin(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdmin, }, + "atlassian.scim": { + // to override args, implement: initAtlassianScim(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianScim, + }, + "atlassian.scim.user": { + // to override args, implement: initAtlassianScimUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianScimUser, + }, + "atlassian.scim.group": { + // to override args, implement: initAtlassianScimGroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianScimGroup, + }, "atlassian.admin.organization": { // to override args, implement: initAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganization, @@ -33,18 +45,6 @@ func init() { // to override args, implement: initAtlassianAdminOrganizationManagedUsers(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganizationManagedUsers, }, - "atlassian.admin.organization.scim": { - // to override args, implement: initAtlassianAdminOrganizationScim(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) - Create: createAtlassianAdminOrganizationScim, - }, - "atlassian.admin.organization.scim.user": { - // to override args, implement: initAtlassianAdminOrganizationScimUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) - Create: createAtlassianAdminOrganizationScimUser, - }, - "atlassian.admin.organization.scim.group": { - // to override args, implement: initAtlassianAdminOrganizationScimGroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) - Create: createAtlassianAdminOrganizationScimGroup, - }, "atlassian.admin.organization.policy": { // to override args, implement: initAtlassianAdminOrganizationPolicy(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganizationPolicy, @@ -53,10 +53,6 @@ func init() { // to override args, implement: initAtlassianAdminOrganizationDomain(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdminOrganizationDomain, }, - "atlassian.admin.organization.event": { - // to override args, implement: initAtlassianAdminOrganizationEvent(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) - Create: createAtlassianAdminOrganizationEvent, - }, "atlassian.jira": { // to override args, implement: initAtlassianJira(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianJira, @@ -168,6 +164,18 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organizations": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdmin).GetOrganizations()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization"))) }, + "atlassian.scim.users": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianScim).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.scim.organization.scim.user"))) + }, + "atlassian.scim.groups": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianScim).GetGroups()).ToDataRes(types.Array(types.Resource("atlassian.scim.organization.scim.group"))) + }, + "atlassian.scim.user.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianScimUser).GetId()).ToDataRes(types.String) + }, + "atlassian.scim.group.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianScimGroup).GetId()).ToDataRes(types.String) + }, "atlassian.admin.organization.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganization).GetId()).ToDataRes(types.String) }, @@ -180,12 +188,6 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.domains": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganization).GetDomains()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.domain"))) }, - "atlassian.admin.organization.events": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganization).GetEvents()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.event"))) - }, - "atlassian.admin.organization.scim": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganization).GetScim()).ToDataRes(types.Resource("atlassian.admin.organization.scim")) - }, "atlassian.admin.organization.managedUsers": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganization).GetManagedUsers()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.managedUsers"))) }, @@ -198,18 +200,6 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.managedUsers.type": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationManagedUsers).GetType()).ToDataRes(types.String) }, - "atlassian.admin.organization.scim.users": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationScim).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.scim.user"))) - }, - "atlassian.admin.organization.scim.groups": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationScim).GetGroups()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization.scim.group"))) - }, - "atlassian.admin.organization.scim.user.id": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationScimUser).GetId()).ToDataRes(types.String) - }, - "atlassian.admin.organization.scim.group.id": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationScimGroup).GetId()).ToDataRes(types.String) - }, "atlassian.admin.organization.policy.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationPolicy).GetId()).ToDataRes(types.String) }, @@ -228,9 +218,6 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.domain.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationDomain).GetId()).ToDataRes(types.String) }, - "atlassian.admin.organization.event.id": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdminOrganizationEvent).GetId()).ToDataRes(types.String) - }, "atlassian.jira.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJira).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.jira.user"))) }, @@ -366,6 +353,34 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdmin).Organizations, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, + "atlassian.scim.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianScim).__id, ok = v.Value.(string) + return + }, + "atlassian.scim.users": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianScim).Users, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, + "atlassian.scim.groups": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianScim).Groups, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) + return + }, + "atlassian.scim.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianScimUser).__id, ok = v.Value.(string) + return + }, + "atlassian.scim.user.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianScimUser).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.scim.group.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianScimGroup).__id, ok = v.Value.(string) + return + }, + "atlassian.scim.group.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianScimGroup).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.admin.organization.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganization).__id, ok = v.Value.(string) return @@ -386,14 +401,6 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganization).Domains, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, - "atlassian.admin.organization.events": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganization).Events, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) - return - }, - "atlassian.admin.organization.scim": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganization).Scim, ok = plugin.RawToTValue[*mqlAtlassianAdminOrganizationScim](v.Value, v.Error) - return - }, "atlassian.admin.organization.managedUsers": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganization).ManagedUsers, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return @@ -414,34 +421,6 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganizationManagedUsers).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, - "atlassian.admin.organization.scim.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationScim).__id, ok = v.Value.(string) - return - }, - "atlassian.admin.organization.scim.users": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationScim).Users, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) - return - }, - "atlassian.admin.organization.scim.groups": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationScim).Groups, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) - return - }, - "atlassian.admin.organization.scim.user.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationScimUser).__id, ok = v.Value.(string) - return - }, - "atlassian.admin.organization.scim.user.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationScimUser).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, - "atlassian.admin.organization.scim.group.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationScimGroup).__id, ok = v.Value.(string) - return - }, - "atlassian.admin.organization.scim.group.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationScimGroup).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, "atlassian.admin.organization.policy.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganizationPolicy).__id, ok = v.Value.(string) return @@ -474,14 +453,6 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganizationDomain).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, - "atlassian.admin.organization.event.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationEvent).__id, ok = v.Value.(string) - return - }, - "atlassian.admin.organization.event.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdminOrganizationEvent).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) - return - }, "atlassian.jira.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianJira).__id, ok = v.Value.(string) return @@ -799,23 +770,18 @@ func (c *mqlAtlassianAdmin) GetOrganizations() *plugin.TValue[[]interface{}] { }) } -// mqlAtlassianAdminOrganization for the atlassian.admin.organization resource -type mqlAtlassianAdminOrganization struct { +// mqlAtlassianScim for the atlassian.scim resource +type mqlAtlassianScim struct { MqlRuntime *plugin.Runtime __id string - // optional: if you define mqlAtlassianAdminOrganizationInternal it will be used here - Id plugin.TValue[string] - Type plugin.TValue[string] - Policies plugin.TValue[[]interface{}] - Domains plugin.TValue[[]interface{}] - Events plugin.TValue[[]interface{}] - Scim plugin.TValue[*mqlAtlassianAdminOrganizationScim] - ManagedUsers plugin.TValue[[]interface{}] + // optional: if you define mqlAtlassianScimInternal it will be used here + Users plugin.TValue[[]interface{}] + Groups plugin.TValue[[]interface{}] } -// createAtlassianAdminOrganization creates a new instance of this resource -func createAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { - res := &mqlAtlassianAdminOrganization{ +// createAtlassianScim creates a new instance of this resource +func createAtlassianScim(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianScim{ MqlRuntime: runtime, } @@ -824,10 +790,15 @@ func createAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]* return res, err } - // to override __id implement: id() (string, error) + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } if runtime.HasRecording { - args, err = runtime.ResourceFromRecording("atlassian.admin.organization", res.__id) + args, err = runtime.ResourceFromRecording("atlassian.scim", res.__id) if err != nil || args == nil { return res, err } @@ -837,26 +808,18 @@ func createAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]* return res, nil } -func (c *mqlAtlassianAdminOrganization) MqlName() string { - return "atlassian.admin.organization" +func (c *mqlAtlassianScim) MqlName() string { + return "atlassian.scim" } -func (c *mqlAtlassianAdminOrganization) MqlID() string { +func (c *mqlAtlassianScim) MqlID() string { return c.__id } -func (c *mqlAtlassianAdminOrganization) GetId() *plugin.TValue[string] { - return &c.Id -} - -func (c *mqlAtlassianAdminOrganization) GetType() *plugin.TValue[string] { - return &c.Type -} - -func (c *mqlAtlassianAdminOrganization) GetPolicies() *plugin.TValue[[]interface{}] { - return plugin.GetOrCompute[[]interface{}](&c.Policies, func() ([]interface{}, error) { +func (c *mqlAtlassianScim) GetUsers() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Users, func() ([]interface{}, error) { if c.MqlRuntime.HasRecording { - d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization", c.__id, "policies") + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.scim", c.__id, "users") if err != nil { return nil, err } @@ -865,14 +828,14 @@ func (c *mqlAtlassianAdminOrganization) GetPolicies() *plugin.TValue[[]interface } } - return c.policies() + return c.users() }) } -func (c *mqlAtlassianAdminOrganization) GetDomains() *plugin.TValue[[]interface{}] { - return plugin.GetOrCompute[[]interface{}](&c.Domains, func() ([]interface{}, error) { +func (c *mqlAtlassianScim) GetGroups() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Groups, func() ([]interface{}, error) { if c.MqlRuntime.HasRecording { - d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization", c.__id, "domains") + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.scim", c.__id, "groups") if err != nil { return nil, err } @@ -881,71 +844,70 @@ func (c *mqlAtlassianAdminOrganization) GetDomains() *plugin.TValue[[]interface{ } } - return c.domains() + return c.groups() }) } -func (c *mqlAtlassianAdminOrganization) GetEvents() *plugin.TValue[[]interface{}] { - return plugin.GetOrCompute[[]interface{}](&c.Events, func() ([]interface{}, error) { - if c.MqlRuntime.HasRecording { - d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization", c.__id, "events") - if err != nil { - return nil, err - } - if d != nil { - return d.Value.([]interface{}), nil - } - } - - return c.events() - }) +// mqlAtlassianScimUser for the atlassian.scim.user resource +type mqlAtlassianScimUser struct { + MqlRuntime *plugin.Runtime + __id string + // optional: if you define mqlAtlassianScimUserInternal it will be used here + Id plugin.TValue[string] } -func (c *mqlAtlassianAdminOrganization) GetScim() *plugin.TValue[*mqlAtlassianAdminOrganizationScim] { - return plugin.GetOrCompute[*mqlAtlassianAdminOrganizationScim](&c.Scim, func() (*mqlAtlassianAdminOrganizationScim, error) { - if c.MqlRuntime.HasRecording { - d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization", c.__id, "scim") - if err != nil { - return nil, err - } - if d != nil { - return d.Value.(*mqlAtlassianAdminOrganizationScim), nil - } +// createAtlassianScimUser creates a new instance of this resource +func createAtlassianScimUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianScimUser{ + MqlRuntime: runtime, + } + + err := SetAllData(res, args) + if err != nil { + return res, err + } + + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err } + } - return c.scim() - }) + if runtime.HasRecording { + args, err = runtime.ResourceFromRecording("atlassian.scim.user", res.__id) + if err != nil || args == nil { + return res, err + } + return res, SetAllData(res, args) + } + + return res, nil } -func (c *mqlAtlassianAdminOrganization) GetManagedUsers() *plugin.TValue[[]interface{}] { - return plugin.GetOrCompute[[]interface{}](&c.ManagedUsers, func() ([]interface{}, error) { - if c.MqlRuntime.HasRecording { - d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization", c.__id, "managedUsers") - if err != nil { - return nil, err - } - if d != nil { - return d.Value.([]interface{}), nil - } - } +func (c *mqlAtlassianScimUser) MqlName() string { + return "atlassian.scim.user" +} - return c.managedUsers() - }) +func (c *mqlAtlassianScimUser) MqlID() string { + return c.__id } -// mqlAtlassianAdminOrganizationManagedUsers for the atlassian.admin.organization.managedUsers resource -type mqlAtlassianAdminOrganizationManagedUsers struct { +func (c *mqlAtlassianScimUser) GetId() *plugin.TValue[string] { + return &c.Id +} + +// mqlAtlassianScimGroup for the atlassian.scim.group resource +type mqlAtlassianScimGroup struct { MqlRuntime *plugin.Runtime __id string - // optional: if you define mqlAtlassianAdminOrganizationManagedUsersInternal it will be used here + // optional: if you define mqlAtlassianScimGroupInternal it will be used here Id plugin.TValue[string] - Name plugin.TValue[string] - Type plugin.TValue[string] } -// createAtlassianAdminOrganizationManagedUsers creates a new instance of this resource -func createAtlassianAdminOrganizationManagedUsers(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { - res := &mqlAtlassianAdminOrganizationManagedUsers{ +// createAtlassianScimGroup creates a new instance of this resource +func createAtlassianScimGroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianScimGroup{ MqlRuntime: runtime, } @@ -954,10 +916,15 @@ func createAtlassianAdminOrganizationManagedUsers(runtime *plugin.Runtime, args return res, err } - // to override __id implement: id() (string, error) + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } if runtime.HasRecording { - args, err = runtime.ResourceFromRecording("atlassian.admin.organization.managedUsers", res.__id) + args, err = runtime.ResourceFromRecording("atlassian.scim.group", res.__id) if err != nil || args == nil { return res, err } @@ -967,38 +934,33 @@ func createAtlassianAdminOrganizationManagedUsers(runtime *plugin.Runtime, args return res, nil } -func (c *mqlAtlassianAdminOrganizationManagedUsers) MqlName() string { - return "atlassian.admin.organization.managedUsers" +func (c *mqlAtlassianScimGroup) MqlName() string { + return "atlassian.scim.group" } -func (c *mqlAtlassianAdminOrganizationManagedUsers) MqlID() string { +func (c *mqlAtlassianScimGroup) MqlID() string { return c.__id } -func (c *mqlAtlassianAdminOrganizationManagedUsers) GetId() *plugin.TValue[string] { +func (c *mqlAtlassianScimGroup) GetId() *plugin.TValue[string] { return &c.Id } -func (c *mqlAtlassianAdminOrganizationManagedUsers) GetName() *plugin.TValue[string] { - return &c.Name -} - -func (c *mqlAtlassianAdminOrganizationManagedUsers) GetType() *plugin.TValue[string] { - return &c.Type -} - -// mqlAtlassianAdminOrganizationScim for the atlassian.admin.organization.scim resource -type mqlAtlassianAdminOrganizationScim struct { +// mqlAtlassianAdminOrganization for the atlassian.admin.organization resource +type mqlAtlassianAdminOrganization struct { MqlRuntime *plugin.Runtime __id string - // optional: if you define mqlAtlassianAdminOrganizationScimInternal it will be used here - Users plugin.TValue[[]interface{}] - Groups plugin.TValue[[]interface{}] + // optional: if you define mqlAtlassianAdminOrganizationInternal it will be used here + Id plugin.TValue[string] + Type plugin.TValue[string] + Policies plugin.TValue[[]interface{}] + Domains plugin.TValue[[]interface{}] + ManagedUsers plugin.TValue[[]interface{}] } -// createAtlassianAdminOrganizationScim creates a new instance of this resource -func createAtlassianAdminOrganizationScim(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { - res := &mqlAtlassianAdminOrganizationScim{ +// createAtlassianAdminOrganization creates a new instance of this resource +func createAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianAdminOrganization{ MqlRuntime: runtime, } @@ -1010,7 +972,7 @@ func createAtlassianAdminOrganizationScim(runtime *plugin.Runtime, args map[stri // to override __id implement: id() (string, error) if runtime.HasRecording { - args, err = runtime.ResourceFromRecording("atlassian.admin.organization.scim", res.__id) + args, err = runtime.ResourceFromRecording("atlassian.admin.organization", res.__id) if err != nil || args == nil { return res, err } @@ -1020,18 +982,26 @@ func createAtlassianAdminOrganizationScim(runtime *plugin.Runtime, args map[stri return res, nil } -func (c *mqlAtlassianAdminOrganizationScim) MqlName() string { - return "atlassian.admin.organization.scim" +func (c *mqlAtlassianAdminOrganization) MqlName() string { + return "atlassian.admin.organization" } -func (c *mqlAtlassianAdminOrganizationScim) MqlID() string { +func (c *mqlAtlassianAdminOrganization) MqlID() string { return c.__id } -func (c *mqlAtlassianAdminOrganizationScim) GetUsers() *plugin.TValue[[]interface{}] { - return plugin.GetOrCompute[[]interface{}](&c.Users, func() ([]interface{}, error) { +func (c *mqlAtlassianAdminOrganization) GetId() *plugin.TValue[string] { + return &c.Id +} + +func (c *mqlAtlassianAdminOrganization) GetType() *plugin.TValue[string] { + return &c.Type +} + +func (c *mqlAtlassianAdminOrganization) GetPolicies() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Policies, func() ([]interface{}, error) { if c.MqlRuntime.HasRecording { - d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization.scim", c.__id, "users") + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization", c.__id, "policies") if err != nil { return nil, err } @@ -1040,14 +1010,14 @@ func (c *mqlAtlassianAdminOrganizationScim) GetUsers() *plugin.TValue[[]interfac } } - return c.users() + return c.policies() }) } -func (c *mqlAtlassianAdminOrganizationScim) GetGroups() *plugin.TValue[[]interface{}] { - return plugin.GetOrCompute[[]interface{}](&c.Groups, func() ([]interface{}, error) { +func (c *mqlAtlassianAdminOrganization) GetDomains() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.Domains, func() ([]interface{}, error) { if c.MqlRuntime.HasRecording { - d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization.scim", c.__id, "groups") + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization", c.__id, "domains") if err != nil { return nil, err } @@ -1056,70 +1026,39 @@ func (c *mqlAtlassianAdminOrganizationScim) GetGroups() *plugin.TValue[[]interfa } } - return c.groups() + return c.domains() }) } -// mqlAtlassianAdminOrganizationScimUser for the atlassian.admin.organization.scim.user resource -type mqlAtlassianAdminOrganizationScimUser struct { - MqlRuntime *plugin.Runtime - __id string - // optional: if you define mqlAtlassianAdminOrganizationScimUserInternal it will be used here - Id plugin.TValue[string] -} - -// createAtlassianAdminOrganizationScimUser creates a new instance of this resource -func createAtlassianAdminOrganizationScimUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { - res := &mqlAtlassianAdminOrganizationScimUser{ - MqlRuntime: runtime, - } - - err := SetAllData(res, args) - if err != nil { - return res, err - } - - if res.__id == "" { - res.__id, err = res.id() - if err != nil { - return nil, err - } - } - - if runtime.HasRecording { - args, err = runtime.ResourceFromRecording("atlassian.admin.organization.scim.user", res.__id) - if err != nil || args == nil { - return res, err +func (c *mqlAtlassianAdminOrganization) GetManagedUsers() *plugin.TValue[[]interface{}] { + return plugin.GetOrCompute[[]interface{}](&c.ManagedUsers, func() ([]interface{}, error) { + if c.MqlRuntime.HasRecording { + d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin.organization", c.__id, "managedUsers") + if err != nil { + return nil, err + } + if d != nil { + return d.Value.([]interface{}), nil + } } - return res, SetAllData(res, args) - } - return res, nil -} - -func (c *mqlAtlassianAdminOrganizationScimUser) MqlName() string { - return "atlassian.admin.organization.scim.user" -} - -func (c *mqlAtlassianAdminOrganizationScimUser) MqlID() string { - return c.__id -} - -func (c *mqlAtlassianAdminOrganizationScimUser) GetId() *plugin.TValue[string] { - return &c.Id + return c.managedUsers() + }) } -// mqlAtlassianAdminOrganizationScimGroup for the atlassian.admin.organization.scim.group resource -type mqlAtlassianAdminOrganizationScimGroup struct { +// mqlAtlassianAdminOrganizationManagedUsers for the atlassian.admin.organization.managedUsers resource +type mqlAtlassianAdminOrganizationManagedUsers struct { MqlRuntime *plugin.Runtime __id string - // optional: if you define mqlAtlassianAdminOrganizationScimGroupInternal it will be used here + // optional: if you define mqlAtlassianAdminOrganizationManagedUsersInternal it will be used here Id plugin.TValue[string] + Name plugin.TValue[string] + Type plugin.TValue[string] } -// createAtlassianAdminOrganizationScimGroup creates a new instance of this resource -func createAtlassianAdminOrganizationScimGroup(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { - res := &mqlAtlassianAdminOrganizationScimGroup{ +// createAtlassianAdminOrganizationManagedUsers creates a new instance of this resource +func createAtlassianAdminOrganizationManagedUsers(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianAdminOrganizationManagedUsers{ MqlRuntime: runtime, } @@ -1128,15 +1067,10 @@ func createAtlassianAdminOrganizationScimGroup(runtime *plugin.Runtime, args map return res, err } - if res.__id == "" { - res.__id, err = res.id() - if err != nil { - return nil, err - } - } + // to override __id implement: id() (string, error) if runtime.HasRecording { - args, err = runtime.ResourceFromRecording("atlassian.admin.organization.scim.group", res.__id) + args, err = runtime.ResourceFromRecording("atlassian.admin.organization.managedUsers", res.__id) if err != nil || args == nil { return res, err } @@ -1146,18 +1080,26 @@ func createAtlassianAdminOrganizationScimGroup(runtime *plugin.Runtime, args map return res, nil } -func (c *mqlAtlassianAdminOrganizationScimGroup) MqlName() string { - return "atlassian.admin.organization.scim.group" +func (c *mqlAtlassianAdminOrganizationManagedUsers) MqlName() string { + return "atlassian.admin.organization.managedUsers" } -func (c *mqlAtlassianAdminOrganizationScimGroup) MqlID() string { +func (c *mqlAtlassianAdminOrganizationManagedUsers) MqlID() string { return c.__id } -func (c *mqlAtlassianAdminOrganizationScimGroup) GetId() *plugin.TValue[string] { +func (c *mqlAtlassianAdminOrganizationManagedUsers) GetId() *plugin.TValue[string] { return &c.Id } +func (c *mqlAtlassianAdminOrganizationManagedUsers) GetName() *plugin.TValue[string] { + return &c.Name +} + +func (c *mqlAtlassianAdminOrganizationManagedUsers) GetType() *plugin.TValue[string] { + return &c.Type +} + // mqlAtlassianAdminOrganizationPolicy for the atlassian.admin.organization.policy resource type mqlAtlassianAdminOrganizationPolicy struct { MqlRuntime *plugin.Runtime @@ -1271,50 +1213,6 @@ func (c *mqlAtlassianAdminOrganizationDomain) GetId() *plugin.TValue[string] { return &c.Id } -// mqlAtlassianAdminOrganizationEvent for the atlassian.admin.organization.event resource -type mqlAtlassianAdminOrganizationEvent struct { - MqlRuntime *plugin.Runtime - __id string - // optional: if you define mqlAtlassianAdminOrganizationEventInternal it will be used here - Id plugin.TValue[string] -} - -// createAtlassianAdminOrganizationEvent creates a new instance of this resource -func createAtlassianAdminOrganizationEvent(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { - res := &mqlAtlassianAdminOrganizationEvent{ - MqlRuntime: runtime, - } - - err := SetAllData(res, args) - if err != nil { - return res, err - } - - // to override __id implement: id() (string, error) - - if runtime.HasRecording { - args, err = runtime.ResourceFromRecording("atlassian.admin.organization.event", res.__id) - if err != nil || args == nil { - return res, err - } - return res, SetAllData(res, args) - } - - return res, nil -} - -func (c *mqlAtlassianAdminOrganizationEvent) MqlName() string { - return "atlassian.admin.organization.event" -} - -func (c *mqlAtlassianAdminOrganizationEvent) MqlID() string { - return c.__id -} - -func (c *mqlAtlassianAdminOrganizationEvent) GetId() *plugin.TValue[string] { - return &c.Id -} - // mqlAtlassianJira for the atlassian.jira resource type mqlAtlassianJira struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 4dbb5ac8da..bddb442e71 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -181,3 +181,36 @@ resources: id: {} name: {} min_mondoo_version: latest + atlassian.scim: + fields: + groups: {} + organizations: {} + users: {} + min_mondoo_version: latest + atlassian.scim.group: + fields: + id: {} + min_mondoo_version: latest + atlassian.scim.organization: + fields: + id: {} + scim: {} + type: {} + min_mondoo_version: latest + atlassian.scim.organization.scim: + fields: + groups: {} + users: {} + min_mondoo_version: latest + atlassian.scim.organization.scim.group: + fields: + id: {} + min_mondoo_version: latest + atlassian.scim.organization.scim.user: + fields: + id: {} + min_mondoo_version: latest + atlassian.scim.user: + fields: + id: {} + min_mondoo_version: latest diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index ab60e5bc7d..3e756caead 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -37,71 +37,6 @@ func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { return res, nil } -func (a *mqlAtlassianAdminOrganization) scim() (*mqlAtlassianAdminOrganizationScim, error) { - mqlAtlassianAdminSCIM, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.scim", - map[string]*llx.RawData{}) - if err != nil { - log.Fatal().Err(err) - } - return mqlAtlassianAdminSCIM.(*mqlAtlassianAdminOrganizationScim), nil -} - -func (a *mqlAtlassianAdminOrganizationScim) users() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*admin.AdminConnection) - admin := conn.Client() - scimUsers, response, err := admin.SCIM.User.Gets(context.Background(), "786d6a74-k7b3-14jk-7863-5b83a48k8c43", nil, 0, 1000) - if err != nil { - log.Fatal().Err(err) - } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } - res := []interface{}{} - for _, scimUser := range scimUsers.Resources { - mqlAtlassianAdminSCIMuser, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.scim.user", - map[string]*llx.RawData{ - "id": llx.StringData(scimUser.ID), - }) - if err != nil { - log.Fatal().Err(err) - } - res = append(res, mqlAtlassianAdminSCIMuser) - } - return res, nil -} - -func (a *mqlAtlassianAdminOrganizationScim) groups() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*admin.AdminConnection) - admin := conn.Client() - scimGroup, response, err := admin.SCIM.Group.Gets(context.Background(), "786d6a74-k7b3-14jk-7863-5b83a48k8c43", "", 0, 1000) - if err != nil { - log.Fatal().Err(err) - } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } - res := []interface{}{} - for _, scimGroup := range scimGroup.Resources { - mqlAtlassianAdminSCIMgroup, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.scim.group", - map[string]*llx.RawData{ - "id": llx.StringData(scimGroup.ID), - }) - if err != nil { - log.Fatal().Err(err) - } - res = append(res, mqlAtlassianAdminSCIMgroup) - } - return res, nil -} - -func (a *mqlAtlassianAdminOrganizationScimUser) id() (string, error) { - return a.Id.Data, nil -} - -func (a *mqlAtlassianAdminOrganizationScimGroup) id() (string, error) { - return a.Id.Data, nil -} - type atlassianUser struct { AccountID string Name string @@ -191,31 +126,6 @@ func (a *mqlAtlassianAdminOrganization) domains() ([]interface{}, error) { return res, nil } -func (a *mqlAtlassianAdminOrganization) events() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*admin.AdminConnection) - admin := conn.Client() - orgId := a.Id.Data - events, response, err := admin.Organization.Events(context.Background(), orgId, nil, "") - if err != nil { - log.Fatal().Err(err) - } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } - res := []interface{}{} - for _, event := range events.Data { - mqlAtlassianAdminDomain, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.event", - map[string]*llx.RawData{ - "id": llx.StringData(event.ID), - }) - if err != nil { - log.Fatal().Err(err) - } - res = append(res, mqlAtlassianAdminDomain) - } - return res, nil -} - func (a *mqlAtlassianAdminOrganizationPolicy) id() (string, error) { return a.Id.Data, nil } diff --git a/providers/atlassian/resources/atlassian_scim.go b/providers/atlassian/resources/atlassian_scim.go new file mode 100644 index 0000000000..f007f25884 --- /dev/null +++ b/providers/atlassian/resources/atlassian_scim.go @@ -0,0 +1,71 @@ +package resources + +import ( + "context" + + "github.com/rs/zerolog/log" + "go.mondoo.com/cnquery/v9/llx" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/scim" +) + +func (a *mqlAtlassianScim) id() (string, error) { + return "scim", nil +} + +func (a *mqlAtlassianScim) users() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*scim.ScimConnection) + admin := conn.Client() + directoryID := "9766e0d0-5319-494c-b216-f85c3882490f" + scimUsers, response, err := admin.SCIM.User.Gets(context.Background(), directoryID, nil, 0, 1000) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + res := []interface{}{} + for _, scimUser := range scimUsers.Resources { + mqlAtlassianAdminSCIMuser, err := CreateResource(a.MqlRuntime, "atlassian.scim.organization.scim.user", + map[string]*llx.RawData{ + "id": llx.StringData(scimUser.ID), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianAdminSCIMuser) + } + return res, nil +} + +func (a *mqlAtlassianScim) groups() ([]interface{}, error) { + conn := a.MqlRuntime.Connection.(*scim.ScimConnection) + admin := conn.Client() + directoryID := "9766e0d0-5319-494c-b216-f85c3882490f" + scimGroup, response, err := admin.SCIM.Group.Gets(context.Background(), directoryID, "", 0, 1000) + if err != nil { + log.Fatal().Err(err) + } + if response.Status != "200 OK" { + log.Fatal().Msgf("Received response: %s\n", response.Status) + } + res := []interface{}{} + for _, scimGroup := range scimGroup.Resources { + mqlAtlassianAdminSCIMgroup, err := CreateResource(a.MqlRuntime, "atlassian.scim.organization.scim.group", + map[string]*llx.RawData{ + "id": llx.StringData(scimGroup.ID), + }) + if err != nil { + log.Fatal().Err(err) + } + res = append(res, mqlAtlassianAdminSCIMgroup) + } + return res, nil +} + +func (a *mqlAtlassianScimUser) id() (string, error) { + return a.Id.Data, nil +} + +func (a *mqlAtlassianScimGroup) id() (string, error) { + return a.Id.Data, nil +} From cb02d4057c187345238439ec88ee5a7b461a58e0 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 09:20:18 +0200 Subject: [PATCH 56/90] directory id argument --- providers/atlassian/connection/scim/connection.go | 8 ++++++++ providers/atlassian/provider/provider.go | 11 +++++++++-- providers/atlassian/resources/atlassian_scim.go | 4 ++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/providers/atlassian/connection/scim/connection.go b/providers/atlassian/connection/scim/connection.go index bb95bdd712..9724bed230 100644 --- a/providers/atlassian/connection/scim/connection.go +++ b/providers/atlassian/connection/scim/connection.go @@ -34,6 +34,10 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* return nil, errors.New("you need to provide atlassian scim token via ATLASSIAN_SCIM_TOKEN env") } + if conf.Options["directory-id"] == "" { + return nil, errors.New("you need to provide a directory id for scim") + } + client, err := admin.New(nil) if err != nil { log.Fatal().Err(err) @@ -76,3 +80,7 @@ func (p *ScimConnection) Type() shared.ConnectionType { func (c *ScimConnection) Host() string { return c.host } + +func (c *ScimConnection) Directory() string { + return c.Conf.Options["directory-id"] +} diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index bcb1047fe9..fe49914a80 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -36,8 +36,14 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) flags = map[string]*llx.Primitive{} } - if len(req.Args) != 1 { - return nil, errors.New("missing argument, use `atlassian jira`, `atlassian admin`, `atlassian confluence`, or `atlassian scim`") + if len(req.Args) == 0 { + return nil, errors.New("missing argument, use `atlassian jira`, `atlassian admin`, `atlassian confluence`, or `atlassian scim {directoryID}`") + } + + if req.Args[0] == "scim" { + if len(req.Args) != 2 { + return nil, errors.New("missing argument, scim requires a directoryID `atlassian scim {directoryID}`") + } } conf := &inventory.Config{ @@ -54,6 +60,7 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) conf.Options["product"] = req.Args[0] case "scim": conf.Options["product"] = req.Args[0] + conf.Options["directory-id"] = req.Args[1] } asset := inventory.Asset{ diff --git a/providers/atlassian/resources/atlassian_scim.go b/providers/atlassian/resources/atlassian_scim.go index f007f25884..db50ead6da 100644 --- a/providers/atlassian/resources/atlassian_scim.go +++ b/providers/atlassian/resources/atlassian_scim.go @@ -15,7 +15,7 @@ func (a *mqlAtlassianScim) id() (string, error) { func (a *mqlAtlassianScim) users() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*scim.ScimConnection) admin := conn.Client() - directoryID := "9766e0d0-5319-494c-b216-f85c3882490f" + directoryID := conn.Directory() scimUsers, response, err := admin.SCIM.User.Gets(context.Background(), directoryID, nil, 0, 1000) if err != nil { log.Fatal().Err(err) @@ -40,7 +40,7 @@ func (a *mqlAtlassianScim) users() ([]interface{}, error) { func (a *mqlAtlassianScim) groups() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*scim.ScimConnection) admin := conn.Client() - directoryID := "9766e0d0-5319-494c-b216-f85c3882490f" + directoryID := conn.Directory() scimGroup, response, err := admin.SCIM.Group.Gets(context.Background(), directoryID, "", 0, 1000) if err != nil { log.Fatal().Err(err) From 155fdcfb40b5213f9f4e454c4fa1392725eb06d6 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 10:03:12 +0200 Subject: [PATCH 57/90] clean up --- providers/atlassian/provider/provider.go | 3 +- providers/atlassian/resources/atlassian.go | 9 ---- providers/atlassian/resources/atlassian.lr | 4 -- providers/atlassian/resources/atlassian.lr.go | 52 ------------------- 4 files changed, 1 insertion(+), 67 deletions(-) delete mode 100644 providers/atlassian/resources/atlassian.go diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index fe49914a80..ddf1cbedbc 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -134,8 +134,7 @@ func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallba asset.Connections[0].Id = conn.ID() s.runtimes[conn.ID()] = &plugin.Runtime{ - Connection: conn, - //Resources: map[string]plugin.Resource{}, + Connection: conn, Callback: callback, HasRecording: req.HasRecording, CreateResource: resources.CreateResource, diff --git a/providers/atlassian/resources/atlassian.go b/providers/atlassian/resources/atlassian.go deleted file mode 100644 index 3192e6b5df..0000000000 --- a/providers/atlassian/resources/atlassian.go +++ /dev/null @@ -1,9 +0,0 @@ -package resources - -func (r *mqlAtlassian) id() (string, error) { - return "atlassian", nil -} - -func (r *mqlAtlassian) field() (string, error) { - return "example", nil -} diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index b70472e9ba..773c526891 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -1,10 +1,6 @@ option provider = "go.mondoo.com/cnquery/providers/atlassian" option go_package = "go.mondoo.com/cnquery/providers/atlassian/resources" -// Atlassian -atlassian { -} - atlassian.admin { organizations() []atlassian.admin.organization } diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index dff64d4dea..f8c0bd9ee9 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -17,10 +17,6 @@ var resourceFactories map[string]plugin.ResourceFactory func init() { resourceFactories = map[string]plugin.ResourceFactory { - "atlassian": { - // to override args, implement: initAtlassian(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) - Create: createAtlassian, - }, "atlassian.admin": { // to override args, implement: initAtlassianAdmin(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianAdmin, @@ -341,10 +337,6 @@ func GetData(resource plugin.Resource, field string, args map[string]*llx.RawDat } var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { - "atlassian.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassian).__id, ok = v.Value.(string) - return - }, "atlassian.admin.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdmin).__id, ok = v.Value.(string) return @@ -665,50 +657,6 @@ func SetAllData(resource plugin.Resource, args map[string]*llx.RawData) error { return nil } -// mqlAtlassian for the atlassian resource -type mqlAtlassian struct { - MqlRuntime *plugin.Runtime - __id string - // optional: if you define mqlAtlassianInternal it will be used here -} - -// createAtlassian creates a new instance of this resource -func createAtlassian(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { - res := &mqlAtlassian{ - MqlRuntime: runtime, - } - - err := SetAllData(res, args) - if err != nil { - return res, err - } - - if res.__id == "" { - res.__id, err = res.id() - if err != nil { - return nil, err - } - } - - if runtime.HasRecording { - args, err = runtime.ResourceFromRecording("atlassian", res.__id) - if err != nil || args == nil { - return res, err - } - return res, SetAllData(res, args) - } - - return res, nil -} - -func (c *mqlAtlassian) MqlName() string { - return "atlassian" -} - -func (c *mqlAtlassian) MqlID() string { - return c.__id -} - // mqlAtlassianAdmin for the atlassian.admin resource type mqlAtlassianAdmin struct { MqlRuntime *plugin.Runtime From 6a1f974f1f6a106213b3b367552725252755f1f9 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 10:06:54 +0200 Subject: [PATCH 58/90] add more fields to scim user --- providers/atlassian/resources/atlassian.lr | 8 ++++++++ providers/atlassian/resources/atlassian_scim.go | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 773c526891..9d46b2c810 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -15,6 +15,14 @@ atlassian.scim { atlassian.scim.user @defaults("id") { // ID id string + // Name + name string + // Display Name + displayName string + // Organization + organization string + // Title + title string } atlassian.scim.group @defaults("id") { diff --git a/providers/atlassian/resources/atlassian_scim.go b/providers/atlassian/resources/atlassian_scim.go index db50ead6da..bf979b7a82 100644 --- a/providers/atlassian/resources/atlassian_scim.go +++ b/providers/atlassian/resources/atlassian_scim.go @@ -27,7 +27,11 @@ func (a *mqlAtlassianScim) users() ([]interface{}, error) { for _, scimUser := range scimUsers.Resources { mqlAtlassianAdminSCIMuser, err := CreateResource(a.MqlRuntime, "atlassian.scim.organization.scim.user", map[string]*llx.RawData{ - "id": llx.StringData(scimUser.ID), + "id": llx.StringData(scimUser.ID), + "name": llx.StringData(scimUser.Name.Formatted), + "displayName": llx.StringData(scimUser.DisplayName), + "organization": llx.StringData(scimUser.Organization), + "title": llx.StringData(scimUser.Title), }) if err != nil { log.Fatal().Err(err) From d7a3e46f8ebfc29f01a1a18d2411f51b5cb7785d Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 10:09:26 +0200 Subject: [PATCH 59/90] remove unused type --- providers/atlassian/resources/atlassian_admin.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index 3e756caead..a355955703 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -37,13 +37,6 @@ func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { return res, nil } -type atlassianUser struct { - AccountID string - Name string - Type string - OrgID string -} - func (a *mqlAtlassianAdminOrganization) managedUsers() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*admin.AdminConnection) From 75c69e94de30ad73079fa27b0b448315a91040af Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 10:13:37 +0200 Subject: [PATCH 60/90] remove response checking --- .../atlassian/resources/atlassian_admin.go | 20 ++------- .../resources/atlassian_confluence.go | 5 +-- .../atlassian/resources/atlassian_jira.go | 43 ++++--------------- .../atlassian/resources/atlassian_scim.go | 10 +---- 4 files changed, 15 insertions(+), 63 deletions(-) diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index a355955703..4bf78ac3c3 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -15,13 +15,10 @@ func (a *mqlAtlassianAdmin) id() (string, error) { func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*admin.AdminConnection) admin := conn.Client() - organizations, response, err := admin.Organization.Gets(context.Background(), "") + organizations, _, err := admin.Organization.Gets(context.Background(), "") if err != nil { log.Fatal().Err(err) } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } res := []interface{}{} for _, org := range organizations.Data { mqlAtlassianAdminOrg, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization", @@ -42,13 +39,10 @@ func (a *mqlAtlassianAdminOrganization) managedUsers() ([]interface{}, error) { admin := conn.Client() - managedUsers, response, err := admin.Organization.Users(context.Background(), a.Id.Data, "") + managedUsers, _, err := admin.Organization.Users(context.Background(), a.Id.Data, "") if err != nil { log.Fatal().Err(err) } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } res := []interface{}{} for _, user := range managedUsers.Data { mqlAtlassianAdminManagedUser, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.managedUser", @@ -69,13 +63,10 @@ func (a *mqlAtlassianAdminOrganization) policies() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*admin.AdminConnection) admin := conn.Client() orgId := a.Id.Data - policies, response, err := admin.Organization.Policy.Gets(context.Background(), orgId, "", "") + policies, _, err := admin.Organization.Policy.Gets(context.Background(), orgId, "", "") if err != nil { log.Fatal().Err(err) } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } res := []interface{}{} for _, policy := range policies.Data { mqlAtlassianAdminPolicy, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.policy", @@ -98,13 +89,10 @@ func (a *mqlAtlassianAdminOrganization) domains() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*admin.AdminConnection) admin := conn.Client() orgId := a.Id.Data - domains, response, err := admin.Organization.Domains(context.Background(), orgId, "") + domains, _, err := admin.Organization.Domains(context.Background(), orgId, "") if err != nil { log.Fatal().Err(err) } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } res := []interface{}{} for _, domain := range domains.Data { mqlAtlassianAdminDomain, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.domain", diff --git a/providers/atlassian/resources/atlassian_confluence.go b/providers/atlassian/resources/atlassian_confluence.go index d0f6194c73..7584d305b4 100644 --- a/providers/atlassian/resources/atlassian_confluence.go +++ b/providers/atlassian/resources/atlassian_confluence.go @@ -16,13 +16,10 @@ func (a *mqlAtlassianConfluence) users() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*confluence.ConfluenceConnection) confluence := conn.Client() cql := "type = user" - users, response, err := confluence.Search.Users(context.Background(), cql, 0, 1000, nil) + users, _, err := confluence.Search.Users(context.Background(), cql, 0, 1000, nil) if err != nil { log.Fatal().Err(err) } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } res := []interface{}{} for _, user := range users.Results { mqlAtlassianConfluenceUser, err := CreateResource(a.MqlRuntime, "atlassian.confluence.user", diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index 0e86af3962..fbb0a77066 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -16,13 +16,10 @@ func (a *mqlAtlassianJira) id() (string, error) { func (a *mqlAtlassianJira) users() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*jira.JiraConnection) jira := conn.Client() - users, response, err := jira.User.Search.Do(context.Background(), "", " ", 0, 1000) + users, _, err := jira.User.Search.Do(context.Background(), "", " ", 0, 1000) if err != nil { log.Fatal().Err(err) } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } res := []interface{}{} for _, user := range users { mqlAtlassianJiraUser, err := CreateResource(a.MqlRuntime, "atlassian.jira.user", @@ -44,13 +41,10 @@ func (a *mqlAtlassianJiraUser) applicationRoles() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*jira.JiraConnection) jira := conn.Client() expands := []string{"groups", "applicationRoles"} - user, response, err := jira.User.Get(context.Background(), a.Id.Data, expands) + user, _, err := jira.User.Get(context.Background(), a.Id.Data, expands) if err != nil { log.Fatal().Err(err) } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } roles := user.ApplicationRoles res := []interface{}{} @@ -71,14 +65,10 @@ func (a *mqlAtlassianJiraUser) applicationRoles() ([]interface{}, error) { func (a *mqlAtlassianJiraUser) groups() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*jira.JiraConnection) jira := conn.Client() - groups, response, err := jira.Group.Bulk(context.Background(), nil, 0, 1000) + groups, _, err := jira.Group.Bulk(context.Background(), nil, 0, 1000) if err != nil { log.Fatal().Err(err) } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } - res := []interface{}{} for _, group := range groups.Values { mqlAtlassianJiraUserGroup, err := CreateResource(a.MqlRuntime, "atlassian.jira.group", @@ -97,14 +87,10 @@ func (a *mqlAtlassianJiraUser) groups() ([]interface{}, error) { func (a *mqlAtlassianJira) groups() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*jira.JiraConnection) jira := conn.Client() - groups, response, err := jira.Group.Bulk(context.Background(), nil, 0, 1000) + groups, _, err := jira.Group.Bulk(context.Background(), nil, 0, 1000) if err != nil { log.Fatal().Err(err) } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } - res := []interface{}{} for _, group := range groups.Values { mqlAtlassianJiraUserGroup, err := CreateResource(a.MqlRuntime, "atlassian.jira.group", @@ -123,13 +109,10 @@ func (a *mqlAtlassianJira) groups() ([]interface{}, error) { func (a *mqlAtlassianJira) serverInfos() (*mqlAtlassianJiraServerInfo, error) { conn := a.MqlRuntime.Connection.(*jira.JiraConnection) jira := conn.Client() - info, response, err := jira.Server.Info(context.Background()) + info, _, err := jira.Server.Info(context.Background()) if err != nil { log.Fatal().Err(err) } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } res, err := CreateResource(a.MqlRuntime, "atlassian.jira.serverInfo", map[string]*llx.RawData{ "baseUrl": llx.StringData(info.BaseURL), @@ -143,13 +126,10 @@ func (a *mqlAtlassianJira) serverInfos() (*mqlAtlassianJiraServerInfo, error) { func (a *mqlAtlassianJira) projects() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*jira.JiraConnection) jira := conn.Client() - projects, response, err := jira.Project.Search(context.Background(), nil, 0, 1000) + projects, _, err := jira.Project.Search(context.Background(), nil, 0, 1000) if err != nil { log.Fatal().Err(err) } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } res := []interface{}{} for _, project := range projects.Values { @@ -180,14 +160,10 @@ func (a *mqlAtlassianJira) issues() ([]interface{}, error) { jql := "order by created DESC" fields := []string{"status", "project"} expands := []string{"changelog", "renderedFields", "names", "schema", "transitions", "operations", "editmeta"} - issues, response, err := jira.Issue.Search.Get(context.Background(), jql, fields, expands, 0, 1000, validate) + issues, _, err := jira.Issue.Search.Get(context.Background(), jql, fields, expands, 0, 1000, validate) if err != nil { log.Fatal().Err(err) } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } - res := []interface{}{} for _, issue := range issues.Issues { mqlAtlassianJiraIssue, err := CreateResource(a.MqlRuntime, "atlassian.jira.issue", @@ -211,13 +187,10 @@ func (a *mqlAtlassianJiraIssue) id() (string, error) { func (a *mqlAtlassianJiraProject) properties() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*jira.JiraConnection) jira := conn.Client() - properties, response, err := jira.Project.Property.Gets(context.Background(), a.Id.Data) + properties, _, err := jira.Project.Property.Gets(context.Background(), a.Id.Data) if err != nil { log.Fatal().Err(err) } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } res := []interface{}{} for _, property := range properties.Keys { diff --git a/providers/atlassian/resources/atlassian_scim.go b/providers/atlassian/resources/atlassian_scim.go index bf979b7a82..c5b354b0da 100644 --- a/providers/atlassian/resources/atlassian_scim.go +++ b/providers/atlassian/resources/atlassian_scim.go @@ -16,13 +16,10 @@ func (a *mqlAtlassianScim) users() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*scim.ScimConnection) admin := conn.Client() directoryID := conn.Directory() - scimUsers, response, err := admin.SCIM.User.Gets(context.Background(), directoryID, nil, 0, 1000) + scimUsers, _, err := admin.SCIM.User.Gets(context.Background(), directoryID, nil, 0, 1000) if err != nil { log.Fatal().Err(err) } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } res := []interface{}{} for _, scimUser := range scimUsers.Resources { mqlAtlassianAdminSCIMuser, err := CreateResource(a.MqlRuntime, "atlassian.scim.organization.scim.user", @@ -45,13 +42,10 @@ func (a *mqlAtlassianScim) groups() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*scim.ScimConnection) admin := conn.Client() directoryID := conn.Directory() - scimGroup, response, err := admin.SCIM.Group.Gets(context.Background(), directoryID, "", 0, 1000) + scimGroup, _, err := admin.SCIM.Group.Gets(context.Background(), directoryID, "", 0, 1000) if err != nil { log.Fatal().Err(err) } - if response.Status != "200 OK" { - log.Fatal().Msgf("Received response: %s\n", response.Status) - } res := []interface{}{} for _, scimGroup := range scimGroup.Resources { mqlAtlassianAdminSCIMgroup, err := CreateResource(a.MqlRuntime, "atlassian.scim.organization.scim.group", From ca2a314e965153305bae9dd3ac539f493b780e22 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 10:17:38 +0200 Subject: [PATCH 61/90] return err instead of log.fatal --- .../atlassian/resources/atlassian_admin.go | 17 +++++----- .../resources/atlassian_confluence.go | 5 ++- .../atlassian/resources/atlassian_jira.go | 31 +++++++++---------- .../atlassian/resources/atlassian_scim.go | 9 +++--- 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index 4bf78ac3c3..bb11ac427c 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -3,7 +3,6 @@ package resources import ( "context" - "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/llx" "go.mondoo.com/cnquery/v9/providers/atlassian/connection/admin" ) @@ -17,7 +16,7 @@ func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { admin := conn.Client() organizations, _, err := admin.Organization.Gets(context.Background(), "") if err != nil { - log.Fatal().Err(err) + return nil, err } res := []interface{}{} for _, org := range organizations.Data { @@ -27,7 +26,7 @@ func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { "type": llx.StringData(org.Type), }) if err != nil { - log.Fatal().Err(err) + return nil, err } res = append(res, mqlAtlassianAdminOrg) } @@ -41,7 +40,7 @@ func (a *mqlAtlassianAdminOrganization) managedUsers() ([]interface{}, error) { managedUsers, _, err := admin.Organization.Users(context.Background(), a.Id.Data, "") if err != nil { - log.Fatal().Err(err) + return nil, err } res := []interface{}{} for _, user := range managedUsers.Data { @@ -52,7 +51,7 @@ func (a *mqlAtlassianAdminOrganization) managedUsers() ([]interface{}, error) { "type": llx.StringData(user.AccountType), }) if err != nil { - log.Fatal().Err(err) + return nil, err } res = append(res, mqlAtlassianAdminManagedUser) } @@ -65,7 +64,7 @@ func (a *mqlAtlassianAdminOrganization) policies() ([]interface{}, error) { orgId := a.Id.Data policies, _, err := admin.Organization.Policy.Gets(context.Background(), orgId, "", "") if err != nil { - log.Fatal().Err(err) + return nil, err } res := []interface{}{} for _, policy := range policies.Data { @@ -78,7 +77,7 @@ func (a *mqlAtlassianAdminOrganization) policies() ([]interface{}, error) { "policyType": llx.StringData(policy.Attributes.Type), }) if err != nil { - log.Fatal().Err(err) + return nil, err } res = append(res, mqlAtlassianAdminPolicy) } @@ -91,7 +90,7 @@ func (a *mqlAtlassianAdminOrganization) domains() ([]interface{}, error) { orgId := a.Id.Data domains, _, err := admin.Organization.Domains(context.Background(), orgId, "") if err != nil { - log.Fatal().Err(err) + return nil, err } res := []interface{}{} for _, domain := range domains.Data { @@ -100,7 +99,7 @@ func (a *mqlAtlassianAdminOrganization) domains() ([]interface{}, error) { "id": llx.StringData(domain.ID), }) if err != nil { - log.Fatal().Err(err) + return nil, err } res = append(res, mqlAtlassianAdminDomain) } diff --git a/providers/atlassian/resources/atlassian_confluence.go b/providers/atlassian/resources/atlassian_confluence.go index 7584d305b4..3b20d40cbc 100644 --- a/providers/atlassian/resources/atlassian_confluence.go +++ b/providers/atlassian/resources/atlassian_confluence.go @@ -3,7 +3,6 @@ package resources import ( "context" - "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/llx" "go.mondoo.com/cnquery/v9/providers/atlassian/connection/confluence" ) @@ -18,7 +17,7 @@ func (a *mqlAtlassianConfluence) users() ([]interface{}, error) { cql := "type = user" users, _, err := confluence.Search.Users(context.Background(), cql, 0, 1000, nil) if err != nil { - log.Fatal().Err(err) + return nil, err } res := []interface{}{} for _, user := range users.Results { @@ -29,7 +28,7 @@ func (a *mqlAtlassianConfluence) users() ([]interface{}, error) { "name": llx.StringData(user.User.DisplayName), }) if err != nil { - log.Fatal().Err(err) + return nil, err } res = append(res, mqlAtlassianConfluenceUser) } diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index fbb0a77066..7faea74879 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -4,7 +4,6 @@ import ( "context" "fmt" - "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/llx" "go.mondoo.com/cnquery/v9/providers/atlassian/connection/jira" ) @@ -18,7 +17,7 @@ func (a *mqlAtlassianJira) users() ([]interface{}, error) { jira := conn.Client() users, _, err := jira.User.Search.Do(context.Background(), "", " ", 0, 1000) if err != nil { - log.Fatal().Err(err) + return nil, err } res := []interface{}{} for _, user := range users { @@ -30,7 +29,7 @@ func (a *mqlAtlassianJira) users() ([]interface{}, error) { "picture": llx.StringData(user.AvatarUrls.One6X16), }) if err != nil { - log.Fatal().Err(err) + return nil, err } res = append(res, mqlAtlassianJiraUser) } @@ -43,7 +42,7 @@ func (a *mqlAtlassianJiraUser) applicationRoles() ([]interface{}, error) { expands := []string{"groups", "applicationRoles"} user, _, err := jira.User.Get(context.Background(), a.Id.Data, expands) if err != nil { - log.Fatal().Err(err) + return nil, err } roles := user.ApplicationRoles @@ -55,7 +54,7 @@ func (a *mqlAtlassianJiraUser) applicationRoles() ([]interface{}, error) { "name": llx.StringData(role.Name), }) if err != nil { - log.Fatal().Err(err) + return nil, err } res = append(res, mqlAtlassianJiraUserRole) } @@ -67,7 +66,7 @@ func (a *mqlAtlassianJiraUser) groups() ([]interface{}, error) { jira := conn.Client() groups, _, err := jira.Group.Bulk(context.Background(), nil, 0, 1000) if err != nil { - log.Fatal().Err(err) + return nil, err } res := []interface{}{} for _, group := range groups.Values { @@ -77,7 +76,7 @@ func (a *mqlAtlassianJiraUser) groups() ([]interface{}, error) { "name": llx.StringData(group.Name), }) if err != nil { - log.Fatal().Err(err) + return nil, err } res = append(res, mqlAtlassianJiraUserGroup) } @@ -89,7 +88,7 @@ func (a *mqlAtlassianJira) groups() ([]interface{}, error) { jira := conn.Client() groups, _, err := jira.Group.Bulk(context.Background(), nil, 0, 1000) if err != nil { - log.Fatal().Err(err) + return nil, err } res := []interface{}{} for _, group := range groups.Values { @@ -99,7 +98,7 @@ func (a *mqlAtlassianJira) groups() ([]interface{}, error) { "name": llx.StringData(group.Name), }) if err != nil { - log.Fatal().Err(err) + return nil, err } res = append(res, mqlAtlassianJiraUserGroup) } @@ -111,7 +110,7 @@ func (a *mqlAtlassianJira) serverInfos() (*mqlAtlassianJiraServerInfo, error) { jira := conn.Client() info, _, err := jira.Server.Info(context.Background()) if err != nil { - log.Fatal().Err(err) + return nil, err } res, err := CreateResource(a.MqlRuntime, "atlassian.jira.serverInfo", map[string]*llx.RawData{ @@ -128,7 +127,7 @@ func (a *mqlAtlassianJira) projects() ([]interface{}, error) { jira := conn.Client() projects, _, err := jira.Project.Search(context.Background(), nil, 0, 1000) if err != nil { - log.Fatal().Err(err) + return nil, err } res := []interface{}{} @@ -146,7 +145,7 @@ func (a *mqlAtlassianJira) projects() ([]interface{}, error) { "archived": llx.BoolData(project.Archived), }) if err != nil { - log.Fatal().Err(err) + return nil, err } res = append(res, mqlAtlassianJiraProject) } @@ -162,7 +161,7 @@ func (a *mqlAtlassianJira) issues() ([]interface{}, error) { expands := []string{"changelog", "renderedFields", "names", "schema", "transitions", "operations", "editmeta"} issues, _, err := jira.Issue.Search.Get(context.Background(), jql, fields, expands, 0, 1000, validate) if err != nil { - log.Fatal().Err(err) + return nil, err } res := []interface{}{} for _, issue := range issues.Issues { @@ -173,7 +172,7 @@ func (a *mqlAtlassianJira) issues() ([]interface{}, error) { "status": llx.StringData(issue.Fields.Status.Name), }) if err != nil { - log.Fatal().Err(err) + return nil, err } res = append(res, mqlAtlassianJiraIssue) } @@ -189,7 +188,7 @@ func (a *mqlAtlassianJiraProject) properties() ([]interface{}, error) { jira := conn.Client() properties, _, err := jira.Project.Property.Gets(context.Background(), a.Id.Data) if err != nil { - log.Fatal().Err(err) + return nil, err } res := []interface{}{} @@ -200,7 +199,7 @@ func (a *mqlAtlassianJiraProject) properties() ([]interface{}, error) { "id": llx.StringData(property.Key), }) if err != nil { - log.Fatal().Err(err) + return nil, err } res = append(res, mqlAtlassianJiraProjectProperty) } diff --git a/providers/atlassian/resources/atlassian_scim.go b/providers/atlassian/resources/atlassian_scim.go index c5b354b0da..b520ef86d9 100644 --- a/providers/atlassian/resources/atlassian_scim.go +++ b/providers/atlassian/resources/atlassian_scim.go @@ -3,7 +3,6 @@ package resources import ( "context" - "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/llx" "go.mondoo.com/cnquery/v9/providers/atlassian/connection/scim" ) @@ -18,7 +17,7 @@ func (a *mqlAtlassianScim) users() ([]interface{}, error) { directoryID := conn.Directory() scimUsers, _, err := admin.SCIM.User.Gets(context.Background(), directoryID, nil, 0, 1000) if err != nil { - log.Fatal().Err(err) + return nil, err } res := []interface{}{} for _, scimUser := range scimUsers.Resources { @@ -31,7 +30,7 @@ func (a *mqlAtlassianScim) users() ([]interface{}, error) { "title": llx.StringData(scimUser.Title), }) if err != nil { - log.Fatal().Err(err) + return nil, err } res = append(res, mqlAtlassianAdminSCIMuser) } @@ -44,7 +43,7 @@ func (a *mqlAtlassianScim) groups() ([]interface{}, error) { directoryID := conn.Directory() scimGroup, _, err := admin.SCIM.Group.Gets(context.Background(), directoryID, "", 0, 1000) if err != nil { - log.Fatal().Err(err) + return nil, err } res := []interface{}{} for _, scimGroup := range scimGroup.Resources { @@ -53,7 +52,7 @@ func (a *mqlAtlassianScim) groups() ([]interface{}, error) { "id": llx.StringData(scimGroup.ID), }) if err != nil { - log.Fatal().Err(err) + return nil, err } res = append(res, mqlAtlassianAdminSCIMgroup) } From 5d0f02683976d4d1e19b0121cdf7a98935e95fa4 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 10:19:13 +0200 Subject: [PATCH 62/90] clean up --- providers/atlassian/connection/connection.go | 1 - 1 file changed, 1 deletion(-) diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index b9acffa419..2b87491809 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -22,7 +22,6 @@ const ( func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (shared.Connection, error) { var conn shared.Connection var err error - fmt.Println("Product: ", conf.Options["product"]) switch conf.Options["product"] { case "admin": conn, err = admin.NewConnection(id, asset, conf) From 1e62146441a4eca90db6cc60ad8d2df1244f29a9 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 10:25:03 +0200 Subject: [PATCH 63/90] more fields --- providers/atlassian/resources/atlassian.lr | 8 ++++++++ providers/atlassian/resources/atlassian_admin.go | 12 ++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 9d46b2c810..f7e2dc0a02 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -50,6 +50,10 @@ atlassian.admin.organization.managedUsers { name string // Type type string + // Email + email string + // Last active + lastActive string } atlassian.admin.organization.policy @defaults("id") { @@ -68,6 +72,10 @@ atlassian.admin.organization.policy @defaults("id") { atlassian.admin.organization.domain @defaults("id") { // Domain ID id string + // Name + name string + // Type + type string } atlassian.jira { diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index bb11ac427c..5c6c45f887 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -46,9 +46,11 @@ func (a *mqlAtlassianAdminOrganization) managedUsers() ([]interface{}, error) { for _, user := range managedUsers.Data { mqlAtlassianAdminManagedUser, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.managedUser", map[string]*llx.RawData{ - "id": llx.StringData(user.AccountID), - "name": llx.StringData(user.Name), - "type": llx.StringData(user.AccountType), + "id": llx.StringData(user.AccountID), + "name": llx.StringData(user.Name), + "type": llx.StringData(user.AccountType), + "email": llx.StringData(user.Email), + "lastActive": llx.StringData(user.LastActive), }) if err != nil { return nil, err @@ -96,7 +98,9 @@ func (a *mqlAtlassianAdminOrganization) domains() ([]interface{}, error) { for _, domain := range domains.Data { mqlAtlassianAdminDomain, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization.domain", map[string]*llx.RawData{ - "id": llx.StringData(domain.ID), + "id": llx.StringData(domain.ID), + "name": llx.StringData(domain.Attributes.Name), + "type": llx.StringData(domain.Type), }) if err != nil { return nil, err From 878a3a0f3ab0e7faaae3529fc8efc74c100980f1 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 10:27:36 +0200 Subject: [PATCH 64/90] fix formatting --- providers/atlassian/resources/atlassian.lr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index f7e2dc0a02..1904242bff 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -117,9 +117,9 @@ atlassian.jira.user @defaults("id") { // Name name string // Account type - type string + type string // Picture of the user - picture string + picture string // Groups groups() []atlassian.jira.group // Roles From 7accffe371e740657ce6330b501a7569dad9ed4a Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 10:31:03 +0200 Subject: [PATCH 65/90] add name to scim group --- providers/atlassian/resources/atlassian.lr | 2 ++ providers/atlassian/resources/atlassian_scim.go | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 1904242bff..bca8d5d17b 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -28,6 +28,8 @@ atlassian.scim.user @defaults("id") { atlassian.scim.group @defaults("id") { // ID id string + // Name + name string } atlassian.admin.organization @defaults("id") { diff --git a/providers/atlassian/resources/atlassian_scim.go b/providers/atlassian/resources/atlassian_scim.go index b520ef86d9..ba277c7ce0 100644 --- a/providers/atlassian/resources/atlassian_scim.go +++ b/providers/atlassian/resources/atlassian_scim.go @@ -49,7 +49,8 @@ func (a *mqlAtlassianScim) groups() ([]interface{}, error) { for _, scimGroup := range scimGroup.Resources { mqlAtlassianAdminSCIMgroup, err := CreateResource(a.MqlRuntime, "atlassian.scim.organization.scim.group", map[string]*llx.RawData{ - "id": llx.StringData(scimGroup.ID), + "id": llx.StringData(scimGroup.ID), + "name": llx.StringData(scimGroup.DisplayName), }) if err != nil { return nil, err From a1c3842002f96689c6bd7c5d1301e115e062ba85 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 10:48:46 +0200 Subject: [PATCH 66/90] fix platformid --- providers/atlassian/connection/admin/connection.go | 4 ++++ providers/atlassian/connection/admin/platform.go | 10 +++++++++- .../atlassian/connection/confluence/connection.go | 4 ++++ providers/atlassian/connection/confluence/platform.go | 10 +++++++++- providers/atlassian/connection/connection.go | 2 -- providers/atlassian/connection/jira/connection.go | 4 ++++ providers/atlassian/connection/jira/platform.go | 10 +++++++++- providers/atlassian/connection/scim/connection.go | 4 ++++ providers/atlassian/connection/scim/platform.go | 10 +++++++++- providers/atlassian/connection/shared/shared.go | 1 + 10 files changed, 53 insertions(+), 6 deletions(-) diff --git a/providers/atlassian/connection/admin/connection.go b/providers/atlassian/connection/admin/connection.go index b558a5dd95..b4526780a6 100644 --- a/providers/atlassian/connection/admin/connection.go +++ b/providers/atlassian/connection/admin/connection.go @@ -76,3 +76,7 @@ func (c *AdminConnection) Type() shared.ConnectionType { func (c *AdminConnection) Host() string { return c.host } + +func (c *AdminConnection) ConnectionType() string { + return "admin" +} diff --git a/providers/atlassian/connection/admin/platform.go b/providers/atlassian/connection/admin/platform.go index bee2a5387f..892f5614c0 100644 --- a/providers/atlassian/connection/admin/platform.go +++ b/providers/atlassian/connection/admin/platform.go @@ -1,6 +1,10 @@ package admin -import "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" +import ( + "fmt" + + "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" +) func (a *AdminConnection) PlatformInfo() *inventory.Platform { return GetPlatformForObject("atlassian") @@ -22,3 +26,7 @@ func GetPlatformForObject(platformName string) *inventory.Platform { Runtime: "atlassian", } } + +func (a *AdminConnection) PlatformID() string { + return "//platformid.api.mondoo.app/runtime/atlassian/admin/" + fmt.Sprint(a.id) +} diff --git a/providers/atlassian/connection/confluence/connection.go b/providers/atlassian/connection/confluence/connection.go index 194980dfe1..27eef3312a 100644 --- a/providers/atlassian/connection/confluence/connection.go +++ b/providers/atlassian/connection/confluence/connection.go @@ -92,3 +92,7 @@ func (c *ConfluenceConnection) Type() shared.ConnectionType { func (c *ConfluenceConnection) Host() string { return c.host } + +func (c *ConfluenceConnection) ConnectionType() string { + return "confluence" +} diff --git a/providers/atlassian/connection/confluence/platform.go b/providers/atlassian/connection/confluence/platform.go index b92c312885..647ada19be 100644 --- a/providers/atlassian/connection/confluence/platform.go +++ b/providers/atlassian/connection/confluence/platform.go @@ -1,6 +1,10 @@ package confluence -import "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" +import ( + "fmt" + + "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" +) func (a *ConfluenceConnection) PlatformInfo() *inventory.Platform { return GetPlatformForObject("atlassian") @@ -22,3 +26,7 @@ func GetPlatformForObject(platformName string) *inventory.Platform { Runtime: "atlassian", } } + +func (a *ConfluenceConnection) PlatformID() string { + return "//platformid.api.mondoo.app/runtime/atlassian/confluence/" + fmt.Sprint(a.id) +} diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index 2b87491809..1a7e485a62 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -4,8 +4,6 @@ package connection import ( - "fmt" - "github.com/pkg/errors" "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" "go.mondoo.com/cnquery/v9/providers/atlassian/connection/admin" diff --git a/providers/atlassian/connection/jira/connection.go b/providers/atlassian/connection/jira/connection.go index f9abe9e74d..fce92d10f0 100644 --- a/providers/atlassian/connection/jira/connection.go +++ b/providers/atlassian/connection/jira/connection.go @@ -92,3 +92,7 @@ func (p *JiraConnection) Type() shared.ConnectionType { func (c *JiraConnection) Host() string { return c.host } + +func (c *JiraConnection) ConnectionType() string { + return "jira" +} diff --git a/providers/atlassian/connection/jira/platform.go b/providers/atlassian/connection/jira/platform.go index c1076ae647..0df8476bdd 100644 --- a/providers/atlassian/connection/jira/platform.go +++ b/providers/atlassian/connection/jira/platform.go @@ -1,6 +1,10 @@ package jira -import "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" +import ( + "fmt" + + "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" +) func (a *JiraConnection) PlatformInfo() *inventory.Platform { return GetPlatformForObject("atlassian") @@ -22,3 +26,7 @@ func GetPlatformForObject(platformName string) *inventory.Platform { Runtime: "atlassian", } } + +func (a *JiraConnection) PlatformID() string { + return "//platformid.api.mondoo.app/runtime/atlassian/jira/" + fmt.Sprint(a.id) +} diff --git a/providers/atlassian/connection/scim/connection.go b/providers/atlassian/connection/scim/connection.go index 9724bed230..2c6e23a7f1 100644 --- a/providers/atlassian/connection/scim/connection.go +++ b/providers/atlassian/connection/scim/connection.go @@ -84,3 +84,7 @@ func (c *ScimConnection) Host() string { func (c *ScimConnection) Directory() string { return c.Conf.Options["directory-id"] } + +func (c *ScimConnection) ConnectionType() string { + return "scim" +} diff --git a/providers/atlassian/connection/scim/platform.go b/providers/atlassian/connection/scim/platform.go index e60a7a78d6..234e21c56c 100644 --- a/providers/atlassian/connection/scim/platform.go +++ b/providers/atlassian/connection/scim/platform.go @@ -1,6 +1,10 @@ package scim -import "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" +import ( + "fmt" + + "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" +) func (a *ScimConnection) PlatformInfo() *inventory.Platform { return GetPlatformForObject("atlassian") @@ -22,3 +26,7 @@ func GetPlatformForObject(platformName string) *inventory.Platform { Runtime: "atlassian", } } + +func (a *ScimConnection) PlatformID() string { + return "//platformid.api.mondoo.app/runtime/atlassian/scim/" + fmt.Sprint(a.id) +} diff --git a/providers/atlassian/connection/shared/shared.go b/providers/atlassian/connection/shared/shared.go index da81207b9b..cb7618e51f 100644 --- a/providers/atlassian/connection/shared/shared.go +++ b/providers/atlassian/connection/shared/shared.go @@ -16,4 +16,5 @@ type Connection interface { Asset() *inventory.Asset Host() string PlatformInfo() *inventory.Platform + PlatformID() string } From 52e873c66bed880e04fe93482e01c51abf6580eb Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 10:51:40 +0200 Subject: [PATCH 67/90] fixes --- providers/atlassian/provider/provider.go | 3 +- providers/atlassian/resources/atlassian.lr | 2 + providers/atlassian/resources/atlassian.lr.go | 108 ++++++++++++++++++ .../resources/atlassian.lr.manifest.yaml | 9 ++ .../atlassian/resources/atlassian_jira.go | 9 +- 5 files changed, 126 insertions(+), 5 deletions(-) diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index ddf1cbedbc..d3360c48ae 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -2,6 +2,7 @@ package provider import ( "errors" + "fmt" "strconv" "go.mondoo.com/cnquery/v9/llx" @@ -149,7 +150,7 @@ func (s *Service) detect(asset *inventory.Asset, conn shared.Connection) error { asset.Name = conn.Host() asset.Platform = conn.PlatformInfo() - asset.PlatformIds = []string{"//platformid.api.mondoo.app/runtime/atlassian"} + asset.PlatformIds = []string{conn.PlatformID()} return nil } diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index bca8d5d17b..80c0992a7d 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -100,6 +100,8 @@ atlassian.jira.issue @defaults("id") { project string // Status status string + // Description + description string } atlassian.jira.serverInfo @defaults("serverTitle") { diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index f8c0bd9ee9..75a32420d4 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -169,9 +169,24 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.scim.user.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianScimUser).GetId()).ToDataRes(types.String) }, + "atlassian.scim.user.name": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianScimUser).GetName()).ToDataRes(types.String) + }, + "atlassian.scim.user.displayName": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianScimUser).GetDisplayName()).ToDataRes(types.String) + }, + "atlassian.scim.user.organization": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianScimUser).GetOrganization()).ToDataRes(types.String) + }, + "atlassian.scim.user.title": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianScimUser).GetTitle()).ToDataRes(types.String) + }, "atlassian.scim.group.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianScimGroup).GetId()).ToDataRes(types.String) }, + "atlassian.scim.group.name": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianScimGroup).GetName()).ToDataRes(types.String) + }, "atlassian.admin.organization.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganization).GetId()).ToDataRes(types.String) }, @@ -196,6 +211,12 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.managedUsers.type": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationManagedUsers).GetType()).ToDataRes(types.String) }, + "atlassian.admin.organization.managedUsers.email": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationManagedUsers).GetEmail()).ToDataRes(types.String) + }, + "atlassian.admin.organization.managedUsers.lastActive": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationManagedUsers).GetLastActive()).ToDataRes(types.String) + }, "atlassian.admin.organization.policy.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationPolicy).GetId()).ToDataRes(types.String) }, @@ -214,6 +235,12 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.domain.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganizationDomain).GetId()).ToDataRes(types.String) }, + "atlassian.admin.organization.domain.name": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationDomain).GetName()).ToDataRes(types.String) + }, + "atlassian.admin.organization.domain.type": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganizationDomain).GetType()).ToDataRes(types.String) + }, "atlassian.jira.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJira).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.jira.user"))) }, @@ -365,6 +392,22 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianScimUser).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.scim.user.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianScimUser).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.scim.user.displayName": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianScimUser).DisplayName, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.scim.user.organization": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianScimUser).Organization, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.scim.user.title": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianScimUser).Title, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.scim.group.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianScimGroup).__id, ok = v.Value.(string) return @@ -373,6 +416,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianScimGroup).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.scim.group.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianScimGroup).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.admin.organization.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganization).__id, ok = v.Value.(string) return @@ -413,6 +460,14 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganizationManagedUsers).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.admin.organization.managedUsers.email": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationManagedUsers).Email, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.organization.managedUsers.lastActive": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationManagedUsers).LastActive, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.admin.organization.policy.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganizationPolicy).__id, ok = v.Value.(string) return @@ -445,6 +500,14 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganizationDomain).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.admin.organization.domain.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationDomain).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, + "atlassian.admin.organization.domain.type": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganizationDomain).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.jira.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianJira).__id, ok = v.Value.(string) return @@ -802,6 +865,10 @@ type mqlAtlassianScimUser struct { __id string // optional: if you define mqlAtlassianScimUserInternal it will be used here Id plugin.TValue[string] + Name plugin.TValue[string] + DisplayName plugin.TValue[string] + Organization plugin.TValue[string] + Title plugin.TValue[string] } // createAtlassianScimUser creates a new instance of this resource @@ -845,12 +912,29 @@ func (c *mqlAtlassianScimUser) GetId() *plugin.TValue[string] { return &c.Id } +func (c *mqlAtlassianScimUser) GetName() *plugin.TValue[string] { + return &c.Name +} + +func (c *mqlAtlassianScimUser) GetDisplayName() *plugin.TValue[string] { + return &c.DisplayName +} + +func (c *mqlAtlassianScimUser) GetOrganization() *plugin.TValue[string] { + return &c.Organization +} + +func (c *mqlAtlassianScimUser) GetTitle() *plugin.TValue[string] { + return &c.Title +} + // mqlAtlassianScimGroup for the atlassian.scim.group resource type mqlAtlassianScimGroup struct { MqlRuntime *plugin.Runtime __id string // optional: if you define mqlAtlassianScimGroupInternal it will be used here Id plugin.TValue[string] + Name plugin.TValue[string] } // createAtlassianScimGroup creates a new instance of this resource @@ -894,6 +978,10 @@ func (c *mqlAtlassianScimGroup) GetId() *plugin.TValue[string] { return &c.Id } +func (c *mqlAtlassianScimGroup) GetName() *plugin.TValue[string] { + return &c.Name +} + // mqlAtlassianAdminOrganization for the atlassian.admin.organization resource type mqlAtlassianAdminOrganization struct { MqlRuntime *plugin.Runtime @@ -1002,6 +1090,8 @@ type mqlAtlassianAdminOrganizationManagedUsers struct { Id plugin.TValue[string] Name plugin.TValue[string] Type plugin.TValue[string] + Email plugin.TValue[string] + LastActive plugin.TValue[string] } // createAtlassianAdminOrganizationManagedUsers creates a new instance of this resource @@ -1048,6 +1138,14 @@ func (c *mqlAtlassianAdminOrganizationManagedUsers) GetType() *plugin.TValue[str return &c.Type } +func (c *mqlAtlassianAdminOrganizationManagedUsers) GetEmail() *plugin.TValue[string] { + return &c.Email +} + +func (c *mqlAtlassianAdminOrganizationManagedUsers) GetLastActive() *plugin.TValue[string] { + return &c.LastActive +} + // mqlAtlassianAdminOrganizationPolicy for the atlassian.admin.organization.policy resource type mqlAtlassianAdminOrganizationPolicy struct { MqlRuntime *plugin.Runtime @@ -1123,6 +1221,8 @@ type mqlAtlassianAdminOrganizationDomain struct { __id string // optional: if you define mqlAtlassianAdminOrganizationDomainInternal it will be used here Id plugin.TValue[string] + Name plugin.TValue[string] + Type plugin.TValue[string] } // createAtlassianAdminOrganizationDomain creates a new instance of this resource @@ -1161,6 +1261,14 @@ func (c *mqlAtlassianAdminOrganizationDomain) GetId() *plugin.TValue[string] { return &c.Id } +func (c *mqlAtlassianAdminOrganizationDomain) GetName() *plugin.TValue[string] { + return &c.Name +} + +func (c *mqlAtlassianAdminOrganizationDomain) GetType() *plugin.TValue[string] { + return &c.Type +} + // mqlAtlassianJira for the atlassian.jira resource type mqlAtlassianJira struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index bddb442e71..5d1511575b 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -26,6 +26,8 @@ resources: atlassian.admin.organization.domain: fields: id: {} + name: {} + type: {} min_mondoo_version: latest atlassian.admin.organization.event: fields: @@ -33,7 +35,9 @@ resources: min_mondoo_version: latest atlassian.admin.organization.managedUsers: fields: + email: {} id: {} + lastActive: {} name: {} type: {} min_mondoo_version: latest @@ -190,6 +194,7 @@ resources: atlassian.scim.group: fields: id: {} + name: {} min_mondoo_version: latest atlassian.scim.organization: fields: @@ -212,5 +217,9 @@ resources: min_mondoo_version: latest atlassian.scim.user: fields: + displayName: {} id: {} + name: {} + organization: {} + title: {} min_mondoo_version: latest diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index 7faea74879..05cced8305 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -157,7 +157,7 @@ func (a *mqlAtlassianJira) issues() ([]interface{}, error) { jira := conn.Client() validate := "" jql := "order by created DESC" - fields := []string{"status", "project"} + fields := []string{"status", "project", "description"} expands := []string{"changelog", "renderedFields", "names", "schema", "transitions", "operations", "editmeta"} issues, _, err := jira.Issue.Search.Get(context.Background(), jql, fields, expands, 0, 1000, validate) if err != nil { @@ -167,9 +167,10 @@ func (a *mqlAtlassianJira) issues() ([]interface{}, error) { for _, issue := range issues.Issues { mqlAtlassianJiraIssue, err := CreateResource(a.MqlRuntime, "atlassian.jira.issue", map[string]*llx.RawData{ - "id": llx.StringData(issue.ID), - "project": llx.StringData(issue.Fields.Project.Name), - "status": llx.StringData(issue.Fields.Status.Name), + "id": llx.StringData(issue.ID), + "project": llx.StringData(issue.Fields.Project.Name), + "status": llx.StringData(issue.Fields.Status.Name), + "description": llx.StringData(issue.Fields.Description), }) if err != nil { return nil, err From e3df517cfd8bb48c6276cb652620e36e1a4b79b7 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 11:15:53 +0200 Subject: [PATCH 68/90] fix platform id --- providers/atlassian/connection/admin/platform.go | 4 +--- providers/atlassian/connection/confluence/platform.go | 6 ++++-- providers/atlassian/connection/jira/platform.go | 6 ++++-- providers/atlassian/connection/scim/platform.go | 4 +--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/providers/atlassian/connection/admin/platform.go b/providers/atlassian/connection/admin/platform.go index 892f5614c0..94f8c8cf88 100644 --- a/providers/atlassian/connection/admin/platform.go +++ b/providers/atlassian/connection/admin/platform.go @@ -1,8 +1,6 @@ package admin import ( - "fmt" - "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" ) @@ -28,5 +26,5 @@ func GetPlatformForObject(platformName string) *inventory.Platform { } func (a *AdminConnection) PlatformID() string { - return "//platformid.api.mondoo.app/runtime/atlassian/admin/" + fmt.Sprint(a.id) + return "//platformid.api.mondoo.app/runtime/atlassian/admin" } diff --git a/providers/atlassian/connection/confluence/platform.go b/providers/atlassian/connection/confluence/platform.go index 647ada19be..595e21e2ab 100644 --- a/providers/atlassian/connection/confluence/platform.go +++ b/providers/atlassian/connection/confluence/platform.go @@ -1,7 +1,7 @@ package confluence import ( - "fmt" + "strings" "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" ) @@ -28,5 +28,7 @@ func GetPlatformForObject(platformName string) *inventory.Platform { } func (a *ConfluenceConnection) PlatformID() string { - return "//platformid.api.mondoo.app/runtime/atlassian/confluence/" + fmt.Sprint(a.id) + hostname := strings.TrimPrefix(a.host, "https://") + host := strings.Replace(hostname, ".", "-", -1) + return "//platformid.api.mondoo.app/runtime/atlassian/confluence/" + host } diff --git a/providers/atlassian/connection/jira/platform.go b/providers/atlassian/connection/jira/platform.go index 0df8476bdd..59decaf04d 100644 --- a/providers/atlassian/connection/jira/platform.go +++ b/providers/atlassian/connection/jira/platform.go @@ -1,7 +1,7 @@ package jira import ( - "fmt" + "strings" "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" ) @@ -28,5 +28,7 @@ func GetPlatformForObject(platformName string) *inventory.Platform { } func (a *JiraConnection) PlatformID() string { - return "//platformid.api.mondoo.app/runtime/atlassian/jira/" + fmt.Sprint(a.id) + hostname := strings.TrimPrefix(a.host, "https://") + host := strings.Replace(hostname, ".", "-", -1) + return "//platformid.api.mondoo.app/runtime/atlassian/jira/" + host } diff --git a/providers/atlassian/connection/scim/platform.go b/providers/atlassian/connection/scim/platform.go index 234e21c56c..31f6b0f17d 100644 --- a/providers/atlassian/connection/scim/platform.go +++ b/providers/atlassian/connection/scim/platform.go @@ -1,8 +1,6 @@ package scim import ( - "fmt" - "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" ) @@ -28,5 +26,5 @@ func GetPlatformForObject(platformName string) *inventory.Platform { } func (a *ScimConnection) PlatformID() string { - return "//platformid.api.mondoo.app/runtime/atlassian/scim/" + fmt.Sprint(a.id) + return "//platformid.api.mondoo.app/runtime/atlassian/scim" } From d80425d0c457b7768289462da29026dc31305ad5 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 11:20:51 +0200 Subject: [PATCH 69/90] add directoryid to scim platformid --- providers/atlassian/connection/scim/platform.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/atlassian/connection/scim/platform.go b/providers/atlassian/connection/scim/platform.go index 31f6b0f17d..1830ab7235 100644 --- a/providers/atlassian/connection/scim/platform.go +++ b/providers/atlassian/connection/scim/platform.go @@ -26,5 +26,5 @@ func GetPlatformForObject(platformName string) *inventory.Platform { } func (a *ScimConnection) PlatformID() string { - return "//platformid.api.mondoo.app/runtime/atlassian/scim" + return "//platformid.api.mondoo.app/runtime/atlassian/scim/" + a.Directory() } From 20c0ee61776d9cba53b966283d60177a3fbb2f9e Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 12:48:26 +0200 Subject: [PATCH 70/90] working on discovery --- .../atlassian/connection/admin/connection.go | 4 + .../connection/confluence/connection.go | 4 + providers/atlassian/connection/connection.go | 7 ++ .../atlassian/connection/jira/connection.go | 4 + .../atlassian/connection/scim/connection.go | 4 + .../atlassian/connection/shared/shared.go | 1 + providers/atlassian/provider/provider.go | 48 ++++++++-- providers/atlassian/resources/atlassian.lr | 2 + providers/atlassian/resources/atlassian.lr.go | 33 ++++++- .../resources/atlassian.lr.manifest.yaml | 2 + .../atlassian/resources/atlassian_admin.go | 17 ++++ providers/atlassian/resources/discovery.go | 88 +++++++++++++++++++ 12 files changed, 204 insertions(+), 10 deletions(-) create mode 100644 providers/atlassian/resources/discovery.go diff --git a/providers/atlassian/connection/admin/connection.go b/providers/atlassian/connection/admin/connection.go index b4526780a6..4615771361 100644 --- a/providers/atlassian/connection/admin/connection.go +++ b/providers/atlassian/connection/admin/connection.go @@ -80,3 +80,7 @@ func (c *AdminConnection) Host() string { func (c *AdminConnection) ConnectionType() string { return "admin" } + +func (c *AdminConnection) Config() *inventory.Config { + return c.Conf +} diff --git a/providers/atlassian/connection/confluence/connection.go b/providers/atlassian/connection/confluence/connection.go index 27eef3312a..f3f857a6f0 100644 --- a/providers/atlassian/connection/confluence/connection.go +++ b/providers/atlassian/connection/confluence/connection.go @@ -96,3 +96,7 @@ func (c *ConfluenceConnection) Host() string { func (c *ConfluenceConnection) ConnectionType() string { return "confluence" } + +func (c *ConfluenceConnection) Config() *inventory.Config { + return c.Conf +} diff --git a/providers/atlassian/connection/connection.go b/providers/atlassian/connection/connection.go index 1a7e485a62..80184e6dfd 100644 --- a/providers/atlassian/connection/connection.go +++ b/providers/atlassian/connection/connection.go @@ -13,6 +13,13 @@ import ( "go.mondoo.com/cnquery/v9/providers/atlassian/connection/shared" ) +const ( + // Discovery flags + DiscoveryAuto = "auto" + DiscoveryAll = "all" + DiscoveryOrganization = "organization" +) + const ( Admin shared.ConnectionType = "atlassian" ) diff --git a/providers/atlassian/connection/jira/connection.go b/providers/atlassian/connection/jira/connection.go index fce92d10f0..079104749a 100644 --- a/providers/atlassian/connection/jira/connection.go +++ b/providers/atlassian/connection/jira/connection.go @@ -96,3 +96,7 @@ func (c *JiraConnection) Host() string { func (c *JiraConnection) ConnectionType() string { return "jira" } + +func (c *JiraConnection) Config() *inventory.Config { + return c.Conf +} diff --git a/providers/atlassian/connection/scim/connection.go b/providers/atlassian/connection/scim/connection.go index 2c6e23a7f1..8612e1b59a 100644 --- a/providers/atlassian/connection/scim/connection.go +++ b/providers/atlassian/connection/scim/connection.go @@ -88,3 +88,7 @@ func (c *ScimConnection) Directory() string { func (c *ScimConnection) ConnectionType() string { return "scim" } + +func (c *ScimConnection) Config() *inventory.Config { + return c.Conf +} diff --git a/providers/atlassian/connection/shared/shared.go b/providers/atlassian/connection/shared/shared.go index cb7618e51f..f884e6fc29 100644 --- a/providers/atlassian/connection/shared/shared.go +++ b/providers/atlassian/connection/shared/shared.go @@ -17,4 +17,5 @@ type Connection interface { Host() string PlatformInfo() *inventory.Platform PlatformID() string + Config() *inventory.Config } diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index d3360c48ae..eeee1175be 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -2,7 +2,6 @@ package provider import ( "errors" - "fmt" "strconv" "go.mondoo.com/cnquery/v9/llx" @@ -48,10 +47,23 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) } conf := &inventory.Config{ - Type: req.Connector, - Options: map[string]string{}, + Type: req.Connector, + Options: map[string]string{}, + Discover: &inventory.Discovery{}, } + // discovery flags + discoverTargets := []string{} + if x, ok := flags["discover"]; ok && len(x.Array) != 0 { + for i := range x.Array { + entry := string(x.Array[i].Value) + discoverTargets = append(discoverTargets, entry) + } + } else { + discoverTargets = []string{"auto"} + } + conf.Discover = &inventory.Discovery{Targets: discoverTargets} + switch req.Args[0] { case "admin": conf.Options["product"] = req.Args[0] @@ -88,17 +100,22 @@ func (s *Service) Connect(req *plugin.ConnectReq, callback plugin.ProviderCallba } } - inventory := &inventory.Inventory{ - Spec: &inventory.InventorySpec{ - Assets: []*inventory.Asset{req.Asset}, - }, + //inventory := &inventory.Inventory{ + //Spec: &inventory.InventorySpec{ + //Assets: []*inventory.Asset{req.Asset}, + //}, + //} + + inv, err := s.discover(conn) + if err != nil { + return nil, err } return &plugin.ConnectRes{ Id: conn.ID(), Name: conn.Name(), Asset: req.Asset, - Inventory: inventory, + Inventory: inv, }, nil } @@ -209,3 +226,18 @@ func (s *Service) StoreData(req *plugin.StoreReq) (*plugin.StoreRes, error) { func (s *Service) MockConnect(req *plugin.ConnectReq, callback plugin.ProviderCallback) (*plugin.ConnectRes, error) { return nil, errors.New("mock connect not yet implemented") } + +func (s *Service) discover(conn shared.Connection) (*inventory.Inventory, error) { + conf := conn.Config() + if conf.Discover == nil { + return nil, nil + } + + runtime, ok := s.runtimes[conn.ID()] + if !ok { + // no connection found, this should never happen + return nil, errors.New("connection " + strconv.FormatUint(uint64(conn.ID()), 10) + " not found") + } + + return resources.Discover(runtime, conf.Options) +} diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 80c0992a7d..069dfc3fbb 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -35,6 +35,8 @@ atlassian.scim.group @defaults("id") { atlassian.admin.organization @defaults("id") { // Organization ID id string + // Name + name string // Organization type type string // Policies diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 75a32420d4..3a5c908144 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -34,7 +34,7 @@ func init() { Create: createAtlassianScimGroup, }, "atlassian.admin.organization": { - // to override args, implement: initAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Init: initAtlassianAdminOrganization, Create: createAtlassianAdminOrganization, }, "atlassian.admin.organization.managedUsers": { @@ -190,6 +190,9 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.admin.organization.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganization).GetId()).ToDataRes(types.String) }, + "atlassian.admin.organization.name": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianAdminOrganization).GetName()).ToDataRes(types.String) + }, "atlassian.admin.organization.type": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianAdminOrganization).GetType()).ToDataRes(types.String) }, @@ -265,6 +268,9 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ "atlassian.jira.issue.status": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraIssue).GetStatus()).ToDataRes(types.String) }, + "atlassian.jira.issue.description": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraIssue).GetDescription()).ToDataRes(types.String) + }, "atlassian.jira.serverInfo.baseUrl": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraServerInfo).GetBaseUrl()).ToDataRes(types.String) }, @@ -428,6 +434,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianAdminOrganization).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.admin.organization.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianAdminOrganization).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.admin.organization.type": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianAdminOrganization).Type, ok = plugin.RawToTValue[string](v.Value, v.Error) return @@ -548,6 +558,10 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJiraIssue).Status, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, + "atlassian.jira.issue.description": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraIssue).Description, ok = plugin.RawToTValue[string](v.Value, v.Error) + return + }, "atlassian.jira.serverInfo.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianJiraServerInfo).__id, ok = v.Value.(string) return @@ -988,6 +1002,7 @@ type mqlAtlassianAdminOrganization struct { __id string // optional: if you define mqlAtlassianAdminOrganizationInternal it will be used here Id plugin.TValue[string] + Name plugin.TValue[string] Type plugin.TValue[string] Policies plugin.TValue[[]interface{}] Domains plugin.TValue[[]interface{}] @@ -1005,7 +1020,12 @@ func createAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]* return res, err } - // to override __id implement: id() (string, error) + if res.__id == "" { + res.__id, err = res.id() + if err != nil { + return nil, err + } + } if runtime.HasRecording { args, err = runtime.ResourceFromRecording("atlassian.admin.organization", res.__id) @@ -1030,6 +1050,10 @@ func (c *mqlAtlassianAdminOrganization) GetId() *plugin.TValue[string] { return &c.Id } +func (c *mqlAtlassianAdminOrganization) GetName() *plugin.TValue[string] { + return &c.Name +} + func (c *mqlAtlassianAdminOrganization) GetType() *plugin.TValue[string] { return &c.Type } @@ -1406,6 +1430,7 @@ type mqlAtlassianJiraIssue struct { Id plugin.TValue[string] Project plugin.TValue[string] Status plugin.TValue[string] + Description plugin.TValue[string] } // createAtlassianJiraIssue creates a new instance of this resource @@ -1457,6 +1482,10 @@ func (c *mqlAtlassianJiraIssue) GetStatus() *plugin.TValue[string] { return &c.Status } +func (c *mqlAtlassianJiraIssue) GetDescription() *plugin.TValue[string] { + return &c.Description +} + // mqlAtlassianJiraServerInfo for the atlassian.jira.serverInfo resource type mqlAtlassianJiraServerInfo struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 5d1511575b..3d69dc35bc 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -18,6 +18,7 @@ resources: events: {} id: {} managedUsers: {} + name: {} policies: {} scim: {} type: {} @@ -133,6 +134,7 @@ resources: min_mondoo_version: latest atlassian.jira.issue: fields: + description: {} id: {} project: {} status: {} diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index 5c6c45f887..2eeb383009 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -4,6 +4,7 @@ import ( "context" "go.mondoo.com/cnquery/v9/llx" + "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin" "go.mondoo.com/cnquery/v9/providers/atlassian/connection/admin" ) @@ -11,6 +12,17 @@ func (a *mqlAtlassianAdmin) id() (string, error) { return "admin", nil } +func initAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { + if len(args) > 2 { + return args, nil, nil + } + //conn := runtime.Connection.(*admin.AdminConnection) + + //client := conn.Client() + + return args, nil, nil +} + func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*admin.AdminConnection) admin := conn.Client() @@ -23,6 +35,7 @@ func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { mqlAtlassianAdminOrg, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization", map[string]*llx.RawData{ "id": llx.StringData(org.ID), + "name": llx.StringData(org.Attributes.Name), "type": llx.StringData(org.Type), }) if err != nil { @@ -113,3 +126,7 @@ func (a *mqlAtlassianAdminOrganization) domains() ([]interface{}, error) { func (a *mqlAtlassianAdminOrganizationPolicy) id() (string, error) { return a.Id.Data, nil } + +func (a *mqlAtlassianAdminOrganization) id() (string, error) { + return a.Id.Data, nil +} diff --git a/providers/atlassian/resources/discovery.go b/providers/atlassian/resources/discovery.go new file mode 100644 index 0000000000..8d91fcf0f7 --- /dev/null +++ b/providers/atlassian/resources/discovery.go @@ -0,0 +1,88 @@ +package resources + +import ( + "context" + + "go.mondoo.com/cnquery/v9/llx" + "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" + "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection" + "go.mondoo.com/cnquery/v9/providers/atlassian/connection/admin" + "go.mondoo.com/cnquery/v9/utils/stringx" +) + +func Discover(runtime *plugin.Runtime, opts map[string]string) (*inventory.Inventory, error) { + conn := runtime.Connection.(*admin.AdminConnection) + + in := &inventory.Inventory{Spec: &inventory.InventorySpec{ + Assets: []*inventory.Asset{}, + }} + + targets := handleTargets(conn.Conf.Discover.Targets) + list, err := discover(runtime, targets) + if err != nil { + return in, err + } + + in.Spec.Assets = list + return in, nil +} + +func handleTargets(targets []string) []string { + if stringx.Contains(targets, connection.DiscoveryAll) { + return []string{connection.DiscoveryOrganization} + } + return targets +} + +func discover(runtime *plugin.Runtime, targets []string) ([]*inventory.Asset, error) { + conn := runtime.Connection.(*admin.AdminConnection) + assetList := []*inventory.Asset{} + orgAssets, err := org(runtime, "test", conn, targets) + if err != nil { + return nil, err + } + assetList = append(assetList, orgAssets...) + return assetList, nil +} + +func org(runtime *plugin.Runtime, orgName string, conn *admin.AdminConnection, targets []string) ([]*inventory.Asset, error) { + assetList := []*inventory.Asset{} + client := conn.Client() + orgs, _, err := client.Organization.Gets(context.Background(), "") + if err != nil { + return nil, err + } + for _, org := range orgs.Data { + mqlOrg, err := getMqlAtlassianOrg(runtime, org.ID, org.Attributes.Name) + if err != nil { + return nil, err + } + assetList = append(assetList, &inventory.Asset{ + PlatformIds: []string{conn.PlatformID()}, + Name: mqlOrg.Id.Data, + Platform: conn.PlatformInfo(), + Labels: map[string]string{}, + Connections: []*inventory.Config{cloneInventoryConf(conn.Conf)}, + }) + } + return assetList, nil +} + +func getMqlAtlassianOrg(runtime *plugin.Runtime, orgId string, orgName string) (*mqlAtlassianAdminOrganization, error) { + res, err := NewResource(runtime, "atlassian.admin.organization", map[string]*llx.RawData{ + "id": llx.StringData(orgId), + "name": llx.StringData(orgName), + }) + if err != nil { + return nil, err + } + return res.(*mqlAtlassianAdminOrganization), nil +} + +func cloneInventoryConf(invConf *inventory.Config) *inventory.Config { + invConfClone := invConf.Clone() + // We do not want to run discovery again for the already discovered assets + invConfClone.Discover = &inventory.Discovery{} + return invConfClone +} From 2b9e994a5de6b46270665503604cf42f279c2f25 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 13:00:13 +0200 Subject: [PATCH 71/90] return err instead of log.fatal --- providers/atlassian/connection/admin/connection.go | 3 +-- providers/atlassian/connection/confluence/connection.go | 3 +-- providers/atlassian/connection/jira/connection.go | 3 +-- providers/atlassian/connection/scim/connection.go | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/providers/atlassian/connection/admin/connection.go b/providers/atlassian/connection/admin/connection.go index 4615771361..95faf6bcdb 100644 --- a/providers/atlassian/connection/admin/connection.go +++ b/providers/atlassian/connection/admin/connection.go @@ -8,7 +8,6 @@ import ( "os" "github.com/ctreminiom/go-atlassian/admin" - "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" "go.mondoo.com/cnquery/v9/providers/atlassian/connection/shared" ) @@ -36,7 +35,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* client, err := admin.New(nil) if err != nil { - log.Fatal().Err(err) + return nil, err } client.Auth.SetBearerToken(adminToken) diff --git a/providers/atlassian/connection/confluence/connection.go b/providers/atlassian/connection/confluence/connection.go index f3f857a6f0..0dfa137d88 100644 --- a/providers/atlassian/connection/confluence/connection.go +++ b/providers/atlassian/connection/confluence/connection.go @@ -8,7 +8,6 @@ import ( "os" "github.com/ctreminiom/go-atlassian/confluence" - "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" "go.mondoo.com/cnquery/v9/providers/atlassian/connection/shared" ) @@ -52,7 +51,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* client, err := confluence.New(nil, host) if err != nil { - log.Fatal().Err(err) + return nil, err } client.Auth.SetBasicAuth(user, token) diff --git a/providers/atlassian/connection/jira/connection.go b/providers/atlassian/connection/jira/connection.go index 079104749a..edeedd1440 100644 --- a/providers/atlassian/connection/jira/connection.go +++ b/providers/atlassian/connection/jira/connection.go @@ -8,7 +8,6 @@ import ( "os" v2 "github.com/ctreminiom/go-atlassian/jira/v2" - "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" "go.mondoo.com/cnquery/v9/providers/atlassian/connection/shared" ) @@ -52,7 +51,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* client, err := v2.New(nil, host) if err != nil { - log.Fatal().Err(err) + return nil, err } client.Auth.SetBasicAuth(user, token) diff --git a/providers/atlassian/connection/scim/connection.go b/providers/atlassian/connection/scim/connection.go index 8612e1b59a..c1d4f47439 100644 --- a/providers/atlassian/connection/scim/connection.go +++ b/providers/atlassian/connection/scim/connection.go @@ -8,7 +8,6 @@ import ( "os" "github.com/ctreminiom/go-atlassian/admin" - "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" "go.mondoo.com/cnquery/v9/providers/atlassian/connection/shared" ) @@ -40,7 +39,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* client, err := admin.New(nil) if err != nil { - log.Fatal().Err(err) + return nil, err } client.Auth.SetBearerToken(token) From 41d73b0178365de199745bb82f2ecd08d571138a Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 13:31:26 +0200 Subject: [PATCH 72/90] remove discovery and make user provide org id --- .../atlassian/connection/admin/connection.go | 8 ++ providers/atlassian/provider/provider.go | 46 ++++------ providers/atlassian/resources/atlassian.lr | 4 - providers/atlassian/resources/atlassian.lr.go | 76 ---------------- .../atlassian/resources/atlassian_admin.go | 61 ++++++------- providers/atlassian/resources/discovery.go | 88 ------------------- 6 files changed, 55 insertions(+), 228 deletions(-) delete mode 100644 providers/atlassian/resources/discovery.go diff --git a/providers/atlassian/connection/admin/connection.go b/providers/atlassian/connection/admin/connection.go index 95faf6bcdb..4128e63a03 100644 --- a/providers/atlassian/connection/admin/connection.go +++ b/providers/atlassian/connection/admin/connection.go @@ -38,6 +38,10 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* return nil, err } + if conf.Options["organization-id"] == "" { + return nil, errors.New("you need to provide a organization id for admin") + } + client.Auth.SetBearerToken(adminToken) client.Auth.SetUserAgent("curl/7.54.0") @@ -83,3 +87,7 @@ func (c *AdminConnection) ConnectionType() string { func (c *AdminConnection) Config() *inventory.Config { return c.Conf } + +func (c *AdminConnection) OrgId() string { + return c.Conf.Options["organization-id"] +} diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index eeee1175be..b803c73325 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -37,19 +37,24 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) } if len(req.Args) == 0 { - return nil, errors.New("missing argument, use `atlassian jira`, `atlassian admin`, `atlassian confluence`, or `atlassian scim {directoryID}`") + return nil, errors.New("missing argument, use `atlassian jira`, `atlassian admin {organizationID}`, `atlassian confluence`, or `atlassian scim {directoryID}`") } if req.Args[0] == "scim" { if len(req.Args) != 2 { - return nil, errors.New("missing argument, scim requires a directoryID `atlassian scim {directoryID}`") + return nil, errors.New("missing argument, scim requires a directory id `atlassian scim {directoryID}`") + } + } + + if req.Args[0] == "admin" { + if len(req.Args) != 2 { + return nil, errors.New("missing argument, admin requires an organization id `atlassian scim {organizationID}`") } } conf := &inventory.Config{ - Type: req.Connector, - Options: map[string]string{}, - Discover: &inventory.Discovery{}, + Type: req.Connector, + Options: map[string]string{}, } // discovery flags @@ -67,6 +72,7 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) switch req.Args[0] { case "admin": conf.Options["product"] = req.Args[0] + conf.Options["organization-id"] = req.Args[1] case "jira": conf.Options["product"] = req.Args[0] case "confluence": @@ -100,22 +106,17 @@ func (s *Service) Connect(req *plugin.ConnectReq, callback plugin.ProviderCallba } } - //inventory := &inventory.Inventory{ - //Spec: &inventory.InventorySpec{ - //Assets: []*inventory.Asset{req.Asset}, - //}, - //} - - inv, err := s.discover(conn) - if err != nil { - return nil, err + inventory := &inventory.Inventory{ + Spec: &inventory.InventorySpec{ + Assets: []*inventory.Asset{req.Asset}, + }, } return &plugin.ConnectRes{ Id: conn.ID(), Name: conn.Name(), Asset: req.Asset, - Inventory: inv, + Inventory: inventory, }, nil } @@ -226,18 +227,3 @@ func (s *Service) StoreData(req *plugin.StoreReq) (*plugin.StoreRes, error) { func (s *Service) MockConnect(req *plugin.ConnectReq, callback plugin.ProviderCallback) (*plugin.ConnectRes, error) { return nil, errors.New("mock connect not yet implemented") } - -func (s *Service) discover(conn shared.Connection) (*inventory.Inventory, error) { - conf := conn.Config() - if conf.Discover == nil { - return nil, nil - } - - runtime, ok := s.runtimes[conn.ID()] - if !ok { - // no connection found, this should never happen - return nil, errors.New("connection " + strconv.FormatUint(uint64(conn.ID()), 10) + " not found") - } - - return resources.Discover(runtime, conf.Options) -} diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index 069dfc3fbb..e60d796d3e 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -1,10 +1,6 @@ option provider = "go.mondoo.com/cnquery/providers/atlassian" option go_package = "go.mondoo.com/cnquery/providers/atlassian/resources" -atlassian.admin { - organizations() []atlassian.admin.organization -} - atlassian.scim { // SCIM users users() []atlassian.scim.organization.scim.user diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 3a5c908144..8406739c88 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -17,10 +17,6 @@ var resourceFactories map[string]plugin.ResourceFactory func init() { resourceFactories = map[string]plugin.ResourceFactory { - "atlassian.admin": { - // to override args, implement: initAtlassianAdmin(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) - Create: createAtlassianAdmin, - }, "atlassian.scim": { // to override args, implement: initAtlassianScim(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianScim, @@ -157,9 +153,6 @@ func CreateResource(runtime *plugin.Runtime, name string, args map[string]*llx.R } var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ - "atlassian.admin.organizations": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianAdmin).GetOrganizations()).ToDataRes(types.Array(types.Resource("atlassian.admin.organization"))) - }, "atlassian.scim.users": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianScim).GetUsers()).ToDataRes(types.Array(types.Resource("atlassian.scim.organization.scim.user"))) }, @@ -370,14 +363,6 @@ func GetData(resource plugin.Resource, field string, args map[string]*llx.RawDat } var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { - "atlassian.admin.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdmin).__id, ok = v.Value.(string) - return - }, - "atlassian.admin.organizations": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianAdmin).Organizations, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) - return - }, "atlassian.scim.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { r.(*mqlAtlassianScim).__id, ok = v.Value.(string) return @@ -734,67 +719,6 @@ func SetAllData(resource plugin.Resource, args map[string]*llx.RawData) error { return nil } -// mqlAtlassianAdmin for the atlassian.admin resource -type mqlAtlassianAdmin struct { - MqlRuntime *plugin.Runtime - __id string - // optional: if you define mqlAtlassianAdminInternal it will be used here - Organizations plugin.TValue[[]interface{}] -} - -// createAtlassianAdmin creates a new instance of this resource -func createAtlassianAdmin(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { - res := &mqlAtlassianAdmin{ - MqlRuntime: runtime, - } - - err := SetAllData(res, args) - if err != nil { - return res, err - } - - if res.__id == "" { - res.__id, err = res.id() - if err != nil { - return nil, err - } - } - - if runtime.HasRecording { - args, err = runtime.ResourceFromRecording("atlassian.admin", res.__id) - if err != nil || args == nil { - return res, err - } - return res, SetAllData(res, args) - } - - return res, nil -} - -func (c *mqlAtlassianAdmin) MqlName() string { - return "atlassian.admin" -} - -func (c *mqlAtlassianAdmin) MqlID() string { - return c.__id -} - -func (c *mqlAtlassianAdmin) GetOrganizations() *plugin.TValue[[]interface{}] { - return plugin.GetOrCompute[[]interface{}](&c.Organizations, func() ([]interface{}, error) { - if c.MqlRuntime.HasRecording { - d, err := c.MqlRuntime.FieldResourceFromRecording("atlassian.admin", c.__id, "organizations") - if err != nil { - return nil, err - } - if d != nil { - return d.Value.([]interface{}), nil - } - } - - return c.organizations() - }) -} - // mqlAtlassianScim for the atlassian.scim resource type mqlAtlassianScim struct { MqlRuntime *plugin.Runtime diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index 2eeb383009..daa2841205 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -8,43 +8,44 @@ import ( "go.mondoo.com/cnquery/v9/providers/atlassian/connection/admin" ) -func (a *mqlAtlassianAdmin) id() (string, error) { - return "admin", nil -} - func initAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { - if len(args) > 2 { - return args, nil, nil + conn := runtime.Connection.(*admin.AdminConnection) + admin := conn.Client() + orgId := conn.OrgId() + organization, _, err := admin.Organization.Get(context.Background(), orgId) + if err != nil { + return nil, nil, err } - //conn := runtime.Connection.(*admin.AdminConnection) - //client := conn.Client() + args["id"] = llx.StringData(organization.Data.ID) + args["name"] = llx.StringData(organization.Data.Attributes.Name) + args["type"] = llx.StringData(organization.Data.Type) return args, nil, nil } -func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*admin.AdminConnection) - admin := conn.Client() - organizations, _, err := admin.Organization.Gets(context.Background(), "") - if err != nil { - return nil, err - } - res := []interface{}{} - for _, org := range organizations.Data { - mqlAtlassianAdminOrg, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization", - map[string]*llx.RawData{ - "id": llx.StringData(org.ID), - "name": llx.StringData(org.Attributes.Name), - "type": llx.StringData(org.Type), - }) - if err != nil { - return nil, err - } - res = append(res, mqlAtlassianAdminOrg) - } - return res, nil -} +//func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { +// conn := a.MqlRuntime.Connection.(*admin.AdminConnection) +// admin := conn.Client() +// organizations, _, err := admin.Organization.Gets(context.Background(), "") +// if err != nil { +// return nil, err +// } +// res := []interface{}{} +// for _, org := range organizations.Data { +// mqlAtlassianAdminOrg, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization", +// map[string]*llx.RawData{ +// "id": llx.StringData(org.ID), +// "name": llx.StringData(org.Attributes.Name), +// "type": llx.StringData(org.Type), +// }) +// if err != nil { +// return nil, err +// } +// res = append(res, mqlAtlassianAdminOrg) +// } +// return res, nil +//} func (a *mqlAtlassianAdminOrganization) managedUsers() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*admin.AdminConnection) diff --git a/providers/atlassian/resources/discovery.go b/providers/atlassian/resources/discovery.go deleted file mode 100644 index 8d91fcf0f7..0000000000 --- a/providers/atlassian/resources/discovery.go +++ /dev/null @@ -1,88 +0,0 @@ -package resources - -import ( - "context" - - "go.mondoo.com/cnquery/v9/llx" - "go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" - "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin" - "go.mondoo.com/cnquery/v9/providers/atlassian/connection" - "go.mondoo.com/cnquery/v9/providers/atlassian/connection/admin" - "go.mondoo.com/cnquery/v9/utils/stringx" -) - -func Discover(runtime *plugin.Runtime, opts map[string]string) (*inventory.Inventory, error) { - conn := runtime.Connection.(*admin.AdminConnection) - - in := &inventory.Inventory{Spec: &inventory.InventorySpec{ - Assets: []*inventory.Asset{}, - }} - - targets := handleTargets(conn.Conf.Discover.Targets) - list, err := discover(runtime, targets) - if err != nil { - return in, err - } - - in.Spec.Assets = list - return in, nil -} - -func handleTargets(targets []string) []string { - if stringx.Contains(targets, connection.DiscoveryAll) { - return []string{connection.DiscoveryOrganization} - } - return targets -} - -func discover(runtime *plugin.Runtime, targets []string) ([]*inventory.Asset, error) { - conn := runtime.Connection.(*admin.AdminConnection) - assetList := []*inventory.Asset{} - orgAssets, err := org(runtime, "test", conn, targets) - if err != nil { - return nil, err - } - assetList = append(assetList, orgAssets...) - return assetList, nil -} - -func org(runtime *plugin.Runtime, orgName string, conn *admin.AdminConnection, targets []string) ([]*inventory.Asset, error) { - assetList := []*inventory.Asset{} - client := conn.Client() - orgs, _, err := client.Organization.Gets(context.Background(), "") - if err != nil { - return nil, err - } - for _, org := range orgs.Data { - mqlOrg, err := getMqlAtlassianOrg(runtime, org.ID, org.Attributes.Name) - if err != nil { - return nil, err - } - assetList = append(assetList, &inventory.Asset{ - PlatformIds: []string{conn.PlatformID()}, - Name: mqlOrg.Id.Data, - Platform: conn.PlatformInfo(), - Labels: map[string]string{}, - Connections: []*inventory.Config{cloneInventoryConf(conn.Conf)}, - }) - } - return assetList, nil -} - -func getMqlAtlassianOrg(runtime *plugin.Runtime, orgId string, orgName string) (*mqlAtlassianAdminOrganization, error) { - res, err := NewResource(runtime, "atlassian.admin.organization", map[string]*llx.RawData{ - "id": llx.StringData(orgId), - "name": llx.StringData(orgName), - }) - if err != nil { - return nil, err - } - return res.(*mqlAtlassianAdminOrganization), nil -} - -func cloneInventoryConf(invConf *inventory.Config) *inventory.Config { - invConfClone := invConf.Clone() - // We do not want to run discovery again for the already discovered assets - invConfClone.Discover = &inventory.Discovery{} - return invConfClone -} From c80c9bd124b09baf8fa2925fb82aacb52bf1d030 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 13:36:51 +0200 Subject: [PATCH 73/90] clean up --- .../atlassian/connection/admin/connection.go | 8 ---- providers/atlassian/provider/provider.go | 9 +---- .../atlassian/resources/atlassian_admin.go | 38 +++++-------------- 3 files changed, 11 insertions(+), 44 deletions(-) diff --git a/providers/atlassian/connection/admin/connection.go b/providers/atlassian/connection/admin/connection.go index 4128e63a03..95faf6bcdb 100644 --- a/providers/atlassian/connection/admin/connection.go +++ b/providers/atlassian/connection/admin/connection.go @@ -38,10 +38,6 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* return nil, err } - if conf.Options["organization-id"] == "" { - return nil, errors.New("you need to provide a organization id for admin") - } - client.Auth.SetBearerToken(adminToken) client.Auth.SetUserAgent("curl/7.54.0") @@ -87,7 +83,3 @@ func (c *AdminConnection) ConnectionType() string { func (c *AdminConnection) Config() *inventory.Config { return c.Conf } - -func (c *AdminConnection) OrgId() string { - return c.Conf.Options["organization-id"] -} diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index b803c73325..bfdcc8875e 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -37,7 +37,7 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) } if len(req.Args) == 0 { - return nil, errors.New("missing argument, use `atlassian jira`, `atlassian admin {organizationID}`, `atlassian confluence`, or `atlassian scim {directoryID}`") + return nil, errors.New("missing argument, use `atlassian jira`, `atlassian admin`, `atlassian confluence`, or `atlassian scim {directoryID}`") } if req.Args[0] == "scim" { @@ -46,12 +46,6 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) } } - if req.Args[0] == "admin" { - if len(req.Args) != 2 { - return nil, errors.New("missing argument, admin requires an organization id `atlassian scim {organizationID}`") - } - } - conf := &inventory.Config{ Type: req.Connector, Options: map[string]string{}, @@ -72,7 +66,6 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) switch req.Args[0] { case "admin": conf.Options["product"] = req.Args[0] - conf.Options["organization-id"] = req.Args[1] case "jira": conf.Options["product"] = req.Args[0] case "confluence": diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index daa2841205..c80689355e 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -2,6 +2,7 @@ package resources import ( "context" + "errors" "go.mondoo.com/cnquery/v9/llx" "go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin" @@ -11,42 +12,23 @@ import ( func initAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { conn := runtime.Connection.(*admin.AdminConnection) admin := conn.Client() - orgId := conn.OrgId() - organization, _, err := admin.Organization.Get(context.Background(), orgId) + organization, _, err := admin.Organization.Gets(context.Background(), "") if err != nil { return nil, nil, err } - args["id"] = llx.StringData(organization.Data.ID) - args["name"] = llx.StringData(organization.Data.Attributes.Name) - args["type"] = llx.StringData(organization.Data.Type) + if len(organization.Data) > 1 { + return nil, nil, errors.New("Unexpectedly received more than 1 organization") + } + org := organization.Data[0] + + args["id"] = llx.StringData(org.ID) + args["name"] = llx.StringData(org.Attributes.Name) + args["type"] = llx.StringData(org.Type) return args, nil, nil } -//func (a *mqlAtlassianAdmin) organizations() ([]interface{}, error) { -// conn := a.MqlRuntime.Connection.(*admin.AdminConnection) -// admin := conn.Client() -// organizations, _, err := admin.Organization.Gets(context.Background(), "") -// if err != nil { -// return nil, err -// } -// res := []interface{}{} -// for _, org := range organizations.Data { -// mqlAtlassianAdminOrg, err := CreateResource(a.MqlRuntime, "atlassian.admin.organization", -// map[string]*llx.RawData{ -// "id": llx.StringData(org.ID), -// "name": llx.StringData(org.Attributes.Name), -// "type": llx.StringData(org.Type), -// }) -// if err != nil { -// return nil, err -// } -// res = append(res, mqlAtlassianAdminOrg) -// } -// return res, nil -//} - func (a *mqlAtlassianAdminOrganization) managedUsers() ([]interface{}, error) { conn := a.MqlRuntime.Connection.(*admin.AdminConnection) From 347ef01066bcb811cfa71476ddaf9ea4200d60e0 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 13:38:08 +0200 Subject: [PATCH 74/90] add docs --- providers/atlassian/resources/atlassian_admin.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index c80689355e..2555ab9e04 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -17,6 +17,8 @@ func initAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*ll return nil, nil, err } + // We should only ever receive one organization that is scoped to the api key + // https://community.atlassian.com/t5/Atlassian-Access-questions/Can-we-access-multiple-organisations-using-one-API-Token/qaq-p/1541337 if len(organization.Data) > 1 { return nil, nil, errors.New("Unexpectedly received more than 1 organization") } From 29748d7693ea4878dd53aa061746d996dd16ba56 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 13:44:10 +0200 Subject: [PATCH 75/90] add docs --- providers/atlassian/resources/atlassian.lr | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index e60d796d3e..a29c53a671 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -1,6 +1,7 @@ option provider = "go.mondoo.com/cnquery/providers/atlassian" option go_package = "go.mondoo.com/cnquery/providers/atlassian/resources" +// Cross-domain Identity Management (SCIM) atlassian.scim { // SCIM users users() []atlassian.scim.organization.scim.user @@ -8,6 +9,7 @@ atlassian.scim { groups() []atlassian.scim.organization.scim.group } +// SCIM user atlassian.scim.user @defaults("id") { // ID id string @@ -21,6 +23,7 @@ atlassian.scim.user @defaults("id") { title string } +// SCIM group atlassian.scim.group @defaults("id") { // ID id string @@ -28,6 +31,7 @@ atlassian.scim.group @defaults("id") { name string } +// Organization atlassian.admin.organization @defaults("id") { // Organization ID id string @@ -43,6 +47,7 @@ atlassian.admin.organization @defaults("id") { managedUsers() []atlassian.admin.organization.managedUsers } +// Managed users atlassian.admin.organization.managedUsers { // ID id string @@ -56,6 +61,7 @@ atlassian.admin.organization.managedUsers { lastActive string } +// Policies (except authentication policies) atlassian.admin.organization.policy @defaults("id") { // Policy ID id string @@ -69,6 +75,7 @@ atlassian.admin.organization.policy @defaults("id") { status string } +// Domains atlassian.admin.organization.domain @defaults("id") { // Domain ID id string @@ -78,6 +85,7 @@ atlassian.admin.organization.domain @defaults("id") { type string } +// Jira atlassian.jira { // Jira users users() []atlassian.jira.user @@ -91,6 +99,7 @@ atlassian.jira { serverInfos() atlassian.jira.serverInfo } +// Issue atlassian.jira.issue @defaults("id") { // ID id string @@ -102,6 +111,7 @@ atlassian.jira.issue @defaults("id") { description string } +// Jira server info atlassian.jira.serverInfo @defaults("serverTitle") { // BaseUrl baseUrl string @@ -113,6 +123,7 @@ atlassian.jira.serverInfo @defaults("serverTitle") { deploymentType string } +// Jira user atlassian.jira.user @defaults("id") { // AccountID id string @@ -129,6 +140,7 @@ atlassian.jira.user @defaults("id") { } +// Jira application role atlassian.jira.applicatonRole @defaults("id") { // Role ID id string @@ -136,6 +148,7 @@ atlassian.jira.applicatonRole @defaults("id") { name string } +// Jira project atlassian.jira.project @defaults("id") { // Project ID id string @@ -159,11 +172,13 @@ atlassian.jira.project @defaults("id") { properties() []atlassian.jira.project.property } +// Jira project property atlassian.jira.project.property @defaults("id") { // Property Key id string } +// Jira group atlassian.jira.group @defaults("id") { // GroupID id string @@ -171,11 +186,13 @@ atlassian.jira.group @defaults("id") { name string } +// Confluence atlassian.confluence { // Confluence users users() []atlassian.confluence.user } +// Confluence user atlassian.confluence.user @defaults("id") { // AccountID id string From 4969478afff85ab398f4eda890a5bc4ea63090f4 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 13:48:07 +0200 Subject: [PATCH 76/90] better defaults --- providers/atlassian/resources/atlassian.lr | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index a29c53a671..cffce493cd 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -10,7 +10,7 @@ atlassian.scim { } // SCIM user -atlassian.scim.user @defaults("id") { +atlassian.scim.user @defaults("displayName") { // ID id string // Name @@ -24,7 +24,7 @@ atlassian.scim.user @defaults("id") { } // SCIM group -atlassian.scim.group @defaults("id") { +atlassian.scim.group @defaults("name") { // ID id string // Name @@ -32,7 +32,7 @@ atlassian.scim.group @defaults("id") { } // Organization -atlassian.admin.organization @defaults("id") { +atlassian.admin.organization @defaults("name") { // Organization ID id string // Name @@ -48,7 +48,7 @@ atlassian.admin.organization @defaults("id") { } // Managed users -atlassian.admin.organization.managedUsers { +atlassian.admin.organization.managedUsers @defaults("name") { // ID id string // Name @@ -62,7 +62,7 @@ atlassian.admin.organization.managedUsers { } // Policies (except authentication policies) -atlassian.admin.organization.policy @defaults("id") { +atlassian.admin.organization.policy @defaults("name") { // Policy ID id string // Policy type @@ -76,7 +76,7 @@ atlassian.admin.organization.policy @defaults("id") { } // Domains -atlassian.admin.organization.domain @defaults("id") { +atlassian.admin.organization.domain @defaults("name") { // Domain ID id string // Name @@ -124,7 +124,7 @@ atlassian.jira.serverInfo @defaults("serverTitle") { } // Jira user -atlassian.jira.user @defaults("id") { +atlassian.jira.user @defaults("name") { // AccountID id string // Name @@ -141,7 +141,7 @@ atlassian.jira.user @defaults("id") { // Jira application role -atlassian.jira.applicatonRole @defaults("id") { +atlassian.jira.applicatonRole @defaults("name") { // Role ID id string // Role Name @@ -149,7 +149,7 @@ atlassian.jira.applicatonRole @defaults("id") { } // Jira project -atlassian.jira.project @defaults("id") { +atlassian.jira.project @defaults("name") { // Project ID id string // Project Name @@ -179,7 +179,7 @@ atlassian.jira.project.property @defaults("id") { } // Jira group -atlassian.jira.group @defaults("id") { +atlassian.jira.group @defaults("name") { // GroupID id string // Group Name @@ -193,7 +193,7 @@ atlassian.confluence { } // Confluence user -atlassian.confluence.user @defaults("id") { +atlassian.confluence.user @defaults("name") { // AccountID id string // Name From bd76e1c3bb7d21e01dfc76f6ee440de134652b16 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 14:55:09 +0200 Subject: [PATCH 77/90] fix makefile --- Makefile | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 1720d39241..2248eb00bc 100644 --- a/Makefile +++ b/Makefile @@ -211,6 +211,7 @@ providers/install: \ providers/install/k8s \ providers/install/azure \ providers/install/ms365 \ + providers/install/atlassian \ providers/install/aws providers/build/mock: providers/lr @@ -316,6 +317,8 @@ providers/install/aws: providers/build/atlassian: providers/lr @$(call buildProvider, providers/atlassian) +providers/install/atlassian: + @$(call installProvider, providers/atlassian) providers/build/ms365: providers/lr @$(call buildProvider, providers/ms365) @@ -345,30 +348,6 @@ providers/dist: @$(call buildProviderDist, providers/aws) @$(call buildProviderDist, providers/atlassian) -providers/install: -# @$(call installProvider, providers/core) - @$(call installProvider, providers/network) - @$(call installProvider, providers/os) - @$(call installProvider, providers/ipmi) - @$(call installProvider, providers/oci) - @$(call installProvider, providers/slack) - @$(call installProvider, providers/github) - @$(call installProvider, providers/gitlab) - @$(call installProvider, providers/terraform) - @$(call installProvider, providers/vsphere) - @$(call installProvider, providers/opcua) - @$(call installProvider, providers/okta) - @$(call installProvider, providers/google-workspace) - @$(call installProvider, providers/arista) - @$(call installProvider, providers/equinix) - @$(call installProvider, providers/vcd) - @$(call installProvider, providers/gcp) - @$(call installProvider, providers/k8s) - @$(call installProvider, providers/azure) - @$(call installProvider, providers/ms365) - @$(call installProvider, providers/aws) - @$(call installProvider, providers/atlassian) - providers/bundle: @$(call bundleProvider, providers/network) @$(call bundleProvider, providers/os) From 6e556bf5f669d67d93461bace4e53e23c0abf003 Mon Sep 17 00:00:00 2001 From: Ivan Milchev Date: Mon, 16 Oct 2023 16:05:58 +0300 Subject: [PATCH 78/90] fix provider build Signed-off-by: Ivan Milchev --- providers/atlassian/go.mod | 24 ++++++++------- providers/atlassian/go.sum | 50 ++++++++++++++++++++----------- providers/github/go.mod | 2 +- providers/github/go.sum | 5 ++-- providers/google-workspace/go.mod | 2 +- providers/google-workspace/go.sum | 5 ++-- 6 files changed, 53 insertions(+), 35 deletions(-) diff --git a/providers/atlassian/go.mod b/providers/atlassian/go.mod index a2d02a1f58..910814ee86 100644 --- a/providers/atlassian/go.mod +++ b/providers/atlassian/go.mod @@ -1,11 +1,15 @@ module go.mondoo.com/cnquery/v9/providers/atlassian -go 1.20 +replace go.mondoo.com/cnquery/v9 => ../.. + +go 1.21 + +toolchain go1.21.3 require ( github.com/ctreminiom/go-atlassian v1.5.1 - github.com/rs/zerolog v1.31.0 - go.mondoo.com/cnquery/v9 v9.0.1 + github.com/pkg/errors v0.9.1 + go.mondoo.com/cnquery/v9 v9.1.0 ) require ( @@ -15,7 +19,7 @@ require ( github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/fatih/color v1.15.0 // indirect - github.com/getsentry/sentry-go v0.24.1 // indirect + github.com/getsentry/sentry-go v0.25.0 // indirect github.com/gofrs/uuid v4.4.0+incompatible // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect @@ -40,9 +44,9 @@ require ( github.com/muesli/termenv v0.15.2 // indirect github.com/oklog/run v1.1.0 // indirect github.com/perimeterx/marshmallow v1.1.5 // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/rivo/uniseg v0.4.4 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect + github.com/rs/zerolog v1.31.0 // indirect github.com/segmentio/fasthash v1.0.3 // indirect github.com/segmentio/ksuid v1.0.4 // indirect github.com/smarty/assertions v1.15.1 // indirect @@ -51,12 +55,12 @@ require ( github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect go.mondoo.com/ranger-rpc v0.5.1 // indirect - golang.org/x/crypto v0.13.0 // indirect - golang.org/x/net v0.15.0 // indirect - golang.org/x/sys v0.12.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/sys v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 // indirect - google.golang.org/grpc v1.58.2 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231009173412-8bfb1ae86b6c // indirect + google.golang.org/grpc v1.58.3 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/square/go-jose.v2 v2.6.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/providers/atlassian/go.sum b/providers/atlassian/go.sum index 0b2b9005c9..7768d463d5 100644 --- a/providers/atlassian/go.sum +++ b/providers/atlassian/go.sum @@ -43,6 +43,7 @@ github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF0 github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= +github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= @@ -62,8 +63,9 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/ctreminiom/go-atlassian v1.5.1 h1:GYji33ywQyWvePNQzxfvgb02fg6fcSH1g59vDy3ApEw= github.com/ctreminiom/go-atlassian v1.5.1/go.mod h1:R1EaOjo33pSN9Y6xIJCEgQ68wgwYoFYAXifnaPlmyc8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -73,16 +75,20 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= -github.com/getsentry/sentry-go v0.24.1 h1:W6/0GyTy8J6ge6lVCc94WB6Gx2ZuLrgopnn9w8Hiwuk= -github.com/getsentry/sentry-go v0.24.1/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= +github.com/getsentry/sentry-go v0.25.0 h1:q6Eo+hS+yoJlTO3uu/azhQadsD8V+jQn2D8VvX1eOyI= +github.com/getsentry/sentry-go v0.25.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/go-errors/errors v1.5.0 h1:/EuijeGOu7ckFxzhkj4CXJ8JaenxK7bKUxpPYqeLHqQ= +github.com/go-errors/errors v1.5.0/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= +github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= @@ -130,7 +136,8 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -168,6 +175,7 @@ github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1: github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= +github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= @@ -208,12 +216,14 @@ github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DV github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s= github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= +github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= @@ -232,12 +242,14 @@ github.com/segmentio/ksuid v1.0.4/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O github.com/smarty/assertions v1.15.1 h1:812oFiXI+G55vxsFf+8bIZ1ux30qtkdqzKbEFwyX3Tk= github.com/smarty/assertions v1.15.1/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec= github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY= +github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60= github.com/spf13/afero v1.10.0 h1:EaGW2JJh15aKOejeuJ+wpFSHnbd7GE6Wvp3TsNhb6LY= github.com/spf13/afero v1.10.0/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.1 h1:4VhoImhV/Bm0ToFkXFi8hXNXwpDRZ/ynw3amt82mzq0= +github.com/stretchr/objx v0.5.1/go.mod h1:/iHQpkQwBD6DLUmQ4pE+s1TXdob1mORJ4/UFdrifcy0= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -260,8 +272,6 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.mondoo.com/cnquery/v9 v9.0.1 h1:bbQ4ufIf2OluZlCPYz13JjsHuDav28kG3Lw2X4iOXlM= -go.mondoo.com/cnquery/v9 v9.0.1/go.mod h1:z5QWUfNdvmjclRPcXjZBQID2/o2ivYiRCF8+3HE6dLc= go.mondoo.com/ranger-rpc v0.5.1 h1:OaVQntDJWDRgbc9nXBP4wOCR9h9Bij8LgHHs86IguGk= go.mondoo.com/ranger-rpc v0.5.1/go.mod h1:3YKcqFrlPgaB4FZ4EoLgdmRtwMQdO7RoAkZYFn+F1eY= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= @@ -271,8 +281,11 @@ go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs= +go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY= go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE= +go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8= go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg= +go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -280,8 +293,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -347,8 +360,8 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -409,10 +422,12 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= +golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -541,8 +556,8 @@ google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13 h1:N3bU/SQDCDyD6R528GJ/PwW9KjYcJA3dgyH+MovAkIM= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230920204549-e6e6cdab5c13/go.mod h1:KSqppvjFjtoCI+KGd4PELB0qLNxdJHRGqRI09mB6pQA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231009173412-8bfb1ae86b6c h1:jHkCUWkseRf+W+edG5hMzr/Uh1xkDREY4caybAq4dpY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231009173412-8bfb1ae86b6c/go.mod h1:4cYg8o5yUbm77w8ZX00LhMVNl/YVBFJRYWDc0uYWMs0= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -559,8 +574,8 @@ google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8= google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= -google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= -google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= +google.golang.org/grpc v1.58.3 h1:BjnpXut1btbtgN/6sp+brB2Kbm2LjNXnidYujAVbSoQ= +google.golang.org/grpc v1.58.3/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -578,6 +593,7 @@ google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI= gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= diff --git a/providers/github/go.mod b/providers/github/go.mod index f2145e5a12..d9ff26113f 100644 --- a/providers/github/go.mod +++ b/providers/github/go.mod @@ -33,7 +33,7 @@ require ( github.com/OpenPeeDeeP/depguard/v2 v2.1.0 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c // indirect github.com/StackExchange/wmi v1.2.1 // indirect - github.com/alecthomas/participle v0.7.1 // indirect + github.com/alecthomas/participle v0.3.0 // indirect github.com/alecthomas/participle/v2 v2.1.0 // indirect github.com/alexkohler/nakedret/v2 v2.0.2 // indirect github.com/alexkohler/prealloc v1.0.0 // indirect diff --git a/providers/github/go.sum b/providers/github/go.sum index 034b2fdce0..1fbe7827ed 100644 --- a/providers/github/go.sum +++ b/providers/github/go.sum @@ -70,11 +70,10 @@ github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDO github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= github.com/alecthomas/assert/v2 v2.3.0 h1:mAsH2wmvjsuvyBvAmCtm7zFsBlb8mIHx5ySLVdDZXL0= github.com/alecthomas/assert/v2 v2.3.0/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= -github.com/alecthomas/participle v0.7.1 h1:2bN7reTw//5f0cugJcTOnY/NYZcWQOaajW+BwZB5xWs= -github.com/alecthomas/participle v0.7.1/go.mod h1:HfdmEuwvr12HXQN44HPWXR0lHmVolVYe4dyL6lQ3duY= +github.com/alecthomas/participle v0.3.0 h1:e8vhrYR1nDjzDxyDwpLO27TWOYWilaT+glkwbPadj50= +github.com/alecthomas/participle v0.3.0/go.mod h1:SW6HZGeZgSIpcUWX3fXpfZhuaWHnmoD5KCVaqSaNTkk= github.com/alecthomas/participle/v2 v2.1.0 h1:z7dElHRrOEEq45F2TG5cbQihMtNTv8vwldytDj7Wrz4= github.com/alecthomas/participle/v2 v2.1.0/go.mod h1:Y1+hAs8DHPmc3YUFzqllV+eSQ9ljPTk0ZkPMtEdAx2c= -github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ= github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk= github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/providers/google-workspace/go.mod b/providers/google-workspace/go.mod index 41ea8e06f3..291f5536b8 100644 --- a/providers/google-workspace/go.mod +++ b/providers/google-workspace/go.mod @@ -36,7 +36,7 @@ require ( github.com/OpenPeeDeeP/depguard/v2 v2.1.0 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c // indirect github.com/StackExchange/wmi v1.2.1 // indirect - github.com/alecthomas/participle v0.7.1 // indirect + github.com/alecthomas/participle v0.3.0 // indirect github.com/alecthomas/participle/v2 v2.1.0 // indirect github.com/alexkohler/nakedret/v2 v2.0.2 // indirect github.com/alexkohler/prealloc v1.0.0 // indirect diff --git a/providers/google-workspace/go.sum b/providers/google-workspace/go.sum index df40f95dc4..4ad2eef485 100644 --- a/providers/google-workspace/go.sum +++ b/providers/google-workspace/go.sum @@ -74,11 +74,10 @@ github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDO github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= github.com/alecthomas/assert/v2 v2.3.0 h1:mAsH2wmvjsuvyBvAmCtm7zFsBlb8mIHx5ySLVdDZXL0= github.com/alecthomas/assert/v2 v2.3.0/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= -github.com/alecthomas/participle v0.7.1 h1:2bN7reTw//5f0cugJcTOnY/NYZcWQOaajW+BwZB5xWs= -github.com/alecthomas/participle v0.7.1/go.mod h1:HfdmEuwvr12HXQN44HPWXR0lHmVolVYe4dyL6lQ3duY= +github.com/alecthomas/participle v0.3.0 h1:e8vhrYR1nDjzDxyDwpLO27TWOYWilaT+glkwbPadj50= +github.com/alecthomas/participle v0.3.0/go.mod h1:SW6HZGeZgSIpcUWX3fXpfZhuaWHnmoD5KCVaqSaNTkk= github.com/alecthomas/participle/v2 v2.1.0 h1:z7dElHRrOEEq45F2TG5cbQihMtNTv8vwldytDj7Wrz4= github.com/alecthomas/participle/v2 v2.1.0/go.mod h1:Y1+hAs8DHPmc3YUFzqllV+eSQ9ljPTk0ZkPMtEdAx2c= -github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ= github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk= github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= From 3b70d297b6cc6751eee3b68913f5a01c1e38168e Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 15:06:46 +0200 Subject: [PATCH 79/90] fix spelling --- .github/actions/spelling/expect.txt | 1 + providers/atlassian/resources/atlassian.lr | 4 +- providers/atlassian/resources/atlassian.lr.go | 52 +++++++++---------- .../resources/atlassian.lr.manifest.yaml | 5 ++ 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index c586f12c8b..0c8890cb75 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -47,6 +47,7 @@ querypack resourcegroup Sas SAMEORIGIN +scim serviceprincipals Snat spdx diff --git a/providers/atlassian/resources/atlassian.lr b/providers/atlassian/resources/atlassian.lr index cffce493cd..836d3ca88a 100644 --- a/providers/atlassian/resources/atlassian.lr +++ b/providers/atlassian/resources/atlassian.lr @@ -136,12 +136,12 @@ atlassian.jira.user @defaults("name") { // Groups groups() []atlassian.jira.group // Roles - applicationRoles() []atlassian.jira.applicatonRole + applicationRoles() []atlassian.jira.applicationRole } // Jira application role -atlassian.jira.applicatonRole @defaults("name") { +atlassian.jira.applicationRole @defaults("name") { // Role ID id string // Role Name diff --git a/providers/atlassian/resources/atlassian.lr.go b/providers/atlassian/resources/atlassian.lr.go index 8406739c88..bd341a8e6f 100644 --- a/providers/atlassian/resources/atlassian.lr.go +++ b/providers/atlassian/resources/atlassian.lr.go @@ -61,9 +61,9 @@ func init() { // to override args, implement: initAtlassianJiraUser(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) Create: createAtlassianJiraUser, }, - "atlassian.jira.applicatonRole": { - // to override args, implement: initAtlassianJiraApplicatonRole(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) - Create: createAtlassianJiraApplicatonRole, + "atlassian.jira.applicationRole": { + // to override args, implement: initAtlassianJiraApplicationRole(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) + Create: createAtlassianJiraApplicationRole, }, "atlassian.jira.project": { // to override args, implement: initAtlassianJiraProject(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) @@ -292,13 +292,13 @@ var getDataFields = map[string]func(r plugin.Resource) *plugin.DataRes{ return (r.(*mqlAtlassianJiraUser).GetGroups()).ToDataRes(types.Array(types.Resource("atlassian.jira.group"))) }, "atlassian.jira.user.applicationRoles": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianJiraUser).GetApplicationRoles()).ToDataRes(types.Array(types.Resource("atlassian.jira.applicatonRole"))) + return (r.(*mqlAtlassianJiraUser).GetApplicationRoles()).ToDataRes(types.Array(types.Resource("atlassian.jira.applicationRole"))) }, - "atlassian.jira.applicatonRole.id": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianJiraApplicatonRole).GetId()).ToDataRes(types.String) + "atlassian.jira.applicationRole.id": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraApplicationRole).GetId()).ToDataRes(types.String) }, - "atlassian.jira.applicatonRole.name": func(r plugin.Resource) *plugin.DataRes { - return (r.(*mqlAtlassianJiraApplicatonRole).GetName()).ToDataRes(types.String) + "atlassian.jira.applicationRole.name": func(r plugin.Resource) *plugin.DataRes { + return (r.(*mqlAtlassianJiraApplicationRole).GetName()).ToDataRes(types.String) }, "atlassian.jira.project.id": func(r plugin.Resource) *plugin.DataRes { return (r.(*mqlAtlassianJiraProject).GetId()).ToDataRes(types.String) @@ -595,16 +595,16 @@ var setDataFields = map[string]func(r plugin.Resource, v *llx.RawData) bool { r.(*mqlAtlassianJiraUser).ApplicationRoles, ok = plugin.RawToTValue[[]interface{}](v.Value, v.Error) return }, - "atlassian.jira.applicatonRole.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianJiraApplicatonRole).__id, ok = v.Value.(string) + "atlassian.jira.applicationRole.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraApplicationRole).__id, ok = v.Value.(string) return }, - "atlassian.jira.applicatonRole.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianJiraApplicatonRole).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) + "atlassian.jira.applicationRole.id": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraApplicationRole).Id, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, - "atlassian.jira.applicatonRole.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { - r.(*mqlAtlassianJiraApplicatonRole).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) + "atlassian.jira.applicationRole.name": func(r plugin.Resource, v *llx.RawData) (ok bool) { + r.(*mqlAtlassianJiraApplicationRole).Name, ok = plugin.RawToTValue[string](v.Value, v.Error) return }, "atlassian.jira.project.__id": func(r plugin.Resource, v *llx.RawData) (ok bool) { @@ -1567,18 +1567,18 @@ func (c *mqlAtlassianJiraUser) GetApplicationRoles() *plugin.TValue[[]interface{ }) } -// mqlAtlassianJiraApplicatonRole for the atlassian.jira.applicatonRole resource -type mqlAtlassianJiraApplicatonRole struct { +// mqlAtlassianJiraApplicationRole for the atlassian.jira.applicationRole resource +type mqlAtlassianJiraApplicationRole struct { MqlRuntime *plugin.Runtime __id string - // optional: if you define mqlAtlassianJiraApplicatonRoleInternal it will be used here + // optional: if you define mqlAtlassianJiraApplicationRoleInternal it will be used here Id plugin.TValue[string] Name plugin.TValue[string] } -// createAtlassianJiraApplicatonRole creates a new instance of this resource -func createAtlassianJiraApplicatonRole(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { - res := &mqlAtlassianJiraApplicatonRole{ +// createAtlassianJiraApplicationRole creates a new instance of this resource +func createAtlassianJiraApplicationRole(runtime *plugin.Runtime, args map[string]*llx.RawData) (plugin.Resource, error) { + res := &mqlAtlassianJiraApplicationRole{ MqlRuntime: runtime, } @@ -1590,7 +1590,7 @@ func createAtlassianJiraApplicatonRole(runtime *plugin.Runtime, args map[string] // to override __id implement: id() (string, error) if runtime.HasRecording { - args, err = runtime.ResourceFromRecording("atlassian.jira.applicatonRole", res.__id) + args, err = runtime.ResourceFromRecording("atlassian.jira.applicationRole", res.__id) if err != nil || args == nil { return res, err } @@ -1600,19 +1600,19 @@ func createAtlassianJiraApplicatonRole(runtime *plugin.Runtime, args map[string] return res, nil } -func (c *mqlAtlassianJiraApplicatonRole) MqlName() string { - return "atlassian.jira.applicatonRole" +func (c *mqlAtlassianJiraApplicationRole) MqlName() string { + return "atlassian.jira.applicationRole" } -func (c *mqlAtlassianJiraApplicatonRole) MqlID() string { +func (c *mqlAtlassianJiraApplicationRole) MqlID() string { return c.__id } -func (c *mqlAtlassianJiraApplicatonRole) GetId() *plugin.TValue[string] { +func (c *mqlAtlassianJiraApplicationRole) GetId() *plugin.TValue[string] { return &c.Id } -func (c *mqlAtlassianJiraApplicatonRole) GetName() *plugin.TValue[string] { +func (c *mqlAtlassianJiraApplicationRole) GetName() *plugin.TValue[string] { return &c.Name } diff --git a/providers/atlassian/resources/atlassian.lr.manifest.yaml b/providers/atlassian/resources/atlassian.lr.manifest.yaml index 3d69dc35bc..ba956db40d 100644 --- a/providers/atlassian/resources/atlassian.lr.manifest.yaml +++ b/providers/atlassian/resources/atlassian.lr.manifest.yaml @@ -118,6 +118,11 @@ resources: serverinfo: {} users: {} min_mondoo_version: latest + atlassian.jira.applicationRole: + fields: + id: {} + name: {} + min_mondoo_version: latest atlassian.jira.applicatonRole: fields: id: {} From 1f9dd3f3f4e72e5ff5e5b43eae43a63633a6bc5b Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 15:11:17 +0200 Subject: [PATCH 80/90] add license headers --- providers/atlassian/config/config.go | 3 +++ providers/atlassian/connection/admin/platform.go | 3 +++ providers/atlassian/connection/confluence/platform.go | 3 +++ providers/atlassian/connection/jira/platform.go | 3 +++ providers/atlassian/connection/scim/platform.go | 3 +++ providers/atlassian/gen/main.go | 3 +++ providers/atlassian/main.go | 3 +++ providers/atlassian/provider/provider.go | 3 +++ providers/atlassian/resources/atlassian_admin.go | 3 +++ providers/atlassian/resources/atlassian_confluence.go | 3 +++ providers/atlassian/resources/atlassian_jira.go | 3 +++ providers/atlassian/resources/atlassian_scim.go | 3 +++ 12 files changed, 36 insertions(+) diff --git a/providers/atlassian/config/config.go b/providers/atlassian/config/config.go index 46bf23c97f..12ae447488 100644 --- a/providers/atlassian/config/config.go +++ b/providers/atlassian/config/config.go @@ -1,3 +1,6 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package config import ( diff --git a/providers/atlassian/connection/admin/platform.go b/providers/atlassian/connection/admin/platform.go index 94f8c8cf88..66c8b3e424 100644 --- a/providers/atlassian/connection/admin/platform.go +++ b/providers/atlassian/connection/admin/platform.go @@ -1,3 +1,6 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package admin import ( diff --git a/providers/atlassian/connection/confluence/platform.go b/providers/atlassian/connection/confluence/platform.go index 595e21e2ab..014aa1557a 100644 --- a/providers/atlassian/connection/confluence/platform.go +++ b/providers/atlassian/connection/confluence/platform.go @@ -1,3 +1,6 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package confluence import ( diff --git a/providers/atlassian/connection/jira/platform.go b/providers/atlassian/connection/jira/platform.go index 59decaf04d..603ade2095 100644 --- a/providers/atlassian/connection/jira/platform.go +++ b/providers/atlassian/connection/jira/platform.go @@ -1,3 +1,6 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package jira import ( diff --git a/providers/atlassian/connection/scim/platform.go b/providers/atlassian/connection/scim/platform.go index 1830ab7235..d31461efa8 100644 --- a/providers/atlassian/connection/scim/platform.go +++ b/providers/atlassian/connection/scim/platform.go @@ -1,3 +1,6 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package scim import ( diff --git a/providers/atlassian/gen/main.go b/providers/atlassian/gen/main.go index 4eca98086f..706d378668 100644 --- a/providers/atlassian/gen/main.go +++ b/providers/atlassian/gen/main.go @@ -1,3 +1,6 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package main import ( diff --git a/providers/atlassian/main.go b/providers/atlassian/main.go index b46f40a0ba..73912139f1 100644 --- a/providers/atlassian/main.go +++ b/providers/atlassian/main.go @@ -1,3 +1,6 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package main import ( diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index bfdcc8875e..9e6e2d4615 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -1,3 +1,6 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package provider import ( diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index 2555ab9e04..006d0fb201 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -1,3 +1,6 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package resources import ( diff --git a/providers/atlassian/resources/atlassian_confluence.go b/providers/atlassian/resources/atlassian_confluence.go index 3b20d40cbc..1288b08072 100644 --- a/providers/atlassian/resources/atlassian_confluence.go +++ b/providers/atlassian/resources/atlassian_confluence.go @@ -1,3 +1,6 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package resources import ( diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index 05cced8305..dc67a3983e 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -1,3 +1,6 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package resources import ( diff --git a/providers/atlassian/resources/atlassian_scim.go b/providers/atlassian/resources/atlassian_scim.go index ba277c7ce0..dab243b656 100644 --- a/providers/atlassian/resources/atlassian_scim.go +++ b/providers/atlassian/resources/atlassian_scim.go @@ -1,3 +1,6 @@ +// Copyright (c) Mondoo, Inc. +// SPDX-License-Identifier: BUSL-1.1 + package resources import ( From fd073a93f4c64753fe035f52e27d1c8dedf7d6da Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 15:32:01 +0200 Subject: [PATCH 81/90] add flags --- providers/atlassian/config/config.go | 33 ++++++++++++++++++- .../atlassian/connection/admin/connection.go | 1 + .../atlassian/connection/jira/connection.go | 2 +- .../atlassian/connection/scim/connection.go | 2 +- providers/atlassian/provider/provider.go | 17 ++++++++++ 5 files changed, 52 insertions(+), 3 deletions(-) diff --git a/providers/atlassian/config/config.go b/providers/atlassian/config/config.go index 12ae447488..6d1f467b9a 100644 --- a/providers/atlassian/config/config.go +++ b/providers/atlassian/config/config.go @@ -26,7 +26,38 @@ var Config = plugin.Provider{ Short: "atlassian", MaxArgs: 2, Discovery: []string{}, - Flags: []plugin.Flag{}, + Flags: []plugin.Flag{ + { + Long: "admintoken", + Type: plugin.FlagType_String, + Default: "", + Desc: "Provide atlassian admin api token (used for atlassian admin).", + }, + { + Long: "host", + Type: plugin.FlagType_String, + Default: "", + Desc: "Provide atlassian hostname (e.g. https://example.atlassian.net).", + }, + { + Long: "user", + Type: plugin.FlagType_String, + Default: "", + Desc: "Provide atlassian user name (e.g. example@example.com).", + }, + { + Long: "usertoken", + Type: plugin.FlagType_String, + Default: "", + Desc: "Provide atlassian user api token (used for jira / confluence).", + }, + { + Long: "scimtoken", + Type: plugin.FlagType_String, + Default: "", + Desc: "Provide atlassian scim api token (used for scim).", + }, + }, }, }, } diff --git a/providers/atlassian/connection/admin/connection.go b/providers/atlassian/connection/admin/connection.go index 95faf6bcdb..ac46d6069a 100644 --- a/providers/atlassian/connection/admin/connection.go +++ b/providers/atlassian/connection/admin/connection.go @@ -5,6 +5,7 @@ package admin import ( "errors" + "fmt" "os" "github.com/ctreminiom/go-atlassian/admin" diff --git a/providers/atlassian/connection/jira/connection.go b/providers/atlassian/connection/jira/connection.go index edeedd1440..c6f0f02991 100644 --- a/providers/atlassian/connection/jira/connection.go +++ b/providers/atlassian/connection/jira/connection.go @@ -41,7 +41,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* return nil, errors.New("you need to provide atlassian user e.g. via ATLASSIAN_USER env") } - token := conf.Options["token"] + token := conf.Options["usertoken"] if token == "" { token = os.Getenv("ATLASSIAN_USER_TOKEN") } diff --git a/providers/atlassian/connection/scim/connection.go b/providers/atlassian/connection/scim/connection.go index c1d4f47439..68d8133a9c 100644 --- a/providers/atlassian/connection/scim/connection.go +++ b/providers/atlassian/connection/scim/connection.go @@ -25,7 +25,7 @@ type ScimConnection struct { } func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*ScimConnection, error) { - token := conf.Options["token"] + token := conf.Options["scimtoken"] if token == "" { token = os.Getenv("ATLASSIAN_SCIM_TOKEN") } diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index 9e6e2d4615..27c61146b3 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -54,6 +54,23 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) Options: map[string]string{}, } + // flags + if x, ok := flags["usertoken"]; ok && len(x.Value) != 0 { + conf.Options["usertoken"] = string(x.Value) + } + if x, ok := flags["user"]; ok && len(x.Value) != 0 { + conf.Options["user"] = string(x.Value) + } + if x, ok := flags["host"]; ok && len(x.Value) != 0 { + conf.Options["host"] = string(x.Value) + } + if x, ok := flags["admintoken"]; ok && len(x.Value) != 0 { + conf.Options["admintoken"] = string(x.Value) + } + if x, ok := flags["scimtoken"]; ok && len(x.Value) != 0 { + conf.Options["scimtoken"] = string(x.Value) + } + // discovery flags discoverTargets := []string{} if x, ok := flags["discover"]; ok && len(x.Array) != 0 { From 972f0c14d450fb24b4077b25ece92359eaaff6ca Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 15:38:14 +0200 Subject: [PATCH 82/90] fix --- providers/atlassian/connection/admin/connection.go | 1 - 1 file changed, 1 deletion(-) diff --git a/providers/atlassian/connection/admin/connection.go b/providers/atlassian/connection/admin/connection.go index ac46d6069a..95faf6bcdb 100644 --- a/providers/atlassian/connection/admin/connection.go +++ b/providers/atlassian/connection/admin/connection.go @@ -5,7 +5,6 @@ package admin import ( "errors" - "fmt" "os" "github.com/ctreminiom/go-atlassian/admin" From 44e0c6740fd6d9df2a8983ab7ba3ddb7dc2a0584 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 16:03:01 +0200 Subject: [PATCH 83/90] prevent conversion panics --- .../atlassian/resources/atlassian_admin.go | 20 +++++++-- .../resources/atlassian_confluence.go | 6 ++- .../atlassian/resources/atlassian_jira.go | 41 +++++++++++++++---- .../atlassian/resources/atlassian_scim.go | 11 ++++- 4 files changed, 63 insertions(+), 15 deletions(-) diff --git a/providers/atlassian/resources/atlassian_admin.go b/providers/atlassian/resources/atlassian_admin.go index 006d0fb201..c5637df273 100644 --- a/providers/atlassian/resources/atlassian_admin.go +++ b/providers/atlassian/resources/atlassian_admin.go @@ -13,7 +13,10 @@ import ( ) func initAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*llx.RawData) (map[string]*llx.RawData, plugin.Resource, error) { - conn := runtime.Connection.(*admin.AdminConnection) + conn, ok := runtime.Connection.(*admin.AdminConnection) + if !ok { + return nil, nil, errors.New("Current connection does not allow admin access") + } admin := conn.Client() organization, _, err := admin.Organization.Gets(context.Background(), "") if err != nil { @@ -35,7 +38,10 @@ func initAtlassianAdminOrganization(runtime *plugin.Runtime, args map[string]*ll } func (a *mqlAtlassianAdminOrganization) managedUsers() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*admin.AdminConnection) + conn, ok := a.MqlRuntime.Connection.(*admin.AdminConnection) + if !ok { + return nil, errors.New("Current connection does not allow admin access") + } admin := conn.Client() @@ -62,7 +68,10 @@ func (a *mqlAtlassianAdminOrganization) managedUsers() ([]interface{}, error) { } func (a *mqlAtlassianAdminOrganization) policies() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*admin.AdminConnection) + conn, ok := a.MqlRuntime.Connection.(*admin.AdminConnection) + if !ok { + return nil, errors.New("Current connection does not allow admin access") + } admin := conn.Client() orgId := a.Id.Data policies, _, err := admin.Organization.Policy.Gets(context.Background(), orgId, "", "") @@ -88,7 +97,10 @@ func (a *mqlAtlassianAdminOrganization) policies() ([]interface{}, error) { } func (a *mqlAtlassianAdminOrganization) domains() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*admin.AdminConnection) + conn, ok := a.MqlRuntime.Connection.(*admin.AdminConnection) + if !ok { + return nil, errors.New("Current connection does not allow admin access") + } admin := conn.Client() orgId := a.Id.Data domains, _, err := admin.Organization.Domains(context.Background(), orgId, "") diff --git a/providers/atlassian/resources/atlassian_confluence.go b/providers/atlassian/resources/atlassian_confluence.go index 1288b08072..c39d8e08cc 100644 --- a/providers/atlassian/resources/atlassian_confluence.go +++ b/providers/atlassian/resources/atlassian_confluence.go @@ -5,6 +5,7 @@ package resources import ( "context" + "errors" "go.mondoo.com/cnquery/v9/llx" "go.mondoo.com/cnquery/v9/providers/atlassian/connection/confluence" @@ -15,7 +16,10 @@ func (a *mqlAtlassianConfluence) id() (string, error) { } func (a *mqlAtlassianConfluence) users() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*confluence.ConfluenceConnection) + conn, ok := a.MqlRuntime.Connection.(*confluence.ConfluenceConnection) + if !ok { + return nil, errors.New("Current connection does not allow confluence access") + } confluence := conn.Client() cql := "type = user" users, _, err := confluence.Search.Users(context.Background(), cql, 0, 1000, nil) diff --git a/providers/atlassian/resources/atlassian_jira.go b/providers/atlassian/resources/atlassian_jira.go index dc67a3983e..f99e399609 100644 --- a/providers/atlassian/resources/atlassian_jira.go +++ b/providers/atlassian/resources/atlassian_jira.go @@ -5,6 +5,7 @@ package resources import ( "context" + "errors" "fmt" "go.mondoo.com/cnquery/v9/llx" @@ -16,7 +17,10 @@ func (a *mqlAtlassianJira) id() (string, error) { } func (a *mqlAtlassianJira) users() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + conn, ok := a.MqlRuntime.Connection.(*jira.JiraConnection) + if !ok { + return nil, errors.New("Current connection does not allow jira access") + } jira := conn.Client() users, _, err := jira.User.Search.Do(context.Background(), "", " ", 0, 1000) if err != nil { @@ -40,7 +44,10 @@ func (a *mqlAtlassianJira) users() ([]interface{}, error) { } func (a *mqlAtlassianJiraUser) applicationRoles() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + conn, ok := a.MqlRuntime.Connection.(*jira.JiraConnection) + if !ok { + return nil, errors.New("Current connection does not allow jira access") + } jira := conn.Client() expands := []string{"groups", "applicationRoles"} user, _, err := jira.User.Get(context.Background(), a.Id.Data, expands) @@ -65,7 +72,10 @@ func (a *mqlAtlassianJiraUser) applicationRoles() ([]interface{}, error) { } func (a *mqlAtlassianJiraUser) groups() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + conn, ok := a.MqlRuntime.Connection.(*jira.JiraConnection) + if !ok { + return nil, errors.New("Current connection does not allow jira access") + } jira := conn.Client() groups, _, err := jira.Group.Bulk(context.Background(), nil, 0, 1000) if err != nil { @@ -87,7 +97,10 @@ func (a *mqlAtlassianJiraUser) groups() ([]interface{}, error) { } func (a *mqlAtlassianJira) groups() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + conn, ok := a.MqlRuntime.Connection.(*jira.JiraConnection) + if !ok { + return nil, errors.New("Current connection does not allow jira access") + } jira := conn.Client() groups, _, err := jira.Group.Bulk(context.Background(), nil, 0, 1000) if err != nil { @@ -109,7 +122,10 @@ func (a *mqlAtlassianJira) groups() ([]interface{}, error) { } func (a *mqlAtlassianJira) serverInfos() (*mqlAtlassianJiraServerInfo, error) { - conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + conn, ok := a.MqlRuntime.Connection.(*jira.JiraConnection) + if !ok { + return nil, errors.New("Current connection does not allow jira access") + } jira := conn.Client() info, _, err := jira.Server.Info(context.Background()) if err != nil { @@ -126,7 +142,10 @@ func (a *mqlAtlassianJira) serverInfos() (*mqlAtlassianJiraServerInfo, error) { } func (a *mqlAtlassianJira) projects() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + conn, ok := a.MqlRuntime.Connection.(*jira.JiraConnection) + if !ok { + return nil, errors.New("Current connection does not allow jira access") + } jira := conn.Client() projects, _, err := jira.Project.Search(context.Background(), nil, 0, 1000) if err != nil { @@ -156,7 +175,10 @@ func (a *mqlAtlassianJira) projects() ([]interface{}, error) { } func (a *mqlAtlassianJira) issues() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + conn, ok := a.MqlRuntime.Connection.(*jira.JiraConnection) + if !ok { + return nil, errors.New("Current connection does not allow jira access") + } jira := conn.Client() validate := "" jql := "order by created DESC" @@ -188,7 +210,10 @@ func (a *mqlAtlassianJiraIssue) id() (string, error) { } func (a *mqlAtlassianJiraProject) properties() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*jira.JiraConnection) + conn, ok := a.MqlRuntime.Connection.(*jira.JiraConnection) + if !ok { + return nil, errors.New("Current connection does not allow jira access") + } jira := conn.Client() properties, _, err := jira.Project.Property.Gets(context.Background(), a.Id.Data) if err != nil { diff --git a/providers/atlassian/resources/atlassian_scim.go b/providers/atlassian/resources/atlassian_scim.go index dab243b656..008ff69a03 100644 --- a/providers/atlassian/resources/atlassian_scim.go +++ b/providers/atlassian/resources/atlassian_scim.go @@ -5,6 +5,7 @@ package resources import ( "context" + "errors" "go.mondoo.com/cnquery/v9/llx" "go.mondoo.com/cnquery/v9/providers/atlassian/connection/scim" @@ -15,7 +16,10 @@ func (a *mqlAtlassianScim) id() (string, error) { } func (a *mqlAtlassianScim) users() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*scim.ScimConnection) + conn, ok := a.MqlRuntime.Connection.(*scim.ScimConnection) + if !ok { + return nil, errors.New("Current connection does not allow scim access") + } admin := conn.Client() directoryID := conn.Directory() scimUsers, _, err := admin.SCIM.User.Gets(context.Background(), directoryID, nil, 0, 1000) @@ -41,7 +45,10 @@ func (a *mqlAtlassianScim) users() ([]interface{}, error) { } func (a *mqlAtlassianScim) groups() ([]interface{}, error) { - conn := a.MqlRuntime.Connection.(*scim.ScimConnection) + conn, ok := a.MqlRuntime.Connection.(*scim.ScimConnection) + if !ok { + return nil, errors.New("Current connection does not allow scim access") + } admin := conn.Client() directoryID := conn.Directory() scimGroup, _, err := admin.SCIM.Group.Gets(context.Background(), directoryID, "", 0, 1000) From a95b354578e2b935f7f4a8c8127bd08d7b73c7dc Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 16:20:05 +0200 Subject: [PATCH 84/90] fix token flag names --- providers/atlassian/config/config.go | 6 +++--- providers/atlassian/connection/admin/connection.go | 4 ++-- .../atlassian/connection/confluence/connection.go | 2 +- providers/atlassian/connection/jira/connection.go | 2 +- providers/atlassian/connection/scim/connection.go | 2 +- providers/atlassian/provider/provider.go | 12 ++++++------ 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/providers/atlassian/config/config.go b/providers/atlassian/config/config.go index 6d1f467b9a..7e6542417c 100644 --- a/providers/atlassian/config/config.go +++ b/providers/atlassian/config/config.go @@ -28,7 +28,7 @@ var Config = plugin.Provider{ Discovery: []string{}, Flags: []plugin.Flag{ { - Long: "admintoken", + Long: "admin-token", Type: plugin.FlagType_String, Default: "", Desc: "Provide atlassian admin api token (used for atlassian admin).", @@ -46,13 +46,13 @@ var Config = plugin.Provider{ Desc: "Provide atlassian user name (e.g. example@example.com).", }, { - Long: "usertoken", + Long: "user-token", Type: plugin.FlagType_String, Default: "", Desc: "Provide atlassian user api token (used for jira / confluence).", }, { - Long: "scimtoken", + Long: "scim-token", Type: plugin.FlagType_String, Default: "", Desc: "Provide atlassian scim api token (used for scim).", diff --git a/providers/atlassian/connection/admin/connection.go b/providers/atlassian/connection/admin/connection.go index 95faf6bcdb..849ea430ad 100644 --- a/providers/atlassian/connection/admin/connection.go +++ b/providers/atlassian/connection/admin/connection.go @@ -25,7 +25,7 @@ type AdminConnection struct { } func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AdminConnection, error) { - adminToken := conf.Options["admintoken"] + adminToken := conf.Options["admin-token"] if adminToken == "" { adminToken = os.Getenv("ATLASSIAN_ADMIN_TOKEN") } @@ -53,7 +53,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* } func (c *AdminConnection) Name() string { - return "atlassian" + return "atlassian-admin" } func (c *AdminConnection) ID() uint32 { diff --git a/providers/atlassian/connection/confluence/connection.go b/providers/atlassian/connection/confluence/connection.go index 0dfa137d88..af57472f50 100644 --- a/providers/atlassian/connection/confluence/connection.go +++ b/providers/atlassian/connection/confluence/connection.go @@ -41,7 +41,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* return nil, errors.New("you need to provide atlassian username via ATLASSIAN_USER env") } - token := conf.Options["usertoken"] + token := conf.Options["user-token"] if token == "" { token = os.Getenv("ATLASSIAN_USER_TOKEN") } diff --git a/providers/atlassian/connection/jira/connection.go b/providers/atlassian/connection/jira/connection.go index c6f0f02991..8551693296 100644 --- a/providers/atlassian/connection/jira/connection.go +++ b/providers/atlassian/connection/jira/connection.go @@ -41,7 +41,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* return nil, errors.New("you need to provide atlassian user e.g. via ATLASSIAN_USER env") } - token := conf.Options["usertoken"] + token := conf.Options["user-token"] if token == "" { token = os.Getenv("ATLASSIAN_USER_TOKEN") } diff --git a/providers/atlassian/connection/scim/connection.go b/providers/atlassian/connection/scim/connection.go index 68d8133a9c..2678e3d8a5 100644 --- a/providers/atlassian/connection/scim/connection.go +++ b/providers/atlassian/connection/scim/connection.go @@ -25,7 +25,7 @@ type ScimConnection struct { } func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*ScimConnection, error) { - token := conf.Options["scimtoken"] + token := conf.Options["scim-token"] if token == "" { token = os.Getenv("ATLASSIAN_SCIM_TOKEN") } diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index 27c61146b3..20c3b6e9f1 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -55,8 +55,8 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) } // flags - if x, ok := flags["usertoken"]; ok && len(x.Value) != 0 { - conf.Options["usertoken"] = string(x.Value) + if x, ok := flags["user-token"]; ok && len(x.Value) != 0 { + conf.Options["user-token"] = string(x.Value) } if x, ok := flags["user"]; ok && len(x.Value) != 0 { conf.Options["user"] = string(x.Value) @@ -64,11 +64,11 @@ func (s *Service) ParseCLI(req *plugin.ParseCLIReq) (*plugin.ParseCLIRes, error) if x, ok := flags["host"]; ok && len(x.Value) != 0 { conf.Options["host"] = string(x.Value) } - if x, ok := flags["admintoken"]; ok && len(x.Value) != 0 { - conf.Options["admintoken"] = string(x.Value) + if x, ok := flags["admin-token"]; ok && len(x.Value) != 0 { + conf.Options["admin-token"] = string(x.Value) } - if x, ok := flags["scimtoken"]; ok && len(x.Value) != 0 { - conf.Options["scimtoken"] = string(x.Value) + if x, ok := flags["scim-token"]; ok && len(x.Value) != 0 { + conf.Options["scim-token"] = string(x.Value) } // discovery flags From 697dfc1a18ccc9ffbb92bdba108aa6ba09649d7c Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 16:23:08 +0200 Subject: [PATCH 85/90] fix error messages --- providers/atlassian/connection/admin/connection.go | 2 +- providers/atlassian/connection/confluence/connection.go | 6 +++--- providers/atlassian/connection/jira/connection.go | 6 +++--- providers/atlassian/connection/scim/connection.go | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/providers/atlassian/connection/admin/connection.go b/providers/atlassian/connection/admin/connection.go index 849ea430ad..d31c4469e8 100644 --- a/providers/atlassian/connection/admin/connection.go +++ b/providers/atlassian/connection/admin/connection.go @@ -30,7 +30,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* adminToken = os.Getenv("ATLASSIAN_ADMIN_TOKEN") } if adminToken == "" { - return nil, errors.New("you need to provide atlassian admin token via ATLASSIAN_ADMIN_TOKEN env") + return nil, errors.New("you need to provide atlassian admin token via ATLASSIAN_ADMIN_TOKEN env or via the --admin-token flag") } client, err := admin.New(nil) diff --git a/providers/atlassian/connection/confluence/connection.go b/providers/atlassian/connection/confluence/connection.go index af57472f50..1775061639 100644 --- a/providers/atlassian/connection/confluence/connection.go +++ b/providers/atlassian/connection/confluence/connection.go @@ -30,7 +30,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* host = os.Getenv("ATLASSIAN_HOST") } if host == "" { - return nil, errors.New("you need to provide atlassian hostname via ATLASSIAN_HOST env") + return nil, errors.New("you need to provide atlassian hostname via ATLASSIAN_HOST env or via --host flag") } user := conf.Options["user"] @@ -38,7 +38,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* user = os.Getenv("ATLASSIAN_USER") } if user == "" { - return nil, errors.New("you need to provide atlassian username via ATLASSIAN_USER env") + return nil, errors.New("you need to provide atlassian username via ATLASSIAN_USER env or via --user flag") } token := conf.Options["user-token"] @@ -46,7 +46,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* token = os.Getenv("ATLASSIAN_USER_TOKEN") } if token == "" { - return nil, errors.New("you need to provide atlassian user token via ATLASSIAN_USER_TOKEN env") + return nil, errors.New("you need to provide atlassian user token via ATLASSIAN_USER_TOKEN env or via --user-token flag") } client, err := confluence.New(nil, host) diff --git a/providers/atlassian/connection/jira/connection.go b/providers/atlassian/connection/jira/connection.go index 8551693296..0db3945035 100644 --- a/providers/atlassian/connection/jira/connection.go +++ b/providers/atlassian/connection/jira/connection.go @@ -30,7 +30,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* host = os.Getenv("ATLASSIAN_HOST") } if host == "" { - return nil, errors.New("you need to provide atlassian host e.g. via ATLASSIAN_HOST env") + return nil, errors.New("you need to provide atlassian host e.g. via ATLASSIAN_HOST env or via --host flag") } user := conf.Options["user"] @@ -38,7 +38,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* user = os.Getenv("ATLASSIAN_USER") } if user == "" { - return nil, errors.New("you need to provide atlassian user e.g. via ATLASSIAN_USER env") + return nil, errors.New("you need to provide atlassian user e.g. via ATLASSIAN_USER env or via --user flag") } token := conf.Options["user-token"] @@ -46,7 +46,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* token = os.Getenv("ATLASSIAN_USER_TOKEN") } if token == "" { - return nil, errors.New("you need to provide atlassian user token e.g. via ATLASSIAN_USER_TOKEN env") + return nil, errors.New("you need to provide atlassian user token e.g. via ATLASSIAN_USER_TOKEN env or via --user-token flag") } client, err := v2.New(nil, host) diff --git a/providers/atlassian/connection/scim/connection.go b/providers/atlassian/connection/scim/connection.go index 2678e3d8a5..5aa82448ea 100644 --- a/providers/atlassian/connection/scim/connection.go +++ b/providers/atlassian/connection/scim/connection.go @@ -30,7 +30,7 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* token = os.Getenv("ATLASSIAN_SCIM_TOKEN") } if token == "" { - return nil, errors.New("you need to provide atlassian scim token via ATLASSIAN_SCIM_TOKEN env") + return nil, errors.New("you need to provide atlassian scim token via ATLASSIAN_SCIM_TOKEN env or via --admin-token flag") } if conf.Options["directory-id"] == "" { From 76f94cf8eb522fc359c6070498fefb946f839ee8 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 16:26:27 +0200 Subject: [PATCH 86/90] fix default connection types --- providers/defaults.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/providers/defaults.go b/providers/defaults.go index d682e5d96d..cb35ff98c9 100644 --- a/providers/defaults.go +++ b/providers/defaults.go @@ -48,8 +48,14 @@ var DefaultProviders Providers = map[string]*Provider{ }, "atlassian": { Provider: &plugin.Provider{ - Name: "atlassian", - ConnectionTypes: []string{"atlassian"}, + Name: "atlassian", + ConnectionTypes: []string{ + "atlassian", + "jira", + "admin", + "confluence", + "scim", + }, Connectors: []plugin.Connector{ { Name: "atlassian", From 1456fa0da18a57f6fe1b2790e55df47fab94ebb1 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 16:35:59 +0200 Subject: [PATCH 87/90] fix platform name --- providers/atlassian/connection/admin/platform.go | 10 +++++----- providers/atlassian/connection/confluence/platform.go | 10 +++++----- providers/atlassian/connection/jira/platform.go | 10 +++++----- providers/atlassian/connection/scim/platform.go | 10 +++++----- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/providers/atlassian/connection/admin/platform.go b/providers/atlassian/connection/admin/platform.go index 66c8b3e424..b1a5ac89e0 100644 --- a/providers/atlassian/connection/admin/platform.go +++ b/providers/atlassian/connection/admin/platform.go @@ -8,21 +8,21 @@ import ( ) func (a *AdminConnection) PlatformInfo() *inventory.Platform { - return GetPlatformForObject("atlassian") + return GetPlatformForObject("atlassian-admin") } func GetPlatformForObject(platformName string) *inventory.Platform { - if platformName != "atlassian" && platformName != "" { + if platformName != "atlassian-admin" && platformName != "" { return &inventory.Platform{ Name: platformName, - Title: "atlassian", + Title: "atlassian-admin", Kind: "api", Runtime: "atlassian", } } return &inventory.Platform{ - Name: "atlassian", - Title: "atlassian", + Name: "atlassian-admin", + Title: "atlassian-admin", Kind: "api", Runtime: "atlassian", } diff --git a/providers/atlassian/connection/confluence/platform.go b/providers/atlassian/connection/confluence/platform.go index 014aa1557a..c858dc0b83 100644 --- a/providers/atlassian/connection/confluence/platform.go +++ b/providers/atlassian/connection/confluence/platform.go @@ -10,21 +10,21 @@ import ( ) func (a *ConfluenceConnection) PlatformInfo() *inventory.Platform { - return GetPlatformForObject("atlassian") + return GetPlatformForObject("atlassian-confluence") } func GetPlatformForObject(platformName string) *inventory.Platform { - if platformName != "atlassian" && platformName != "" { + if platformName != "atlassian-confluence" && platformName != "" { return &inventory.Platform{ Name: platformName, - Title: "atlassian", + Title: "atlassian-confluence", Kind: "api", Runtime: "atlassian", } } return &inventory.Platform{ - Name: "atlassian", - Title: "atlassian", + Name: "atlassian-confluence", + Title: "atlassian-confluence", Kind: "api", Runtime: "atlassian", } diff --git a/providers/atlassian/connection/jira/platform.go b/providers/atlassian/connection/jira/platform.go index 603ade2095..96d4bf5c1c 100644 --- a/providers/atlassian/connection/jira/platform.go +++ b/providers/atlassian/connection/jira/platform.go @@ -10,21 +10,21 @@ import ( ) func (a *JiraConnection) PlatformInfo() *inventory.Platform { - return GetPlatformForObject("atlassian") + return GetPlatformForObject("atlassian-jira") } func GetPlatformForObject(platformName string) *inventory.Platform { - if platformName != "atlassian" && platformName != "" { + if platformName != "atlassian-jira" && platformName != "" { return &inventory.Platform{ Name: platformName, - Title: "atlassian", + Title: "atlassian-jira", Kind: "api", Runtime: "atlassian", } } return &inventory.Platform{ - Name: "atlassian", - Title: "atlassian", + Name: "atlassian-jira", + Title: "atlassian-jira", Kind: "api", Runtime: "atlassian", } diff --git a/providers/atlassian/connection/scim/platform.go b/providers/atlassian/connection/scim/platform.go index d31461efa8..9672d22e4b 100644 --- a/providers/atlassian/connection/scim/platform.go +++ b/providers/atlassian/connection/scim/platform.go @@ -8,21 +8,21 @@ import ( ) func (a *ScimConnection) PlatformInfo() *inventory.Platform { - return GetPlatformForObject("atlassian") + return GetPlatformForObject("atlassian-scim") } func GetPlatformForObject(platformName string) *inventory.Platform { - if platformName != "atlassian" && platformName != "" { + if platformName != "atlassian-scim" && platformName != "" { return &inventory.Platform{ Name: platformName, - Title: "atlassian", + Title: "atlassian-scim", Kind: "api", Runtime: "atlassian", } } return &inventory.Platform{ - Name: "atlassian", - Title: "atlassian", + Name: "atlassian-scim", + Title: "atlassian-scim", Kind: "api", Runtime: "atlassian", } From 8bbb3f56c66a596f8ef3241553314fa9c6060d2a Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 16:39:10 +0200 Subject: [PATCH 88/90] fix title too human readable name --- providers/atlassian/connection/admin/platform.go | 4 ++-- providers/atlassian/connection/confluence/platform.go | 4 ++-- providers/atlassian/connection/jira/platform.go | 4 ++-- providers/atlassian/connection/scim/platform.go | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/providers/atlassian/connection/admin/platform.go b/providers/atlassian/connection/admin/platform.go index b1a5ac89e0..9f1fd9379c 100644 --- a/providers/atlassian/connection/admin/platform.go +++ b/providers/atlassian/connection/admin/platform.go @@ -15,14 +15,14 @@ func GetPlatformForObject(platformName string) *inventory.Platform { if platformName != "atlassian-admin" && platformName != "" { return &inventory.Platform{ Name: platformName, - Title: "atlassian-admin", + Title: "Atlassian Admin", Kind: "api", Runtime: "atlassian", } } return &inventory.Platform{ Name: "atlassian-admin", - Title: "atlassian-admin", + Title: "Atlassian Admin", Kind: "api", Runtime: "atlassian", } diff --git a/providers/atlassian/connection/confluence/platform.go b/providers/atlassian/connection/confluence/platform.go index c858dc0b83..54a8340a34 100644 --- a/providers/atlassian/connection/confluence/platform.go +++ b/providers/atlassian/connection/confluence/platform.go @@ -17,14 +17,14 @@ func GetPlatformForObject(platformName string) *inventory.Platform { if platformName != "atlassian-confluence" && platformName != "" { return &inventory.Platform{ Name: platformName, - Title: "atlassian-confluence", + Title: "Atlassian Confluence", Kind: "api", Runtime: "atlassian", } } return &inventory.Platform{ Name: "atlassian-confluence", - Title: "atlassian-confluence", + Title: "Atlassian Confluence", Kind: "api", Runtime: "atlassian", } diff --git a/providers/atlassian/connection/jira/platform.go b/providers/atlassian/connection/jira/platform.go index 96d4bf5c1c..d330c10ba0 100644 --- a/providers/atlassian/connection/jira/platform.go +++ b/providers/atlassian/connection/jira/platform.go @@ -17,14 +17,14 @@ func GetPlatformForObject(platformName string) *inventory.Platform { if platformName != "atlassian-jira" && platformName != "" { return &inventory.Platform{ Name: platformName, - Title: "atlassian-jira", + Title: "Atlassian Jira", Kind: "api", Runtime: "atlassian", } } return &inventory.Platform{ Name: "atlassian-jira", - Title: "atlassian-jira", + Title: "Atlassian Jira", Kind: "api", Runtime: "atlassian", } diff --git a/providers/atlassian/connection/scim/platform.go b/providers/atlassian/connection/scim/platform.go index 9672d22e4b..343a19fa87 100644 --- a/providers/atlassian/connection/scim/platform.go +++ b/providers/atlassian/connection/scim/platform.go @@ -15,14 +15,14 @@ func GetPlatformForObject(platformName string) *inventory.Platform { if platformName != "atlassian-scim" && platformName != "" { return &inventory.Platform{ Name: platformName, - Title: "atlassian-scim", + Title: "Atlassian SCIM", Kind: "api", Runtime: "atlassian", } } return &inventory.Platform{ Name: "atlassian-scim", - Title: "atlassian-scim", + Title: "Atlassian SCIM", Kind: "api", Runtime: "atlassian", } From 8aae86cce4673cc43881ee91faf32546053dafe2 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 16:47:21 +0200 Subject: [PATCH 89/90] fix scim name --- providers/atlassian/connection/scim/connection.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/providers/atlassian/connection/scim/connection.go b/providers/atlassian/connection/scim/connection.go index 5aa82448ea..d29f9fe1a4 100644 --- a/providers/atlassian/connection/scim/connection.go +++ b/providers/atlassian/connection/scim/connection.go @@ -5,6 +5,7 @@ package scim import ( "errors" + "fmt" "os" "github.com/ctreminiom/go-atlassian/admin" @@ -45,12 +46,13 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* client.Auth.SetBearerToken(token) client.Auth.SetUserAgent("curl/7.54.0") + host := fmt.Sprintf("Directory %s", conf.Options["directory-id"]) conn := &ScimConnection{ Conf: conf, id: id, asset: asset, client: client, - host: "admin.atlassian.com", + host: host, } return conn, nil From da1f75bed5b4f0b804c722296d32f7d8c3bf2ba6 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Mon, 16 Oct 2023 16:55:45 +0200 Subject: [PATCH 90/90] change host to name --- providers/atlassian/connection/admin/connection.go | 10 +++------- .../atlassian/connection/confluence/connection.go | 10 +++------- .../atlassian/connection/confluence/platform.go | 2 +- providers/atlassian/connection/jira/connection.go | 10 +++------- providers/atlassian/connection/jira/platform.go | 2 +- providers/atlassian/connection/scim/connection.go | 12 ++++-------- providers/atlassian/connection/shared/shared.go | 1 - providers/atlassian/provider/provider.go | 2 +- 8 files changed, 16 insertions(+), 33 deletions(-) diff --git a/providers/atlassian/connection/admin/connection.go b/providers/atlassian/connection/admin/connection.go index d31c4469e8..6445a7ca13 100644 --- a/providers/atlassian/connection/admin/connection.go +++ b/providers/atlassian/connection/admin/connection.go @@ -21,7 +21,7 @@ type AdminConnection struct { Conf *inventory.Config asset *inventory.Asset client *admin.Client - host string + name string } func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AdminConnection, error) { @@ -46,14 +46,14 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* id: id, asset: asset, client: client, - host: "admin.atlassian.com", + name: "admin.atlassian.com", } return conn, nil } func (c *AdminConnection) Name() string { - return "atlassian-admin" + return c.name } func (c *AdminConnection) ID() uint32 { @@ -72,10 +72,6 @@ func (c *AdminConnection) Type() shared.ConnectionType { return Admin } -func (c *AdminConnection) Host() string { - return c.host -} - func (c *AdminConnection) ConnectionType() string { return "admin" } diff --git a/providers/atlassian/connection/confluence/connection.go b/providers/atlassian/connection/confluence/connection.go index 1775061639..b773af87c7 100644 --- a/providers/atlassian/connection/confluence/connection.go +++ b/providers/atlassian/connection/confluence/connection.go @@ -21,7 +21,7 @@ type ConfluenceConnection struct { Conf *inventory.Config asset *inventory.Asset client *confluence.Client - host string + name string } func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*ConfluenceConnection, error) { @@ -62,14 +62,14 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* id: id, asset: asset, client: client, - host: host, + name: host, } return conn, nil } func (c *ConfluenceConnection) Name() string { - return "atlassian" + return c.name } func (c *ConfluenceConnection) ID() uint32 { @@ -88,10 +88,6 @@ func (c *ConfluenceConnection) Type() shared.ConnectionType { return Confluence } -func (c *ConfluenceConnection) Host() string { - return c.host -} - func (c *ConfluenceConnection) ConnectionType() string { return "confluence" } diff --git a/providers/atlassian/connection/confluence/platform.go b/providers/atlassian/connection/confluence/platform.go index 54a8340a34..8004b74432 100644 --- a/providers/atlassian/connection/confluence/platform.go +++ b/providers/atlassian/connection/confluence/platform.go @@ -31,7 +31,7 @@ func GetPlatformForObject(platformName string) *inventory.Platform { } func (a *ConfluenceConnection) PlatformID() string { - hostname := strings.TrimPrefix(a.host, "https://") + hostname := strings.TrimPrefix(a.name, "https://") host := strings.Replace(hostname, ".", "-", -1) return "//platformid.api.mondoo.app/runtime/atlassian/confluence/" + host } diff --git a/providers/atlassian/connection/jira/connection.go b/providers/atlassian/connection/jira/connection.go index 0db3945035..d94aa6830f 100644 --- a/providers/atlassian/connection/jira/connection.go +++ b/providers/atlassian/connection/jira/connection.go @@ -21,7 +21,7 @@ type JiraConnection struct { Conf *inventory.Config asset *inventory.Asset client *v2.Client - host string + name string } func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*JiraConnection, error) { @@ -62,14 +62,14 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* id: id, asset: asset, client: client, - host: host, + name: host, } return conn, nil } func (c *JiraConnection) Name() string { - return "jira" + return c.name } func (c *JiraConnection) ID() uint32 { @@ -88,10 +88,6 @@ func (p *JiraConnection) Type() shared.ConnectionType { return Jira } -func (c *JiraConnection) Host() string { - return c.host -} - func (c *JiraConnection) ConnectionType() string { return "jira" } diff --git a/providers/atlassian/connection/jira/platform.go b/providers/atlassian/connection/jira/platform.go index d330c10ba0..bd46dc827e 100644 --- a/providers/atlassian/connection/jira/platform.go +++ b/providers/atlassian/connection/jira/platform.go @@ -31,7 +31,7 @@ func GetPlatformForObject(platformName string) *inventory.Platform { } func (a *JiraConnection) PlatformID() string { - hostname := strings.TrimPrefix(a.host, "https://") + hostname := strings.TrimPrefix(a.name, "https://") host := strings.Replace(hostname, ".", "-", -1) return "//platformid.api.mondoo.app/runtime/atlassian/jira/" + host } diff --git a/providers/atlassian/connection/scim/connection.go b/providers/atlassian/connection/scim/connection.go index d29f9fe1a4..7f72a7d8f9 100644 --- a/providers/atlassian/connection/scim/connection.go +++ b/providers/atlassian/connection/scim/connection.go @@ -22,7 +22,7 @@ type ScimConnection struct { Conf *inventory.Config asset *inventory.Asset client *admin.Client - host string + name string } func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*ScimConnection, error) { @@ -46,20 +46,20 @@ func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (* client.Auth.SetBearerToken(token) client.Auth.SetUserAgent("curl/7.54.0") - host := fmt.Sprintf("Directory %s", conf.Options["directory-id"]) + name := fmt.Sprintf("Directory %s", conf.Options["directory-id"]) conn := &ScimConnection{ Conf: conf, id: id, asset: asset, client: client, - host: host, + name: name, } return conn, nil } func (c *ScimConnection) Name() string { - return "scim" + return c.name } func (c *ScimConnection) ID() uint32 { @@ -78,10 +78,6 @@ func (p *ScimConnection) Type() shared.ConnectionType { return Scim } -func (c *ScimConnection) Host() string { - return c.host -} - func (c *ScimConnection) Directory() string { return c.Conf.Options["directory-id"] } diff --git a/providers/atlassian/connection/shared/shared.go b/providers/atlassian/connection/shared/shared.go index f884e6fc29..1c8945f336 100644 --- a/providers/atlassian/connection/shared/shared.go +++ b/providers/atlassian/connection/shared/shared.go @@ -14,7 +14,6 @@ type Connection interface { Name() string Type() ConnectionType Asset() *inventory.Asset - Host() string PlatformInfo() *inventory.Platform PlatformID() string Config() *inventory.Config diff --git a/providers/atlassian/provider/provider.go b/providers/atlassian/provider/provider.go index 20c3b6e9f1..26d80cf9af 100644 --- a/providers/atlassian/provider/provider.go +++ b/providers/atlassian/provider/provider.go @@ -178,7 +178,7 @@ func (s *Service) connect(req *plugin.ConnectReq, callback plugin.ProviderCallba func (s *Service) detect(asset *inventory.Asset, conn shared.Connection) error { asset.Id = string(conn.Type()) - asset.Name = conn.Host() + asset.Name = conn.Name() asset.Platform = conn.PlatformInfo() asset.PlatformIds = []string{conn.PlatformID()}