Best Python code snippet using localstack_python
Credential.py
Source:Credential.py
...22 :param aws_session_token: AWS session token value23 :type aws_session_token: Optional[str]24 """25 self.__cache__ = {}26 self.set_aws_access_key_id(aws_access_key_id)27 self.set_aws_secret_access_key(aws_secret_access_key)28 self.set_aws_session_token(aws_session_token)29 self.set_iam_role_arn(iam_role_arn)30 self.set_profile_name(profile_name)31 def get_boto3_session(self, region_name, cache=True) -> Session:32 """33 Use these credentials to return a Boto3 session object34 :param region_name: The AWS region for the session to be created in35 :type region_name: str36 :param cache: Flag indicating the credential should be cached for future get_boto3_session() calls37 :type cache: bool38 :return: Boto3 Session object39 40 :raise Exception: on authentication failure41 """42 session_name = str(self.__aws_access_key_id__) or ''43 session_name = session_name + str(self.__aws_secret_access_key__) or ''44 session_name = session_name + str(self.__aws_session_token__) or ''45 session_name = session_name + str(self.__profile_name__) or ''46 session_name = session_name + str(region_name)47 session_name = hashlib.md5(session_name.encode())48 session_name = str(session_name.hexdigest())49 # If we are caching, return cached copy50 if cache is True and session_name in self.__cache__.keys():51 return self.__cache__[session_name]52 session = boto3.session.Session(53 aws_access_key_id=self.__aws_access_key_id__,54 aws_secret_access_key=self.__aws_secret_access_key__,55 aws_session_token=self.__aws_session_token__,56 region_name=region_name,57 profile_name=self.__profile_name__58 )59 # If we are caching, persist this session to the cache60 if cache is True:61 self.__cache__[session_name] = session62 return session63 def get_profile_name(self) -> Optional[str]:64 """65 Retrieve AWS profile name66 :return: AWS profile name or None if not set67 """68 return self.__profile_name__69 def set_profile_name(self, profile_name) -> None:70 """71 Set AWS profile name72 :param profile_name: AWS profile name73 :type profile_name: Optional[str]74 """75 self.__profile_name__ = profile_name76 def get_iam_role_arn(self) -> Optional[str]:77 """78 Retrieve AWS IAM role ARN79 :return: AWS IAM role ARN or None if not set80 """81 return self.__iam_role_arn__82 def set_iam_role_arn(self, iam_role_arn) -> None:83 """84 Set AWS IAM role ARN85 :param iam_role_arn: AWS IAM role ARN86 :type iam_role_arn: Optional[str]87 """88 self.__iam_role_arn__ = iam_role_arn89 def get_aws_access_key_id(self) -> Optional[str]:90 """91 Retrieve AWS access key ID92 :return: AWS access key ID or None if not set93 """94 return self.__aws_access_key_id__95 def set_aws_access_key_id(self, aws_access_key_id) -> None:96 """97 Set AWS access key ID98 :param aws_access_key_id: AWS access key ID value99 :type aws_access_key_id: Optional[str]100 """101 self.__aws_access_key_id__ = aws_access_key_id102 def get_aws_secret_access_key(self) -> Optional[str]:103 """104 Retrieve AWS access key secret105 :return: AWS access key secret or None if not set106 """107 return self.__aws_secret_access_key__108 def set_aws_secret_access_key(self, aws_secret_access_key) -> None:109 """...
auth.py
Source:auth.py
...26 access_key_id = extract_access_key_id_from_auth_header(context.request.headers)27 if not access_key_id:28 access_key_id = TEST_AWS_ACCESS_KEY_ID29 # Save the request access key ID in the current thread local storage30 set_aws_access_key_id(access_key_id)31 if account_id_from_header := context.request.headers.get(HEADER_LOCALSTACK_ACCOUNT_ID):32 context.account_id = account_id_from_header33 else:34 context.account_id = get_account_id_from_access_key_id(access_key_id)35 # Make Moto use the same Account ID as LocalStack...
cmd_configure.py
Source:cmd_configure.py
2from alf import utils3@click.command('configure', short_help='Configure keys')4def configure():5 key = input('S3 ACCESS KEY: ')6 utils.set_aws_access_key_id(key)7 key = input('S3 SECRET ACCESS KEY: ')8 utils.set_aws_secret_access_key(key)9 key = input('S3 BUCKET: ')...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!