Added redshift.get_cluster_credentials (#3611)
* Added redshift.get_cluster_credentials * Marked endpoint in list * Removed f string from tests * Python 2.7 compat changes * Fixed parameter retrieval * Formatting * Removed try/catch in favor of if * Changed to existing random_string util Co-authored-by: Andrea Amorosi <aamorosi@amazon.es>
This commit is contained in:
parent
d7f218bfec
commit
5a41866f71
4 changed files with 148 additions and 2 deletions
|
|
@ -8,6 +8,7 @@ from boto3 import Session
|
|||
from moto.compat import OrderedDict
|
||||
from moto.core import BaseBackend, BaseModel, CloudFormationModel
|
||||
from moto.core.utils import iso_8601_datetime_with_milliseconds
|
||||
from moto.utilities.utils import random_string
|
||||
from moto.ec2 import ec2_backends
|
||||
from .exceptions import (
|
||||
ClusterAlreadyExistsFaultError,
|
||||
|
|
@ -941,6 +942,25 @@ class RedshiftBackend(BaseBackend):
|
|||
resource = self._get_resource_from_arn(resource_name)
|
||||
resource.delete_tags(tag_keys)
|
||||
|
||||
def get_cluster_credentials(
|
||||
self, cluster_identifier, db_user, auto_create, duration_seconds
|
||||
):
|
||||
if duration_seconds < 900 or duration_seconds > 3600:
|
||||
raise InvalidParameterValueError(
|
||||
"Token duration must be between 900 and 3600 seconds"
|
||||
)
|
||||
expiration = datetime.datetime.now() + datetime.timedelta(0, duration_seconds)
|
||||
if cluster_identifier in self.clusters:
|
||||
user_prefix = "IAM:" if auto_create is False else "IAMA:"
|
||||
db_user = user_prefix + db_user
|
||||
return {
|
||||
"DbUser": db_user,
|
||||
"DbPassword": random_string(32),
|
||||
"Expiration": expiration,
|
||||
}
|
||||
else:
|
||||
raise ClusterNotFoundError(cluster_identifier)
|
||||
|
||||
|
||||
redshift_backends = {}
|
||||
for region in Session().get_available_regions("redshift"):
|
||||
|
|
|
|||
|
|
@ -694,3 +694,24 @@ class RedshiftResponse(BaseResponse):
|
|||
}
|
||||
}
|
||||
)
|
||||
|
||||
def get_cluster_credentials(self):
|
||||
cluster_identifier = self._get_param("ClusterIdentifier")
|
||||
db_user = self._get_param("DbUser")
|
||||
auto_create = self._get_bool_param("AutoCreate", False)
|
||||
duration_seconds = self._get_int_param("DurationSeconds", 900)
|
||||
|
||||
cluster_credentials = self.redshift_backend.get_cluster_credentials(
|
||||
cluster_identifier, db_user, auto_create, duration_seconds
|
||||
)
|
||||
|
||||
return self.get_response(
|
||||
{
|
||||
"GetClusterCredentialsResponse": {
|
||||
"GetClusterCredentialsResult": cluster_credentials,
|
||||
"ResponseMetadata": {
|
||||
"RequestId": "384ac68d-3775-11df-8963-01868b7c937a"
|
||||
},
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue