mirror of
https://github.com/openziti/ziti.git
synced 2026-09-22 10:33:40 +00:00
105 lines
3.5 KiB
Go
105 lines
3.5 KiB
Go
/*
|
|
Copyright NetFoundry Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package db
|
|
|
|
import (
|
|
"github.com/michaelquigley/pfxlog"
|
|
"github.com/openziti/storage/boltz"
|
|
)
|
|
|
|
const (
|
|
FieldPostureCheckProcessMultiOsType = "osType"
|
|
FieldPostureCheckProcessMultiPath = "path"
|
|
FieldPostureCheckProcessMultiHashes = "hashes"
|
|
FieldPostureCheckProcessMultiSignerFingerprints = "signerFingerprints"
|
|
FieldPostureCheckProcessMultiProcesses = "processes"
|
|
)
|
|
|
|
type PostureCheckProcessMulti struct {
|
|
Semantic string `json:"semantic"`
|
|
Processes []*ProcessMulti `json:"processes"`
|
|
}
|
|
|
|
type ProcessMulti struct {
|
|
OsType string `json:"osType"`
|
|
Path string `json:"path"`
|
|
Hashes []string `json:"hashes"`
|
|
SignerFingerprints []string `json:"signerFingerprints"`
|
|
}
|
|
|
|
func newPostureCheckProcessMulti() PostureCheckSubType {
|
|
return &PostureCheckProcessMulti{
|
|
Semantic: "",
|
|
Processes: nil,
|
|
}
|
|
}
|
|
|
|
func (entity *PostureCheckProcessMulti) LoadValues(bucket *boltz.TypedBucket) {
|
|
entity.Semantic = bucket.GetStringOrError(FieldSemantic)
|
|
|
|
processesBucket := bucket.GetBucket(FieldPostureCheckProcessMultiProcesses)
|
|
|
|
processCursor := processesBucket.Cursor()
|
|
|
|
for key, _ := processCursor.First(); key != nil; key, _ = processCursor.Next() {
|
|
procBucket := processesBucket.GetBucket(string(key))
|
|
proc := &ProcessMulti{}
|
|
|
|
proc.Path = procBucket.GetStringOrError(FieldPostureCheckProcessMultiPath)
|
|
proc.OsType = procBucket.GetStringOrError(FieldPostureCheckProcessMultiOsType)
|
|
proc.SignerFingerprints = procBucket.GetStringList(FieldPostureCheckProcessMultiSignerFingerprints)
|
|
proc.Hashes = procBucket.GetStringList(FieldPostureCheckProcessMultiHashes)
|
|
|
|
entity.Processes = append(entity.Processes, proc)
|
|
}
|
|
}
|
|
|
|
func (entity *PostureCheckProcessMulti) SetValues(ctx *boltz.PersistContext, bucket *boltz.TypedBucket) {
|
|
bucket.SetString(FieldSemantic, entity.Semantic, ctx.FieldChecker)
|
|
|
|
processesBucket := bucket.GetOrCreateBucket(FieldPostureCheckProcessMultiProcesses)
|
|
|
|
seenKeys := map[string]struct{}{}
|
|
for _, proc := range entity.Processes {
|
|
key := proc.OsType + "-" + proc.Path
|
|
seenKeys[key] = struct{}{}
|
|
|
|
procBucket := processesBucket.GetOrCreateBucket(key)
|
|
|
|
procBucket.SetString(FieldPostureCheckProcessMultiPath, proc.Path, ctx.FieldChecker)
|
|
procBucket.SetString(FieldPostureCheckProcessMultiOsType, proc.OsType, ctx.FieldChecker)
|
|
procBucket.SetStringList(FieldPostureCheckProcessMultiHashes, proc.Hashes, ctx.FieldChecker)
|
|
procBucket.SetStringList(FieldPostureCheckProcessMultiSignerFingerprints, proc.SignerFingerprints, ctx.FieldChecker)
|
|
}
|
|
|
|
processCursor := processesBucket.Cursor()
|
|
|
|
var removeKeys [][]byte
|
|
for key, _ := processCursor.First(); key != nil; key, _ = processCursor.Next() {
|
|
if _, ok := seenKeys[string(key)]; !ok {
|
|
removeKeys = append(removeKeys, key)
|
|
}
|
|
}
|
|
|
|
for _, key := range removeKeys {
|
|
if err := processesBucket.DeleteBucket(key); err != nil {
|
|
pfxlog.Logger().Debugf("error deleting multi process key %s: %v", string(key), err)
|
|
}
|
|
|
|
}
|
|
}
|