Files
teleport/lib/cloud/azure/errors.go
T
rosstimothy 1b5e0b0082 Reduce exposure of lib/cloud/gcp (#41678)
* Move imds related code into their own packages

Separating imds from cloud vm, kubernetes, etc. prevents the
dependency tree expanding to include extra cloud related things
for callers that only require an imds client.

* Move cloud constructors for types.KubeCluster out of lib/services

lib/services is meant to be a relatively dependency free package
that provides basic interfaces and functions for dealing with
types. NewKubeClusterFromGCPGKE, NewKubeClusterFromAWSEKS, NewKubeClusterFromAzureAKS
caused a slew of cloud related dependencies to be imported in
lib/services which increases binary sizes of client tools.

They have all been moved into lib/srv/discovery/common since
they were only consumed by other code in lib/srv/discovery.

* Decouple servicecfg and lib/auth/keystore

This was the last remaining way for lib/cloud/gcp to slip
into client tools that aren't importing lib/auth directly.

```
goda tree "reach(github.com/gravitational/teleport/tool/tctl...:all, cloud.google.com/go/compute/apiv1)"
├ github.com/gravitational/teleport/tool/tctl
    └ github.com/gravitational/teleport/tool/tctl/common
      ├ github.com/gravitational/teleport/lib/config
        ├ github.com/gravitational/teleport/lib/pam
          └ github.com/gravitational/teleport/lib/service/servicecfg
            └ github.com/gravitational/teleport/lib/auth/keystore
              └ github.com/gravitational/teleport/lib/cloud
                └ github.com/gravitational/teleport/lib/cloud/gcp
                  └ cloud.google.com/go/compute/apiv1
        └ github.com/gravitational/teleport/lib/service/servicecfg ~
      ├ github.com/gravitational/teleport/lib/service/servicecfg ~
      ├ github.com/gravitational/teleport/tool/tctl/common/accessmonitoring
        └ github.com/gravitational/teleport/lib/service/servicecfg ~
      ├ github.com/gravitational/teleport/tool/tctl/common/loginrule
        └ github.com/gravitational/teleport/lib/service/servicecfg ~
      ├ github.com/gravitational/teleport/tool/tctl/sso/configure
        ├ github.com/gravitational/teleport/lib/service/servicecfg ~
        └ github.com/gravitational/teleport/tool/tctl/sso/tester
          └ github.com/gravitational/teleport/lib/service/servicecfg ~
      └ github.com/gravitational/teleport/tool/tctl/sso/tester ~
```

* fix lints

* tidy integrations/event-handler

* fix license

* fix: only populate cloud clients if aws kms configured
2024-05-17 10:29:02 +00:00

55 lines
1.7 KiB
Go

/*
* Teleport
* Copyright (C) 2023 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package azure
import (
"errors"
"net/http"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/gravitational/trace"
)
// ConvertResponseError converts `error` into Azure Response error.
// to trace error. If the provided error is not a `ResponseError` it returns.
// the error without modifying it.
func ConvertResponseError(err error) error {
if err == nil {
return nil
}
var responseErr *azcore.ResponseError
var authenticationFailedErr *azidentity.AuthenticationFailedError
switch {
case errors.As(err, &responseErr):
switch responseErr.StatusCode {
case http.StatusForbidden:
return trace.AccessDenied(responseErr.Error())
case http.StatusConflict:
return trace.AlreadyExists(responseErr.Error())
case http.StatusNotFound:
return trace.NotFound(responseErr.Error())
}
case errors.As(err, &authenticationFailedErr):
return trace.AccessDenied(authenticationFailedErr.Error())
}
return err // Return unmodified.
}