* task: Datadog analyzer init commit with limited resources and permissions No cases covered * task: added more permissions * task: added more permissions | refactoring * task: added domain handling * refactor: incorporated PR feedback * task: Analyzer Result implementation for enterprise * task: added tests | Analysis Info configuration changes | permissions.yaml * revert: reverted datadog detector base URL * refactor: streamline Datadog API key analysis and permission handling - Simplified API key retrieval logic by removing redundant checks for "key". - Enhanced permission binding extraction by introducing a new function for permissions. - Cleaned up resource binding logic for better clarity and maintainability. - Removed unnecessary ID fields from scopes.json to reduce clutter.
85 lines
1.9 KiB
Go
85 lines
1.9 KiB
Go
package datadog
|
|
|
|
import "sync"
|
|
|
|
// Resource type constants for consistent usage
|
|
const (
|
|
ResourceTypeValidate = "Validate"
|
|
ResourceTypeCurrentUser = "Current User"
|
|
ResourceTypeDashboard = "Dashboard"
|
|
ResourceTypeMonitor = "Monitor"
|
|
)
|
|
|
|
// Permission represents a permission granted to an API key
|
|
type Permission struct {
|
|
Name string
|
|
Title string
|
|
Description string
|
|
MetaData map[string]string
|
|
}
|
|
|
|
// SecretInfo holds all information gathered about a Datadog API key
|
|
type SecretInfo struct {
|
|
User User
|
|
Permissions []Permission
|
|
|
|
mu sync.RWMutex
|
|
Resources []Resource
|
|
}
|
|
|
|
// User is the information about the user to whom the token belongs
|
|
type User struct {
|
|
Id string
|
|
Name string
|
|
Email string
|
|
}
|
|
|
|
// Resource represents a Datadog resource
|
|
type Resource struct {
|
|
ID string
|
|
Name string
|
|
Type string
|
|
MetaData map[string]string
|
|
}
|
|
|
|
// API response structures
|
|
type currentUserResponse struct {
|
|
Data struct {
|
|
Id string `json:"id"`
|
|
Attributes struct {
|
|
Name string `json:"name"`
|
|
Email string `json:"email"`
|
|
} `json:"attributes"`
|
|
} `json:"data"`
|
|
}
|
|
|
|
type dashboardResponse struct {
|
|
Dashboards []DashboardItem `json:"dashboards"`
|
|
}
|
|
|
|
type DashboardItem struct {
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
URL string `json:"url"`
|
|
IsReadOnly bool `json:"is_read_only"`
|
|
CreatedAt string `json:"created_at"`
|
|
ModifiedAt string `json:"modified_at"`
|
|
AuthorHandle string `json:"author_handle"`
|
|
Description *string `json:"description"`
|
|
LayoutType string `json:"layout_type"`
|
|
DeletedAt *string `json:"deleted_at"`
|
|
}
|
|
|
|
type monitorResponse []struct {
|
|
ID int `json:"id"`
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
// appendResource adds a resource to secret info resources list
|
|
func (s *SecretInfo) appendResource(resource Resource) {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
|
|
s.Resources = append(s.Resources, resource)
|
|
}
|