2022-12-02 03:57:00 +05:30
|
|
|
package customtemplates
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/types"
|
2023-04-19 17:42:52 -04:00
|
|
|
errorutil "github.com/projectdiscovery/utils/errors"
|
2022-12-02 03:57:00 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Provider interface {
|
2023-04-19 17:42:52 -04:00
|
|
|
Download(ctx context.Context)
|
|
|
|
|
Update(ctx context.Context)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CustomTemplatesManager is a manager for custom templates
|
|
|
|
|
type CustomTemplatesManager struct {
|
|
|
|
|
providers []Provider
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Download downloads the custom templates
|
|
|
|
|
func (c *CustomTemplatesManager) Download(ctx context.Context) {
|
|
|
|
|
for _, provider := range c.providers {
|
|
|
|
|
provider.Download(ctx)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update updates the custom templates
|
|
|
|
|
func (c *CustomTemplatesManager) Update(ctx context.Context) {
|
|
|
|
|
for _, provider := range c.providers {
|
|
|
|
|
provider.Update(ctx)
|
|
|
|
|
}
|
2022-12-02 03:57:00 +05:30
|
|
|
}
|
|
|
|
|
|
2023-04-19 17:42:52 -04:00
|
|
|
// NewCustomTemplatesManager returns a new instance of a custom templates manager
|
|
|
|
|
func NewCustomTemplatesManager(options *types.Options) (*CustomTemplatesManager, error) {
|
|
|
|
|
ctm := &CustomTemplatesManager{providers: []Provider{}}
|
|
|
|
|
|
2022-12-21 22:48:43 +05:30
|
|
|
if options.Cloud {
|
2023-04-19 17:42:52 -04:00
|
|
|
// if cloud is enabled, custom templates are Nop
|
|
|
|
|
return ctm, nil
|
2022-12-21 22:48:43 +05:30
|
|
|
}
|
2022-12-02 03:57:00 +05:30
|
|
|
|
2023-05-19 11:36:39 -04:00
|
|
|
// Add GitHub providers
|
2023-04-19 17:42:52 -04:00
|
|
|
githubProviders, err := NewGithubProviders(options)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errorutil.NewWithErr(err).Msgf("could not create github providers for custom templates")
|
2022-12-02 03:57:00 +05:30
|
|
|
}
|
2023-04-19 17:42:52 -04:00
|
|
|
for _, v := range githubProviders {
|
|
|
|
|
ctm.providers = append(ctm.providers, v)
|
2022-12-02 03:57:00 +05:30
|
|
|
}
|
2023-04-17 04:18:06 -04:00
|
|
|
|
2023-05-19 11:36:39 -04:00
|
|
|
// Add AWS S3 providers
|
2023-04-19 17:42:52 -04:00
|
|
|
s3Providers, err := NewS3Providers(options)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errorutil.NewWithErr(err).Msgf("could not create s3 providers for custom templates")
|
|
|
|
|
}
|
|
|
|
|
for _, v := range s3Providers {
|
|
|
|
|
ctm.providers = append(ctm.providers, v)
|
|
|
|
|
}
|
2023-04-17 04:18:06 -04:00
|
|
|
|
2023-04-19 17:42:52 -04:00
|
|
|
// Add Azure providers
|
|
|
|
|
azureProviders, err := NewAzureProviders(options)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errorutil.NewWithErr(err).Msgf("could not create azure providers for custom templates")
|
|
|
|
|
}
|
|
|
|
|
for _, v := range azureProviders {
|
|
|
|
|
ctm.providers = append(ctm.providers, v)
|
2023-04-17 04:18:06 -04:00
|
|
|
}
|
2023-04-19 17:42:52 -04:00
|
|
|
|
|
|
|
|
// Add GitLab providers
|
|
|
|
|
gitlabProviders, err := NewGitlabProviders(options)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errorutil.NewWithErr(err).Msgf("could not create gitlab providers for custom templates")
|
|
|
|
|
}
|
|
|
|
|
for _, v := range gitlabProviders {
|
|
|
|
|
ctm.providers = append(ctm.providers, v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ctm, nil
|
2022-12-02 03:57:00 +05:30
|
|
|
}
|