Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/external/customtemplates/templates_provider.go
2070 views
1
package customtemplates
2
3
import (
4
"context"
5
6
"github.com/projectdiscovery/nuclei/v3/pkg/types"
7
"github.com/projectdiscovery/utils/errkit"
8
)
9
10
type Provider interface {
11
Download(ctx context.Context)
12
Update(ctx context.Context)
13
}
14
15
// CustomTemplatesManager is a manager for custom templates
16
type CustomTemplatesManager struct {
17
providers []Provider
18
}
19
20
// Download downloads the custom templates
21
func (c *CustomTemplatesManager) Download(ctx context.Context) {
22
for _, provider := range c.providers {
23
provider.Download(ctx)
24
}
25
}
26
27
// Update updates the custom templates
28
func (c *CustomTemplatesManager) Update(ctx context.Context) {
29
for _, provider := range c.providers {
30
provider.Update(ctx)
31
}
32
}
33
34
// NewCustomTemplatesManager returns a new instance of a custom templates manager
35
func NewCustomTemplatesManager(options *types.Options) (*CustomTemplatesManager, error) {
36
ctm := &CustomTemplatesManager{providers: []Provider{}}
37
38
// Add GitHub providers
39
githubProviders, err := NewGitHubProviders(options)
40
if err != nil {
41
errx := errkit.FromError(err)
42
errx.Msgf("could not create github providers for custom templates")
43
return nil, errx
44
}
45
for _, v := range githubProviders {
46
ctm.providers = append(ctm.providers, v)
47
}
48
49
// Add AWS S3 providers
50
s3Providers, err := NewS3Providers(options)
51
if err != nil {
52
errx := errkit.FromError(err)
53
errx.Msgf("could not create s3 providers for custom templates")
54
return nil, errx
55
}
56
for _, v := range s3Providers {
57
ctm.providers = append(ctm.providers, v)
58
}
59
60
// Add Azure providers
61
azureProviders, err := NewAzureProviders(options)
62
if err != nil {
63
errx := errkit.FromError(err)
64
errx.Msgf("could not create azure providers for custom templates")
65
return nil, errx
66
}
67
for _, v := range azureProviders {
68
ctm.providers = append(ctm.providers, v)
69
}
70
71
// Add GitLab providers
72
gitlabProviders, err := NewGitLabProviders(options)
73
if err != nil {
74
errx := errkit.FromError(err)
75
errx.Msgf("could not create gitlab providers for custom templates")
76
return nil, errx
77
}
78
for _, v := range gitlabProviders {
79
ctm.providers = append(ctm.providers, v)
80
}
81
82
return ctm, nil
83
}
84
85