Skip to content

Commit

Permalink
feat: added template-url support in template flag feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Ice3man543 committed Aug 25, 2023
1 parent c7ec638 commit 2773927
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions v2/pkg/catalog/loader/loader.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package loader

import (
"fmt"
"net/url"
"os"
"sort"
"strings"

"github.com/pkg/errors"
"github.com/projectdiscovery/gologger"
Expand Down Expand Up @@ -120,6 +123,20 @@ func New(config *Config) (*Store, error) {
finalWorkflows: config.Workflows,
}

// Do a check to see if we have URLs in templates flag, if so
// we need to processs them separately and remove them from the initial list
var templatesFinal []string
var urlTemplates []string
for _, template := range config.Templates {
if _, err := url.ParseRequestURI(template); err == nil {
urlTemplates = append(urlTemplates, handleTemplatesEditorURLs(template))
} else {
templatesFinal = append(templatesFinal, template)
}
}
store.finalTemplates = templatesFinal
config.TemplateURLs = append(config.TemplateURLs, urlTemplates...)

urlBasedTemplatesProvided := len(config.TemplateURLs) > 0 || len(config.WorkflowURLs) > 0
if urlBasedTemplatesProvided {
remoteTemplates, remoteWorkflows, err := getRemoteTemplatesAndWorkflows(config.TemplateURLs, config.WorkflowURLs, config.RemoteTemplateDomainList)
Expand All @@ -145,6 +162,22 @@ func New(config *Config) (*Store, error) {
return store, nil
}

func handleTemplatesEditorURLs(input string) string {
parsed, err := url.Parse(input)
if err != nil {
return input
}
if !strings.HasSuffix(parsed.Hostname(), "ondigitalocean.app") {
return input
}
if strings.HasSuffix(parsed.Path, ".yaml") {
return input
}
parsed.Path = fmt.Sprintf("%s.yaml", parsed.Path)
finalURL := parsed.String()
return finalURL
}

// Templates returns all the templates in the store
func (store *Store) Templates() []*templates.Template {
return store.templates
Expand Down

0 comments on commit 2773927

Please sign in to comment.