Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
goSDN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
goSDN
Commits
3bccf682
Commit
3bccf682
authored
4 years ago
by
Manuel Kieweg
Browse files
Options
Downloads
Patches
Plain Diff
lib path traversal v0.0.1
parent
3a906b3b
Branches
Branches containing commit
Tags
Tags containing commit
3 merge requests
!95
path traversal library
,
!91
"Overhaul Architecture"
,
!90
Develop
Pipeline
#60819
passed with warnings
4 years ago
Stage: test
Stage: deploy
This commit is part of merge request
!91
. Comments created here will be created in the context of that merge request.
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/path-traversal/path_traversal.go
+7
-4
7 additions, 4 deletions
cmd/path-traversal/path_traversal.go
nucleus/util/path_traversal.go
+64
-10
64 additions, 10 deletions
nucleus/util/path_traversal.go
with
71 additions
and
14 deletions
cmd/path-traversal/path_traversal.go
+
7
−
4
Edit
View file @
3bccf682
...
...
@@ -3,16 +3,19 @@ package main
import
(
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util"
"code.fbi.h-da.de/cocsn/yang-models/generated/arista"
log
"github.com/sirupsen/logrus"
)
func
main
()
{
schema
,
_
:=
arista
.
Schema
()
log
.
SetLevel
(
log
.
DebugLevel
)
schema
,
_
:=
arista
.
Schema
()
paths
:=
util
.
NewPaths
()
paths
.
ParseSchema
(
schema
,
"device"
)
for
_
,
v
:=
range
paths
{
for
_
,
v
:=
range
paths
{
v
.
Print
()
}
}
p
:=
paths
.
StringBuilder
()
log
.
Debug
(
p
)
}
This diff is collapsed.
Click to expand it.
nucleus/util/path_traversal.go
+
64
−
10
Edit
View file @
3bccf682
...
...
@@ -4,14 +4,18 @@ import (
"fmt"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/ygot/ytypes"
log
"github.com/sirupsen/logrus"
"strings"
)
const
DELIM
=
"/"
type
PathElement
struct
{
Children
[]
*
PathElement
Name
string
}
func
(
p
*
PathElement
)
Print
()
{
func
(
p
*
PathElement
)
Print
()
{
printPE
(
0
,
p
)
}
...
...
@@ -21,7 +25,7 @@ func printPE(indent int, pe *PathElement) {
}
fmt
.
Println
(
pe
.
Name
)
if
len
(
pe
.
Children
)
>
0
{
for
_
,
p
:=
range
pe
.
Children
{
for
_
,
p
:=
range
pe
.
Children
{
printPE
(
indent
+
1
,
p
)
}
}
...
...
@@ -33,34 +37,84 @@ func NewPaths() Paths {
type
Paths
map
[
string
]
*
PathElement
func
(
p
Paths
)
processEntry
(
e
*
yang
.
Entry
)
*
PathElement
{
func
processEntry
(
e
*
yang
.
Entry
)
*
PathElement
{
if
e
.
Dir
!=
nil
{
elem
:=
&
PathElement
{
Children
:
make
([]
*
PathElement
,
len
(
e
.
Dir
)),
Name
:
e
.
Name
,
}
i
:=
0
for
_
,
v
:=
range
e
.
Dir
{
elem
.
Children
[
i
]
=
p
.
processEntry
(
v
)
for
_
,
v
:=
range
e
.
Dir
{
elem
.
Children
[
i
]
=
processEntry
(
v
)
i
++
}
p
[
e
.
Name
]
=
elem
return
elem
}
leaf
:=
&
PathElement
{
Name
:
e
.
Name
,
Name
:
e
.
Name
,
}
return
leaf
}
func
(
p
Paths
)
ParseSchema
(
schema
*
ytypes
.
Schema
,
root
string
)
error
{
tree
:=
schema
.
SchemaTree
for
_
,
v
:=
range
tree
{
for
k
,
v
:=
range
tree
{
if
v
.
Parent
!=
nil
{
if
v
.
Parent
.
Name
==
root
{
p
.
processEntry
(
v
)
path
:=
processEntry
(
v
)
p
[
k
]
=
path
}
}
}
return
nil
}
\ No newline at end of file
}
func
(
p
Paths
)
StringBuilder
()
[]
string
{
paths
:=
make
([]
string
,
0
)
ch
:=
make
(
chan
string
)
stop
:=
make
(
chan
bool
)
val
:=
make
(
chan
[]
string
)
go
appendix
(
ch
,
stop
,
val
)
for
_
,
v
:=
range
p
{
var
b
strings
.
Builder
stringBuilder
(
ch
,
&
b
,
v
)
}
stop
<-
true
paths
=
<-
val
return
paths
}
func
appendix
(
c
chan
string
,
stop
chan
bool
,
p
chan
[]
string
)
{
paths
:=
make
([]
string
,
0
)
var
sig
bool
for
{
select
{
case
path
:=
<-
c
:
paths
=
append
(
paths
,
path
)
log
.
Debug
(
path
)
case
sig
=
<-
stop
:
log
.
Debug
(
"Signal received: %v"
,
sig
)
}
if
sig
{
break
}
}
p
<-
paths
}
func
stringBuilder
(
ch
chan
string
,
b
*
strings
.
Builder
,
v
*
PathElement
)
{
if
b
.
Len
()
==
0
{
b
.
WriteString
(
"/"
)
}
b
.
WriteString
(
v
.
Name
)
if
v
.
Children
!=
nil
{
b
.
WriteString
(
DELIM
)
for
_
,
c
:=
range
v
.
Children
{
var
b_cpy
strings
.
Builder
b_cpy
.
WriteString
(
b
.
String
())
stringBuilder
(
ch
,
&
b_cpy
,
c
)
}
}
else
{
log
.
Debug
(
"leaf"
)
ch
<-
b
.
String
()
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment