cloudflare/cloudflared

Public

mirrored from https://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
d03469b6d3467d2e79b741bdb9dc9bdfdacaaf6f

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

cmd/cloudflared/path/path.go

30lines · modecode

1package path
2
3import (
4 "fmt"
5 "net/url"
6 "os"
7 "path/filepath"
8 "strings"
9
10 "github.com/cloudflare/cloudflared/cmd/cloudflared/config"
11 "github.com/mitchellh/go-homedir"
12)
13
14// GenerateFilePathFromURL will return a filepath for given access application url
15func GenerateFilePathFromURL(url *url.URL, suffix string) (string, error) {
16 configPath, err := homedir.Expand(config.DefaultConfigDirs[0])
17 if err != nil {
18 return "", err
19 }
20 ok, err := config.FileExists(configPath)
21 if !ok && err == nil {
22 // create config directory if doesn't already exist
23 err = os.Mkdir(configPath, 0700)
24 }
25 if err != nil {
26 return "", err
27 }
28 name := strings.Replace(fmt.Sprintf("%s%s-%s", url.Hostname(), url.EscapedPath(), suffix), "/", "-", -1)
29 return filepath.Join(configPath, name), nil
30}
31