Skip to content

Commit

Permalink
⭐️ atlassian provider (#2253)
Browse files Browse the repository at this point in the history
* ⭐️ atlassian provider

Signed-off-by: Marius Kimmina <mar.kimmina@gmail.com>
Signed-off-by: Ivan Milchev <ivan@mondoo.com>
Co-authored-by: Ivan Milchev <ivan@mondoo.com>
  • Loading branch information
mariuskimmina and imilchev authored Oct 16, 2023
1 parent 5cfecb6 commit e6976c2
Show file tree
Hide file tree
Showing 26 changed files with 4,524 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
aks
atlassian
Auths
autoaccept
autoscaler
Expand All @@ -8,6 +9,7 @@ cavium
cdn
certificatechains
cmek
confluence
cryptokey
customresources
datapath
Expand All @@ -25,6 +27,7 @@ iap
ilb
ingresstls
iotedge
jira
linux
loggingservice
managedzone
Expand All @@ -44,6 +47,7 @@ querypack
resourcegroup
Sas
SAMEORIGIN
scim
serviceprincipals
Snat
spdx
Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -210,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
Expand Down Expand Up @@ -313,6 +315,11 @@ providers/build/aws: providers/lr
providers/install/aws:
@$(call installProvider, providers/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)
providers/install/ms365:
Expand All @@ -339,6 +346,7 @@ providers/dist:
@$(call buildProviderDist, providers/azure)
@$(call buildProviderDist, providers/ms365)
@$(call buildProviderDist, providers/aws)
@$(call buildProviderDist, providers/atlassian)

providers/bundle:
@$(call bundleProvider, providers/network)
Expand All @@ -361,6 +369,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)
Expand All @@ -384,6 +393,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/...
Expand Down
63 changes: 63 additions & 0 deletions providers/atlassian/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package config

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",
ConnectionTypes: []string{
provider.DefaultConnectionType,
"jira",
"admin",
"confluence",
"scim",
},
Connectors: []plugin.Connector{
{
Name: "atlassian",
Use: "atlassian",
Short: "atlassian",
MaxArgs: 2,
Discovery: []string{},
Flags: []plugin.Flag{
{
Long: "admin-token",
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: "user-token",
Type: plugin.FlagType_String,
Default: "",
Desc: "Provide atlassian user api token (used for jira / confluence).",
},
{
Long: "scim-token",
Type: plugin.FlagType_String,
Default: "",
Desc: "Provide atlassian scim api token (used for scim).",
},
},
},
},
}
81 changes: 81 additions & 0 deletions providers/atlassian/connection/admin/connection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package admin

import (
"errors"
"os"

"github.com/ctreminiom/go-atlassian/admin"
"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
name string
}

func NewConnection(id uint32, asset *inventory.Asset, conf *inventory.Config) (*AdminConnection, error) {
adminToken := conf.Options["admin-token"]
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 or via the --admin-token flag")
}

client, err := admin.New(nil)
if err != nil {
return nil, err
}

client.Auth.SetBearerToken(adminToken)
client.Auth.SetUserAgent("curl/7.54.0")

conn := &AdminConnection{
Conf: conf,
id: id,
asset: asset,
client: client,
name: "admin.atlassian.com",
}

return conn, nil
}

func (c *AdminConnection) Name() string {
return c.name
}

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 (c *AdminConnection) Type() shared.ConnectionType {
return Admin
}

func (c *AdminConnection) ConnectionType() string {
return "admin"
}

func (c *AdminConnection) Config() *inventory.Config {
return c.Conf
}
33 changes: 33 additions & 0 deletions providers/atlassian/connection/admin/platform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package admin

import (
"go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory"
)

func (a *AdminConnection) PlatformInfo() *inventory.Platform {
return GetPlatformForObject("atlassian-admin")
}

func GetPlatformForObject(platformName string) *inventory.Platform {
if platformName != "atlassian-admin" && platformName != "" {
return &inventory.Platform{
Name: platformName,
Title: "Atlassian Admin",
Kind: "api",
Runtime: "atlassian",
}
}
return &inventory.Platform{
Name: "atlassian-admin",
Title: "Atlassian Admin",
Kind: "api",
Runtime: "atlassian",
}
}

func (a *AdminConnection) PlatformID() string {
return "//platformid.api.mondoo.app/runtime/atlassian/admin"
}
97 changes: 97 additions & 0 deletions providers/atlassian/connection/confluence/connection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package confluence

import (
"errors"
"os"

"github.com/ctreminiom/go-atlassian/confluence"
"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
name string
}

func NewConnection(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 or via --host flag")
}

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 or via --user flag")
}

token := conf.Options["user-token"]
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 or via --user-token flag")
}

client, err := confluence.New(nil, host)
if err != nil {
return nil, err
}

client.Auth.SetBasicAuth(user, token)
client.Auth.SetUserAgent("curl/7.54.0")

conn := &ConfluenceConnection{
Conf: conf,
id: id,
asset: asset,
client: client,
name: host,
}

return conn, nil
}

func (c *ConfluenceConnection) Name() string {
return c.name
}

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 (c *ConfluenceConnection) Type() shared.ConnectionType {
return Confluence
}

func (c *ConfluenceConnection) ConnectionType() string {
return "confluence"
}

func (c *ConfluenceConnection) Config() *inventory.Config {
return c.Conf
}
37 changes: 37 additions & 0 deletions providers/atlassian/connection/confluence/platform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1

package confluence

import (
"strings"

"go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory"
)

func (a *ConfluenceConnection) PlatformInfo() *inventory.Platform {
return GetPlatformForObject("atlassian-confluence")
}

func GetPlatformForObject(platformName string) *inventory.Platform {
if platformName != "atlassian-confluence" && platformName != "" {
return &inventory.Platform{
Name: platformName,
Title: "Atlassian Confluence",
Kind: "api",
Runtime: "atlassian",
}
}
return &inventory.Platform{
Name: "atlassian-confluence",
Title: "Atlassian Confluence",
Kind: "api",
Runtime: "atlassian",
}
}

func (a *ConfluenceConnection) PlatformID() string {
hostname := strings.TrimPrefix(a.name, "https://")
host := strings.Replace(hostname, ".", "-", -1)
return "//platformid.api.mondoo.app/runtime/atlassian/confluence/" + host
}
Loading

0 comments on commit e6976c2

Please sign in to comment.