mirror of
https://github.com/gravitational/teleport.git
synced 2026-11-05 03:33:24 +08:00
* Vendor slack plugin and supporting libraries * Fix up plugin integration tests (wip) * Run GCI on vendored code * Use newtype instead of type alias golangci-lint currently panics on this, "skip-files" et al don't help, as it is a linter panic, not an error See https://github.com/dominikh/go-tools/commit/d717045480130461e1e777ead7f2981621f0d9f0 * Remove long-runing plugins tests from difftest * Move access plugin tests to unit-tests-integrations
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
// Copyright 2023 Gravitational, 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
|
|
//
|
|
// http://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 lib
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"github.com/gravitational/trace"
|
|
"github.com/gravitational/trace/trail"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// TODO: remove this when trail.FromGRPC will understand additional error codes
|
|
func FromGRPC(err error) error {
|
|
switch {
|
|
case err == io.EOF:
|
|
fallthrough
|
|
case status.Code(err) == codes.Canceled, err == context.Canceled:
|
|
fallthrough
|
|
case status.Code(err) == codes.DeadlineExceeded, err == context.DeadlineExceeded:
|
|
return trace.Wrap(err)
|
|
default:
|
|
return trail.FromGRPC(err)
|
|
}
|
|
}
|
|
|
|
// TODO: remove this when trail.FromGRPC will understand additional error codes
|
|
func IsCanceled(err error) bool {
|
|
err = trace.Unwrap(err)
|
|
return err == context.Canceled || status.Code(err) == codes.Canceled
|
|
}
|
|
|
|
// TODO: remove this when trail.FromGRPC will understand additional error codes
|
|
func IsDeadline(err error) bool {
|
|
err = trace.Unwrap(err)
|
|
return err == context.DeadlineExceeded || status.Code(err) == codes.DeadlineExceeded
|
|
}
|