-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide utility method in non-internal package to retrieve providers …
…configuration (closes #117)
- Loading branch information
1 parent
b9abe6e
commit a044663
Showing
2 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package stratus | ||
|
||
import ( | ||
"errors" | ||
"github.com/datadog/stratus-red-team/internal/providers" | ||
) | ||
|
||
func AWSProvider() *providers.AWSProvider { | ||
return providers.AWS() | ||
} | ||
|
||
func K8sProvider() *providers.K8sProvider { | ||
return providers.K8s() | ||
} | ||
|
||
// EnsureAuthenticated ensures that the current user is properly authenticated against a specific platform | ||
func EnsureAuthenticated(platform Platform) error { | ||
switch platform { | ||
case AWS: | ||
if !providers.AWS().IsAuthenticatedAgainstAWS() { | ||
return errors.New("you are not authenticated against AWS, or you have not set your region. " + | ||
"Make sure you are authenticated against AWS, and you have a default region set in your AWS config " + | ||
"or environment (export AWS_DEFAULT_REGION=us-east-1)") | ||
} | ||
case Kubernetes: | ||
if !providers.K8s().IsAuthenticated() { | ||
return errors.New("You do not have a kubeconfig set up, or you do not have proper permissions for " + | ||
"this cluster. Make sure you have proper credentials set in " + providers.GetKubeConfigPath()) | ||
} | ||
default: | ||
return errors.New("unhandled platform " + string(platform)) | ||
} | ||
|
||
return nil | ||
} |