How to use create_authorizer method in localstack

Best Python code snippet using localstack_python

access.py

Source:access.py Github

copy

Full Screen

...14GROUPS_TOML = ".groups.toml"15TOKENS_TOML = ".tokens.toml"16GLOBUS_SDK_TUTORIAL = "https://globus-sdk-python.readthedocs.io/en/stable/tutorial.html"17DEVELOPER_PAGE = "https://auth.globus.org/v2/web/developers"18def create_authorizer(tokens_file, key, client):19 token_data = toml.load(tokens_file)20 auth_rt = token_data[key]["refresh_token"]21 auth_at = token_data[key]["access_token"]22 expiration = token_data[key]["expires_at_seconds"]23 authorizer = globus_sdk.RefreshTokenAuthorizer(24 auth_rt, client, access_token=auth_at, expires_at=expiration)25 return authorizer26 27def get_auth_client(client):28 auth_authorizer = create_authorizer(TOKENS_TOML, 'auth', client)29 ac = AuthClient(authorizer=auth_authorizer)30 return ac31def get_groups_client(client):32 groups_authorizer = create_authorizer(TOKENS_TOML, 'groups', client)33 gc = GroupsClient(authorizer=groups_authorizer)34 return gc35def get_transfer_client(client):36 transfer_authorizer = create_authorizer(TOKENS_TOML, 'transfer', client)37 tc = globus_sdk.TransferClient(authorizer=transfer_authorizer)38 return tc39def get_client_id(f=CLIENT_TOML):40 try:41 client_id = toml.load(f)['client_id']42 except:43 print (f"Could not find or read Client ID from {CLIENT_TOML} file.\n")44 print (f"If you haven't done so already, register a Globus app and get a Client ID as described here: {GLOBUS_SDK_TUTORIAL}\n")45 print (f"If your already registered the app, you can look up your Client ID here: {DEVELOPER_PAGE}")46 client_id = input("Please enter your client ID: ").strip()47 with open(CLIENT_TOML, "w") as f:48 toml.dump({"client_id": client_id}, f)49 return client_id50 ...

Full Screen

Full Screen

iot_custom_authorizer_provider.py

Source:iot_custom_authorizer_provider.py Github

copy

Full Screen

...16 custom_authorizer_function_arn = event["ResourceProperties"]["authorizer_function_arn"]17 custom_authorizer_name = event["ResourceProperties"]["authorizer_name"]18 public_key = event["ResourceProperties"]["public_key"]19 token_key_name = event["ResourceProperties"]["token_key_name"]20 create_authorizer(21 custom_authorizer_name, custom_authorizer_function_arn, public_key, token_key_name22 )23 response = {"PhysicalResourceId": physical_id}24 print(f"### on_create_or_update response: {response}")25 return response26def on_delete(event):27 print(f"### on_delete({event})")28 custom_authorizer_name = event["ResourceProperties"]["authorizer_name"]29 delete_authorizer(custom_authorizer_name)30 response = {"PhysicalResourceId": physical_id}31 print(f"### on_delete response: {response}")32 return response33def create_authorizer(name, function_arn, public_key, token_key_name):34 print(f"### create_authorizer({name, function_arn, public_key, token_key_name})")35 client = boto3.client("iot")36 formatted_key = format_public_key(public_key)37 create_authorizer_response = client.create_authorizer(38 authorizerName=name,39 authorizerFunctionArn=function_arn,40 tokenKeyName=token_key_name,41 status="ACTIVE",42 signingDisabled=False,43 tokenSigningPublicKeys={"public_key": formatted_key},44 )45 print(f"### create_authorizer_response: {create_authorizer_response}")46def format_public_key(public_key):47 return f"-----BEGIN PUBLIC KEY-----\n{public_key}\n-----END PUBLIC KEY-----"48def delete_authorizer(name):49 print(f"### delete_authorizer({name})")50 client = boto3.client("iot")51 update_authorizer_response = client.update_authorizer(authorizerName=name, status="INACTIVE")...

Full Screen

Full Screen

authorizer_factory_abc.py

Source:authorizer_factory_abc.py Github

copy

Full Screen

...4from servey.access_control.authorizer_abc import AuthorizerABC5class AuthorizerFactoryABC(ABC):6 priority: int = 1007 @abstractmethod8 def create_authorizer(self) -> Optional[AuthorizerABC]:9 """Create a new authorizer instance. Return None if this was not possible"""10def create_authorizer():11 """12 Use the highest priority factory that can actually do it to create an authorizer.13 For example, the KmsAuthorizerFactory requires that boto3 is available and that a KMS_KEY_ID specified14 as an environment variable, so will yield nothing if either of these constraints are not met.15 The JwtAuthorizationFactory has lower priority, will make up a key on the fly as required, but requires16 that pyjwt is installed.17 """18 factories = list(get_impls(AuthorizerFactoryABC))19 factories.sort(key=lambda f: f.priority, reverse=True)20 for factory in factories:21 authorizer = factory().create_authorizer()22 if authorizer:23 return authorizer24_default_authorizer = None25def get_default_authorizer():26 global _default_authorizer27 if not _default_authorizer:28 _default_authorizer = create_authorizer()...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful