Skip to content

Commit 61ec565

Browse files
Implement translib backend logic for the gNSI Authz feature
This commit adds the necessary transformer code to read authorization policy counters and related state from the Redis databases.
1 parent fd092c6 commit 61ec565

File tree

5 files changed

+456
-5
lines changed

5 files changed

+456
-5
lines changed

translib/log/level.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package log
2+
3+
import "github.com/golang/glog"
4+
5+
const (
6+
ERROR glog.Level = iota
7+
WARNING
8+
INFO
9+
DEBUG
10+
)

translib/tlerr/tlerr.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ package tlerr
3131

3232
import (
3333
// "fmt"
34+
"errors"
3435
"github.com/Azure/sonic-mgmt-common/cvl"
36+
lvl "github.com/Azure/sonic-mgmt-common/translib/log"
37+
"github.com/golang/glog"
3538
"golang.org/x/text/language"
3639
"golang.org/x/text/message"
3740
// "errors"
@@ -190,3 +193,32 @@ type TranslibBusy struct {
190193
func (e TranslibBusy) Error() string {
191194
return p.Sprintf("Translib Busy")
192195
}
196+
197+
func IsTranslibRedisClientEntryNotExist(err error) bool {
198+
switch err.(type) {
199+
case *TranslibRedisClientEntryNotExist, TranslibRedisClientEntryNotExist:
200+
return true
201+
}
202+
return false
203+
}
204+
205+
// isDBEntryNotExistError returns `true` if `err` is (or wraps around) an error
206+
// of type `TranslibRedisClientEntryNotExist`.
207+
func isDBEntryNotExistError(err error) bool {
208+
if IsTranslibRedisClientEntryNotExist(err) {
209+
return true
210+
}
211+
pdberr := &TranslibRedisClientEntryNotExist{}
212+
return errors.As(err, &TranslibRedisClientEntryNotExist{}) || errors.As(err, &pdberr)
213+
}
214+
215+
// ErrorSeverity based on `err` calculates the VLOG level.
216+
func ErrorSeverity(err error) glog.Level {
217+
if err == nil {
218+
return lvl.DEBUG
219+
}
220+
if isDBEntryNotExistError(err) {
221+
return lvl.DEBUG
222+
}
223+
return lvl.ERROR
224+
}

translib/transformer/subscribe_req_xlate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type subscribeReqXlator struct {
4444
type subscribeReq struct {
4545
reqLogId string
4646
reqUri string
47+
requestURI string
4748
ygPath string
4849
isTrgtPathWldcrd bool
4950
gPath *gnmipb.Path
@@ -478,7 +479,7 @@ func (pathXltr *subscribePathXlator) handleSubtreeNodeXlate() error {
478479
log.Info(pathXltr.subReq.reqLogId, "handleSubtreeNodeXlate: handleSubtreeNodeXlate: uriSubtree: ", uriSubtree)
479480
}
480481

481-
subInParam := XfmrSubscInParams{uriSubtree, pathXltr.subReq.dbs, make(RedisDbMap), TRANSLATE_SUBSCRIBE}
482+
subInParam := XfmrSubscInParams{uri: uriSubtree, requestURI: pathXltr.subReq.requestURI, dbs: pathXltr.subReq.dbs, dbDataMap: make(RedisDbMap), subscProc: TRANSLATE_SUBSCRIBE}
482483
subOutPram, subErr := xfmrSubscSubtreeHandler(subInParam, ygXpathInfo.xfmrFunc)
483484

484485
if log.V(dbLgLvl) {

translib/transformer/xfmr_interface.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ type notificationOpts struct {
7676

7777
// XfmrSubscInParams represents input to subscribe subtree callbacks - request uri, DBs info access-pointers, DB info for request uri and subscription process type from translib.
7878
type XfmrSubscInParams struct {
79-
uri string
80-
dbs [db.MaxDB]*db.DB
81-
dbDataMap RedisDbMap
82-
subscProc SubscProcType
79+
uri string
80+
requestURI string
81+
dbs [db.MaxDB]*db.DB
82+
dbDataMap RedisDbMap
83+
subscProc SubscProcType
8384
}
8485

8586
// XfmrSubscOutParams represents output from subscribe subtree callback - DB data for request uri, Need cache, OnChange, subscription preference and interval.

0 commit comments

Comments
 (0)