Path: blob/dev/pkg/external/customtemplates/templates_provider.go
2070 views
package customtemplates12import (3"context"45"github.com/projectdiscovery/nuclei/v3/pkg/types"6"github.com/projectdiscovery/utils/errkit"7)89type Provider interface {10Download(ctx context.Context)11Update(ctx context.Context)12}1314// CustomTemplatesManager is a manager for custom templates15type CustomTemplatesManager struct {16providers []Provider17}1819// Download downloads the custom templates20func (c *CustomTemplatesManager) Download(ctx context.Context) {21for _, provider := range c.providers {22provider.Download(ctx)23}24}2526// Update updates the custom templates27func (c *CustomTemplatesManager) Update(ctx context.Context) {28for _, provider := range c.providers {29provider.Update(ctx)30}31}3233// NewCustomTemplatesManager returns a new instance of a custom templates manager34func NewCustomTemplatesManager(options *types.Options) (*CustomTemplatesManager, error) {35ctm := &CustomTemplatesManager{providers: []Provider{}}3637// Add GitHub providers38githubProviders, err := NewGitHubProviders(options)39if err != nil {40errx := errkit.FromError(err)41errx.Msgf("could not create github providers for custom templates")42return nil, errx43}44for _, v := range githubProviders {45ctm.providers = append(ctm.providers, v)46}4748// Add AWS S3 providers49s3Providers, err := NewS3Providers(options)50if err != nil {51errx := errkit.FromError(err)52errx.Msgf("could not create s3 providers for custom templates")53return nil, errx54}55for _, v := range s3Providers {56ctm.providers = append(ctm.providers, v)57}5859// Add Azure providers60azureProviders, err := NewAzureProviders(options)61if err != nil {62errx := errkit.FromError(err)63errx.Msgf("could not create azure providers for custom templates")64return nil, errx65}66for _, v := range azureProviders {67ctm.providers = append(ctm.providers, v)68}6970// Add GitLab providers71gitlabProviders, err := NewGitLabProviders(options)72if err != nil {73errx := errkit.FromError(err)74errx.Msgf("could not create gitlab providers for custom templates")75return nil, errx76}77for _, v := range gitlabProviders {78ctm.providers = append(ctm.providers, v)79}8081return ctm, nil82}838485