-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ⭐️ 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
1 parent
5cfecb6
commit e6976c2
Showing
26 changed files
with
4,524 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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).", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.