port of semgrep fixes oss (#14488)

This commit is contained in:
Hridoy Roy 2022-03-15 13:17:55 -07:00 committed by GitHub
parent ff62a34487
commit 1558387af4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 24 deletions

View File

@ -90,6 +90,12 @@ func (s *GRPCStorageServer) List(ctx context.Context, args *pb.StorageListArgs)
func (s *GRPCStorageServer) Get(ctx context.Context, args *pb.StorageGetArgs) (*pb.StorageGetReply, error) {
storageEntry, err := s.impl.Get(ctx, args.Key)
if storageEntry == nil {
return &pb.StorageGetReply{
Entry: nil,
Err: pb.ErrToString(err),
}, nil
}
return &pb.StorageGetReply{
Entry: pb.LogicalStorageEntryToProtoStorageEntry(storageEntry),
Err: pb.ErrToString(err),

View File

@ -158,37 +158,30 @@ func (c *UIConfig) get(ctx context.Context) (*uiConfigEntry, error) {
if err != nil {
return nil, err
}
configRaw, uiConfigGetErr := c.barrierStorage.Get(ctx, uiConfigKey)
configRaw, err := c.barrierStorage.Get(ctx, uiConfigKey)
if err == nil {
if configRaw == nil {
return nil, nil
}
config := new(uiConfigEntry)
if err := json.Unmarshal(configRaw.Value, config); err != nil {
return nil, err
}
// Respond with error only if not sealed, otherwise do not throw the error
if uiConfigGetErr != nil && !strings.Contains(uiConfigGetErr.Error(), ErrBarrierSealed.Error()) {
return nil, uiConfigGetErr
}
if configRaw == nil {
return nil, nil
}
config := new(uiConfigEntry)
if config == nil {
return nil, nil
}
if err := json.Unmarshal(configRaw.Value, config); err != nil {
return nil, err
}
if uiConfigGetErr == nil {
// Check that plaintext value matches barrier value, if not sync values
if plaintextConfigRaw == nil || bytes.Compare(plaintextConfigRaw.Value, configRaw.Value) != 0 {
if err := c.save(ctx, config); err != nil {
return nil, err
}
}
return config, nil
}
// Respond with error if not sealed
if !strings.Contains(err.Error(), ErrBarrierSealed.Error()) {
return nil, err
}
// Respond with plaintext value
if configRaw == nil {
return nil, nil
}
config := new(uiConfigEntry)
if err := json.Unmarshal(plaintextConfigRaw.Value, config); err != nil {
return nil, err
}
return config, nil
}