Files
ziti/controller/sync_strats/marshal.go
T
Andrew Martinez 5dc8a66fe9 addresses #1226 api session certificate issues w/ 3rd party cas
- events during a multi-step transaction were immediately emitting events
  causing out of order and incomplete events to be received,
  specifically API Sessions w/o fingerprints
- API Session Certificates created implicitly during 3rd Party CA auth
  did not properly set all properties
- adds tests
2022-11-04 14:40:07 -04:00

68 lines
2.0 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 sync_strats
import (
"github.com/michaelquigley/pfxlog"
"github.com/openziti/edge/controller/env"
"github.com/openziti/edge/pb/edge_ctrl_pb"
"go.etcd.io/bbolt"
)
func apiSessionToProto(ae *env.AppEnv, token, identityId, apiSessionId string) (*edge_ctrl_pb.ApiSession, error) {
var result *edge_ctrl_pb.ApiSession
err := ae.GetDbProvider().GetDb().View(func(tx *bbolt.Tx) error {
var err error
result, err = apiSessionToProtoWithTx(tx, ae, token, identityId, apiSessionId)
return err
})
return result, err
}
func apiSessionToProtoWithTx(tx *bbolt.Tx, ae *env.AppEnv, token, identityId, apiSessionId string) (*edge_ctrl_pb.ApiSession, error) {
fingerprints, err := getFingerprints(tx, ae, identityId, apiSessionId)
if err != nil {
return nil, err
}
return &edge_ctrl_pb.ApiSession{
Token: token,
CertFingerprints: fingerprints,
Id: apiSessionId,
}, nil
}
func getFingerprints(tx *bbolt.Tx, ae *env.AppEnv, identityId, apiSessionId string) ([]string, error) {
prints := map[string]struct{}{}
err := ae.Managers.ApiSession.VisitFingerprintsForApiSession(tx, identityId, apiSessionId, func(fingerprint string) bool {
prints[fingerprint] = struct{}{}
return false
})
if err != nil {
return nil, err
}
var result []string
for k := range prints {
result = append(result, k)
}
pfxlog.Logger().WithField("apiSessionId", apiSessionId).WithField("fingerprints", result).Debug("resolving fingerprints for apiSession")
return result, nil
}