Add a path return limit for the git import system to be limited to the package name length in path entries.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0d4036d05c
commit
976d356398
12
conf/zone.go
12
conf/zone.go
@ -8,12 +8,13 @@ type ZoneYaml struct {
|
|||||||
CssURL string `yaml:"cssURL"`
|
CssURL string `yaml:"cssURL"`
|
||||||
HavePageContents bool `yaml:"havePageContents"`
|
HavePageContents bool `yaml:"havePageContents"`
|
||||||
BasePath string `yaml:"basePath"`
|
BasePath string `yaml:"basePath"`
|
||||||
UsernameProvided bool `yaml:"usernameProvided"`
|
UsernameProvided bool `yaml:"usernameProvided"` //If set, the outputter will do /{user}/{repo}/ for repos rather than /{repo}/ ; Should really be named usernameProvidedByRequest
|
||||||
Username string `yaml:"username"`
|
Username string `yaml:"username"`
|
||||||
BasePrefixURL string `yaml:"basePrefixURL"`
|
BasePrefixURL string `yaml:"basePrefixURL"`
|
||||||
SuffixDirectoryURL string `yaml:"suffixDirectoryURL"`
|
SuffixDirectoryURL string `yaml:"suffixDirectoryURL"`
|
||||||
SuffixFileURL string `yaml:"suffixFileURL"`
|
SuffixFileURL string `yaml:"suffixFileURL"`
|
||||||
RangeSupported bool `yaml:"rangeSupported"`
|
RangeSupported bool `yaml:"rangeSupported"`
|
||||||
|
PathLengthLimit uint `yaml:"pathLengthLimit"` //The length of the path (Number of entries in the path) to return in the responses; (If 0: defaults to 1, if the username is not expected to be provided by the request, otherwise defaulting to 2)
|
||||||
CacheSettings CacheSettingsYaml `yaml:"cacheSettings"`
|
CacheSettings CacheSettingsYaml `yaml:"cacheSettings"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,11 +23,20 @@ func (zy ZoneYaml) GetPackageMetaTagOutputter() *outputMeta.PackageMetaTagOutput
|
|||||||
if !zy.UsernameProvided {
|
if !zy.UsernameProvided {
|
||||||
theUsername = zy.Username
|
theUsername = zy.Username
|
||||||
}
|
}
|
||||||
|
pthLength := zy.PathLengthLimit
|
||||||
|
if pthLength == 0 {
|
||||||
|
if zy.UsernameProvided {
|
||||||
|
pthLength = 2
|
||||||
|
} else {
|
||||||
|
pthLength = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
return &outputMeta.PackageMetaTagOutputter{
|
return &outputMeta.PackageMetaTagOutputter{
|
||||||
BasePath: zy.BasePath,
|
BasePath: zy.BasePath,
|
||||||
Username: theUsername,
|
Username: theUsername,
|
||||||
BasePrefixURL: zy.BasePrefixURL,
|
BasePrefixURL: zy.BasePrefixURL,
|
||||||
SuffixDirectoryURL: zy.SuffixDirectoryURL,
|
SuffixDirectoryURL: zy.SuffixDirectoryURL,
|
||||||
SuffixFileURL: zy.SuffixFileURL,
|
SuffixFileURL: zy.SuffixFileURL,
|
||||||
|
PathLengthLimit: pthLength,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,12 @@ zones: #An array of zones
|
|||||||
havePageContents: true #Output a header and link to the target repo
|
havePageContents: true #Output a header and link to the target repo
|
||||||
basePath: "localhost" #The base-path, also known as, package name
|
basePath: "localhost" #The base-path, also known as, package name
|
||||||
basePrefixURL: "http://localhost" #The base git URL
|
basePrefixURL: "http://localhost" #The base git URL
|
||||||
usernameProvided: true #If the username would be provided in requests to the server (When false the value of username can be used)
|
usernameProvided: true #If the username is expected to be provided in requests to the server (When false the value of username can be used)
|
||||||
username: "captain-alm" #The username to append to the start of a path under the prefix
|
username: "captain-alm" #The username to append to the start of a path under the prefix
|
||||||
suffixDirectoryURL: "src/branch/master{/dir}" #The suffix location of the main branch for directory usage
|
suffixDirectoryURL: "src/branch/master{/dir}" #The suffix location of the main branch for directory usage
|
||||||
suffixFileURL: "src/branch/master{/dir}/{file}#L{line}" #The suffix location of the main branch for file usage
|
suffixFileURL: "src/branch/master{/dir}/{file}#L{line}" #The suffix location of the main branch for file usage
|
||||||
rangeSupported: true #Are range requests supported
|
rangeSupported: true #Are range requests supported
|
||||||
|
pathLengthLimit: 0 #The length of the returned paths in the responses (Number of path entries); (If 0: defaults to 1, if the username is not expected to be provided by the request, otherwise defaulting to 2)
|
||||||
cacheSettings: #Cache settings
|
cacheSettings: #Cache settings
|
||||||
maxAge: 0 #The maximum age of the cache
|
maxAge: 0 #The maximum age of the cache
|
||||||
notModifiedUsingLastModified: true #Are the conditional headers attached to Last-Modified used to work out if to send a 304 Cache Redirect
|
notModifiedUsingLastModified: true #Are the conditional headers attached to Last-Modified used to work out if to send a 304 Cache Redirect
|
||||||
|
@ -11,6 +11,7 @@ type PackageMetaTagOutputter struct {
|
|||||||
BasePrefixURL string
|
BasePrefixURL string
|
||||||
SuffixDirectoryURL string
|
SuffixDirectoryURL string
|
||||||
SuffixFileURL string
|
SuffixFileURL string
|
||||||
|
PathLengthLimit uint //The number of path entries in the go import paths
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pkgMTO *PackageMetaTagOutputter) GetMetaTags(pathIn string) string {
|
func (pkgMTO *PackageMetaTagOutputter) GetMetaTags(pathIn string) string {
|
||||||
@ -19,12 +20,27 @@ func (pkgMTO *PackageMetaTagOutputter) GetMetaTags(pathIn string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (pkgMTO *PackageMetaTagOutputter) GetMetaContentForGoImport(pathIn string) string {
|
func (pkgMTO *PackageMetaTagOutputter) GetMetaContentForGoImport(pathIn string) string {
|
||||||
return pkgMTO.getPrefix(pathIn) + " git " + pkgMTO.getHomeURL(pathIn)
|
pathLoc := pkgMTO.GetPath(pathIn)
|
||||||
|
return pkgMTO.getPrefix(pathLoc) + " git " + pkgMTO.getHomeURL(pathLoc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pkgMTO *PackageMetaTagOutputter) GetMetaContentForGoSource(pathIn string) string {
|
func (pkgMTO *PackageMetaTagOutputter) GetMetaContentForGoSource(pathIn string) string {
|
||||||
return pkgMTO.getPrefix(pathIn) + " " + pkgMTO.getHomeURL(pathIn) + " " +
|
pathLoc := pkgMTO.GetPath(pathIn)
|
||||||
pkgMTO.getDirectoryURL(pathIn) + " " + pkgMTO.getFileURL(pathIn)
|
return pkgMTO.getPrefix(pathLoc) + " " + pkgMTO.getHomeURL(pathLoc) + " " +
|
||||||
|
pkgMTO.getDirectoryURL(pathLoc) + " " + pkgMTO.getFileURL(pathLoc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pkgMTO *PackageMetaTagOutputter) GetPath(pathIn string) string {
|
||||||
|
cleaned := path.Clean(pathIn)
|
||||||
|
if cleaned == "/" || cleaned == "." {
|
||||||
|
return cleaned
|
||||||
|
}
|
||||||
|
split := strings.Split(cleaned, "/")
|
||||||
|
toReturn := ""
|
||||||
|
for i := 1; i < len(split) && i < int(pkgMTO.PathLengthLimit)+1; i++ {
|
||||||
|
toReturn += split[i] + "/"
|
||||||
|
}
|
||||||
|
return toReturn[:len(toReturn)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pkgMTO *PackageMetaTagOutputter) assureBasePrefixURL() (failed bool) {
|
func (pkgMTO *PackageMetaTagOutputter) assureBasePrefixURL() (failed bool) {
|
||||||
|
@ -20,8 +20,8 @@ func (htm handlerTemplateMarshal) GetGoSourceMetaContent() string {
|
|||||||
|
|
||||||
func (htm handlerTemplateMarshal) GetLink() string {
|
func (htm handlerTemplateMarshal) GetLink() string {
|
||||||
if htm.PageHandler.MetaOutput.Username == "" {
|
if htm.PageHandler.MetaOutput.Username == "" {
|
||||||
return htm.PageHandler.MetaOutput.BasePrefixURL + "/" + strings.TrimLeft(path.Clean(htm.RequestPath), "/")
|
return htm.PageHandler.MetaOutput.BasePrefixURL + "/" + strings.TrimLeft(path.Clean(htm.PageHandler.MetaOutput.GetPath(htm.RequestPath)), "/")
|
||||||
} else {
|
} else {
|
||||||
return htm.PageHandler.MetaOutput.BasePrefixURL + "/" + strings.TrimLeft(path.Join(htm.PageHandler.MetaOutput.Username, htm.RequestPath), "/")
|
return htm.PageHandler.MetaOutput.BasePrefixURL + "/" + strings.TrimLeft(path.Join(htm.PageHandler.MetaOutput.Username, htm.PageHandler.MetaOutput.GetPath(htm.RequestPath)), "/")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user