How to use iam method in localstack

Best Python code snippet using localstack_python

test_iam.py

Source:test_iam.py Github

copy

Full Screen

...611 json.loads(self.object_iam_string), IAM_OBJECT_READ_ROLE,612 self.public_object_read_binding)613 self.new_object_iam_path = self.CreateTempFile(614 contents=json.dumps(self.new_object_iam_policy))615 def test_seek_ahead_iam(self):616 """Ensures that the seek-ahead iterator is being used with iam commands."""617 gsutil_object = self.CreateObject(618 bucket_uri=self.bucket, contents='foobar')619 # This forces the seek-ahead iterator to be utilized.620 with SetBotoConfigForTest([('GSUtil', 'task_estimation_threshold', '1'),621 ('GSUtil', 'task_estimation_force', 'True')]):622 stderr = self.RunGsUtil(623 ['-m', 'iam', 'set', self.new_object_iam_path, gsutil_object.uri],624 return_stderr=True)625 self.assertIn('Estimated work for this command: objects: 1\n', stderr)626 def test_set_invalid_iam_bucket(self):627 """Ensures invalid content returns error on input check."""628 inpath = self.CreateTempFile(contents='badIam')629 stderr = self.RunGsUtil(['iam', 'set', inpath, self.bucket.uri],...

Full Screen

Full Screen

writerid_estimator_training.py

Source:writerid_estimator_training.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3Writer identification based of shape context codebook features and 4a shared kernel GP classifier. This file covers the training and evaluation5of the estimators.6@author: Fredrik Wahlberg <fredrik.wahlberg@it.uu.se>7"""8from __future__ import print_function, division9import numpy as np10import os.path11from model import SharedKernelClassifier12import time13cache_path = os.path.expanduser("~/tmp/gp_multiclass")14def cache_filename_features(N, p, q):15 return os.path.join(cache_path, 16 "features_N%i_p%i_q%i.npz" % (N, p, q))17def cache_filename_estimator(N, p, q):18 return os.path.join(cache_path, 19 "estimator_N%i_p%i_q%i.npz" % (N, p, q))20def cache_filename_result_npz(N, p, q):21 return os.path.join(cache_path, 22 "result_N%i_p%i_q%i.npz" % (N, p, q))23def cache_filename_result_csv(N, p, q):24 return os.path.join(cache_path, 25 "result_N%i_p%i_q%i.csv" % (N, p, q))26parameter_distribution = {27 'p': list(range(2, 6+1)),28 'q': list(range(4, 9+1)),29 'N': list(range(7, 21+1, 2))}30from sklearn.model_selection import ParameterGrid31valid_parameters = [p for p in ParameterGrid(parameter_distribution) if p['N']>p['p']*2]32print("%i parameter configurations" % len(valid_parameters))33feature_files = [cache_filename_features(N=pa['N'], p=pa['p'], q=pa['q']) 34 for pa in valid_parameters 35 if os.path.exists(cache_filename_features(N=pa['N'], p=pa['p'], q=pa['q']))]36import random37random.shuffle(valid_parameters)38#%%39csv_categories = ['Dataset', 'Training authors', 'Training documents', 40 'Testing authors', 'Testing documents', 'Kernel', 'ARD', 41 'Codebook size', 'N', 'p', 'q', 'Hard 5-top', 'Hard 3-top', 42 '1-top', 'Soft 3-top', 'Soft 5-top', 'Likelihood']43with open(os.path.join(cache_path, "00categories.csv"), 'w') as f:44 for i, cat in enumerate(csv_categories):45 f.write('"' + cat + '"')46 if i==len(csv_categories)-1:47 f.write("\n")48 else:49 f.write(";")50for feature_file in feature_files:51 # Read feature data file52 cache_file_data = np.load(feature_file)53 print(cache_file_data.keys())54 data = dict()55 for k in cache_file_data.keys():56 if k in ['cluster_centers', 'codebooks', 'N', 'p', 'q', 'rotationalinvariant', 'authors']:57 data[k] = cache_file_data[k].tolist()58 else:59 data[k] = cache_file_data[k]60 feature_keys = [k for k in data.keys() if k[:8]=='features']61 # Set up output and check for old results62 cvs_filename = cache_filename_result_csv(N=data['N'], p=data['p'], q=data['q'])63 if not os.path.exists(cvs_filename):64 csv_file = open(cvs_filename, 'w')65 # CVL authors are id>100066 authors = data['authors']67 cvl_mask = [a>1000 for a in authors]68 cvl_train_mask = [a>1000 and a<=1050 for a in authors]69 cvl_test_mask = [a>1000 and a>1050 for a in authors]70 cvl_y_train = np.vstack([a for a,b in zip(authors, cvl_train_mask) if b])71 assert np.sum(cvl_train_mask)==len(cvl_y_train)72 cvl_y_test = np.vstack([a for a,b in zip(authors, cvl_test_mask) if b])73 assert np.sum(cvl_test_mask)==len(cvl_y_test)74 75 iam_mask = [a<1000 for a in authors]76 iam_train_mask = [a<1000 and a<=26 for a in authors]77 iam_test_mask = [a<1000 and a>26 for a in authors]78 iam_y_train = np.vstack([a for a,b in zip(authors, iam_train_mask) if b])79 assert np.sum(iam_train_mask)==len(iam_y_train)80 iam_y_test = np.vstack([a for a,b in zip(authors, iam_test_mask) if b])81 assert np.sum(iam_test_mask)==len(iam_y_test)82 cvl_iam_train_mask = [a or b for a, b in zip(cvl_train_mask, iam_train_mask)]83 cvl_iam_test_mask = [a or b for a, b in zip(cvl_test_mask, iam_test_mask)]84 assert np.sum(cvl_iam_train_mask) == np.sum(cvl_train_mask) + np.sum(iam_train_mask)85 assert np.sum(cvl_iam_test_mask) == np.sum(cvl_test_mask) + np.sum(iam_test_mask)86 cvl_iam_y_train = np.vstack([a for a,b in zip(authors, cvl_iam_train_mask) if b])87 assert np.sum(cvl_iam_train_mask)==len(cvl_iam_y_train)88 cvl_iam_y_test = np.vstack([a for a,b in zip(authors, cvl_iam_test_mask) if b])89 assert np.sum(cvl_iam_test_mask)==len(cvl_iam_y_test)90 91 # Model standard parameters92# kernel='rbf'93 ard=False94 n_iter = 1595 n_restarts = 096 97# for feature_key in feature_keys[:1]:98 for feature_key in feature_keys:99 100 # Separate feature data sets101 cvl_X_train = data[feature_key][cvl_train_mask, :]102 cvl_X_test = data[feature_key][cvl_test_mask, :]103 assert cvl_X_train.shape[0] == np.sum(cvl_train_mask)104 assert cvl_X_test.shape[0] == np.sum(cvl_test_mask)105 iam_X_train = data[feature_key][iam_train_mask, :]106 iam_X_test = data[feature_key][iam_test_mask, :]107 assert iam_X_train.shape[0] == np.sum(iam_train_mask)108 assert iam_X_test.shape[0] == np.sum(iam_test_mask)109 cvl_iam_X_train = data[feature_key][cvl_iam_train_mask, :]110 cvl_iam_X_test = data[feature_key][cvl_iam_test_mask, :]111 assert cvl_iam_X_train.shape[0] == np.sum(cvl_iam_train_mask)112 assert cvl_iam_X_test.shape[0] == np.sum(cvl_iam_test_mask)113 #%% CVL Estimator114 for kernel in ['matern52', 'rbf']:115# for ard in [True, False]:116 print("Kernel %s " % kernel, end="")117 if ard:118 print("with ard")119 else:120 print("without ard")121 cvl_estimator = SharedKernelClassifier(kernel=kernel, ard=ard, n_iter=n_iter, 122 n_restarts=n_restarts, verbose=True)123 print("Training CVL estimator...", end="")124 t0 = time.time()125 cvl_estimator.fit(cvl_X_train, cvl_y_train)126 print("done (%.1fs)" % (time.time()-t0))127 128 print("CVL 1-top training set: %.1f%%" % (cvl_estimator.score_covar_ntop(cvl_X_train, cvl_y_train)[4]*100))129 ntop = cvl_estimator.score_covar_ntop(cvl_X_test, cvl_y_test)130 print("CVL 1-top test set: %.1f%%" % (ntop[4]*100))131 print("Likelihood %.2f" % cvl_estimator.log_likelihood_)132 ntop2 = cvl_estimator.score_covar_ntop(iam_X_test, iam_y_test)133 print("CVL on IAM 1-top test set: %.1f%%" % (ntop2[4]*100))134 135 dataset = 'CVL'136 d = (dataset, len(np.unique(cvl_y_train)), len(cvl_y_train), 137 len(np.unique(cvl_y_test)), len(cvl_y_test), kernel, ard, 138 cvl_X_train.shape[1], data['N'], data['p'], data['q'], ntop[0]*100, 139 ntop[2]*100, ntop[4]*100, ntop[6]*100, ntop[8]*100, cvl_estimator.log_likelihood_)140 csv_file.write("\"%s\";%i;%i;%i;%i;\"%s\";\"%s\";%i;%i;%i;%i;%f;%f;%f;%f;%f;%f\n" % d)141 142 dataset = 'CVL on IAM'143 d = (dataset, len(np.unique(cvl_y_train)), len(cvl_y_train), 144 len(np.unique(iam_y_test)), len(iam_y_test), kernel, ard, 145 cvl_X_train.shape[1], data['N'], data['p'], data['q'], ntop2[0]*100, 146 ntop2[2]*100, ntop2[4]*100, ntop2[6]*100, ntop2[8]*100, cvl_estimator.log_likelihood_)147 csv_file.write("\"%s\";%i;%i;%i;%i;\"%s\";\"%s\";%i;%i;%i;%i;%f;%f;%f;%f;%f;%f\n" % d)148 #%% IAM Estimator149 iam_estimator = SharedKernelClassifier(kernel=kernel, ard=ard, n_iter=n_iter, 150 n_restarts=n_restarts, verbose=True)151 print("Training IAM estimator...", end="")152 t0 = time.time()153 iam_estimator.fit(iam_X_train, iam_y_train)154 print("done (%.1fs)" % (time.time()-t0))155 156 print("IAM 1-top training set: %.1f%%" % (iam_estimator.score_covar_ntop(iam_X_train, iam_y_train)[4]*100))157 ntop = iam_estimator.score_covar_ntop(iam_X_test, iam_y_test)158 print("IAM 1-top test set: %.1f%%" % (ntop[4]*100))159 print("Likelihood %.2f" % iam_estimator.log_likelihood_)160 ntop2 = iam_estimator.score_covar_ntop(cvl_X_test, cvl_y_test)161 print("IAM on CVL 1-top test set: %.1f%%" % (ntop2[4]*100))162 163 dataset = 'IAM'164 d = (dataset, len(np.unique(iam_y_train)), len(iam_y_train), 165 len(np.unique(iam_y_test)), len(iam_y_test), kernel, ard, 166 iam_X_train.shape[1], data['N'], data['p'], data['q'], ntop[0]*100, 167 ntop[2]*100, ntop[4]*100, ntop[6]*100, ntop[8]*100, iam_estimator.log_likelihood_)168 csv_file.write("\"%s\";%i;%i;%i;%i;\"%s\";\"%s\";%i;%i;%i;%i;%f;%f;%f;%f;%f;%f\n" % d)169 dataset = 'IAM on CVL'170 d = (dataset, len(np.unique(iam_y_train)), len(iam_y_train), 171 len(np.unique(cvl_y_test)), len(cvl_y_test), kernel, ard, 172 iam_X_train.shape[1], data['N'], data['p'], data['q'], ntop2[0]*100, 173 ntop2[2]*100, ntop2[4]*100, ntop2[6]*100, ntop2[8]*100, iam_estimator.log_likelihood_)174 csv_file.write("\"%s\";%i;%i;%i;%i;\"%s\";\"%s\";%i;%i;%i;%i;%f;%f;%f;%f;%f;%f\n" % d)175 # b = estimator.score_unseen_proba_metric(cvl_X_test, cvl_y_test)176 #%% CVL+IAM Estimator177 cvl_iam_estimator = SharedKernelClassifier(kernel=kernel, ard=ard, n_iter=n_iter, 178 n_restarts=n_restarts, verbose=True)179 print("Training CVL+IAM estimator...", end="")180 t0 = time.time()181 cvl_iam_estimator.fit(cvl_iam_X_train, cvl_iam_y_train)182 print("done (%.1fs)" % (time.time()-t0))183 184 print("CVL+IAM 1-top training set: %.1f%%" % (cvl_iam_estimator.score_covar_ntop(cvl_iam_X_train, cvl_iam_y_train)[4]*100))185 ntop = cvl_iam_estimator.score_covar_ntop(cvl_iam_X_test, cvl_iam_y_test)186 ntop2 = cvl_iam_estimator.score_covar_ntop(cvl_X_test, cvl_y_test)187 ntop3 = cvl_iam_estimator.score_covar_ntop(iam_X_test, iam_y_test)188 print("CVL+IAM 1-top test set: %.1f%%" % (ntop[4]*100))189 print("CVL+IAM on CVL 1-top test set: %.1f%%" % (ntop2[4]*100))190 print("CVL+IAM on IAM 1-top test set: %.1f%%" % (ntop3[4]*100))191 print("Likelihood %.2f" % cvl_iam_estimator.log_likelihood_)192 dataset = 'CVL+IAM'193 d = (dataset, len(np.unique(cvl_iam_y_train)), len(cvl_iam_y_train), 194 len(np.unique(cvl_iam_y_test)), len(cvl_iam_y_test), kernel, ard, 195 cvl_iam_X_train.shape[1], data['N'], data['p'], data['q'], ntop[0]*100, 196 ntop[2]*100, ntop[4]*100, ntop[6]*100, ntop[8]*100, cvl_iam_estimator.log_likelihood_)197 csv_file.write(("\"%s\";%i;%i;%i;%i;\"%s\";\"%s\";%i;%i;%i;%i;%f;%f;%f;%f;%f;%f\n" % d).replace('.', ','))198 dataset = 'CVL+IAM on CVL'199 d = (dataset, len(np.unique(cvl_iam_y_train)), len(cvl_iam_y_train), 200 len(np.unique(cvl_y_test)), len(cvl_y_test), kernel, ard, 201 cvl_iam_X_train.shape[1], data['N'], data['p'], data['q'], ntop2[0]*100, 202 ntop2[2]*100, ntop2[4]*100, ntop2[6]*100, ntop2[8]*100, cvl_iam_estimator.log_likelihood_)203 csv_file.write(("\"%s\";%i;%i;%i;%i;\"%s\";\"%s\";%i;%i;%i;%i;%f;%f;%f;%f;%f;%f\n" % d).replace('.', ','))204 dataset = 'CVL+IAM on IAM'205 d = (dataset, len(np.unique(cvl_iam_y_train)), len(cvl_iam_y_train), 206 len(np.unique(iam_y_test)), len(iam_y_test), kernel, ard, 207 cvl_iam_X_train.shape[1], data['N'], data['p'], data['q'], ntop3[0]*100, 208 ntop3[2]*100, ntop3[4]*100, ntop3[6]*100, ntop3[8]*100, cvl_iam_estimator.log_likelihood_)209 csv_file.write(("\"%s\";%i;%i;%i;%i;\"%s\";\"%s\";%i;%i;%i;%i;%f;%f;%f;%f;%f;%f\n" % d).replace('.', ','))210# csv_file.write("\"%s\";%i;%i;%i;%i;\"%s\";\"%s\";%i;%i;%i;%i;%f;%f;%f;%f;%f;%f\n" % d)211 if feature_key==feature_keys[-1]:212 np.savez_compressed(cache_filename_result_npz(N=data['N'], p=data['p'], q=data['q']), 213 covariance_matrix = np.asarray(cvl_iam_estimator.get_kernel()(cvl_iam_X_test), dtype=np.float16),214 labels = cvl_iam_y_test.ravel(),215 likelihood = cvl_iam_estimator.log_likelihood_)216 217 csv_file.close()218 else:...

Full Screen

Full Screen

iam-groups-cf-template.py

Source:iam-groups-cf-template.py Github

copy

Full Screen

1"""Generating CloudFormation template."""2from troposphere import (3 Template,4 Join,5 Ref,6)7from troposphere.iam import (8 Group,9 ManagedPolicy,10)11from awacs.aws import (12 Action,13 Allow,14 Condition,15 NumericGreaterThan,16 Deny,17 Null,18 Policy,19 Statement,20)21t = Template()22t.add_description("Effective DevOps in AWS: User Groups")23t.add_resource(Group(24 "Admins",25 GroupName="Admins",26 ManagedPolicyArns=[27 "arn:aws:iam::aws:policy/AdministratorAccess"28 ],29))30t.add_resource(ManagedPolicy(31 "CommonIamPolicy",32 Description="Common policy to manage IAM resources",33 PolicyDocument=Policy(34 Version="2012-10-17",35 Statement=[36 Statement(37 Effect=Allow,38 Action=[39 Action("iam", "GetAccountPasswordPolicy"),40 Action("iam", "ListUsers"),41 Action("iam", "ListMFADevices"),42 Action("iam", "ListVirtualMFADEvices")43 ],44 Resource=["*"]45 ),46 Statement(47 Effect=Allow,48 Action=[49 Action("iam", "CreateVirtualMFADevice")50 ],51 Resource=[52 Join(53 "",54 [55 "arn:aws:iam::",56 Ref("AWS::AccountId"),57 ":mfa/${aws:username}",58 ]59 )60 ]61 ),62 Statement(63 Effect=Allow,64 Action=[65 Action("iam", "ChangePassword"),66 Action("iam", "CreateAccessKey"),67 Action("iam", "CreateLoginProfile"),68 Action("iam", "DeleteAccessKey"),69 Action("iam", "DeleteLoginProfile"),70 Action("iam", "EnableMFADevice"),71 Action("iam", "GetAccessKeyLastUsed"),72 Action("iam", "GetLoginProfile"),73 Action("iam", "GetUser"),74 Action("iam", "ListAccessKeys"),75 Action("iam", "UpdateAccessKey"),76 Action("iam", "UpdateLoginProfile")77 ],78 Resource=[79 Join(80 "",81 [82 "arn:aws:iam::",83 Ref("AWS::AccountId"),84 ":user/${aws:username}",85 ]86 )87 ]88 ),89 Statement(90 Effect=Deny,91 NotAction=[92 Action("iam", "ChangePassword"),93 Action("iam", "CreateVirtualMFADevice"),94 Action("iam", "EnableMFADevice"),95 Action("iam", "GetUser"),96 Action("iam", "ListMFADevices"),97 Action("iam", "ListUsers"),98 Action("iam", "ListVirtualMFADEvices")99 ],100 Resource=["*"],101 Condition=Condition(102 Null("aws:MultiFactorAuthAge", "true"),103 ),104 ),105 Statement(106 Effect=Deny,107 NotAction=[108 Action("iam", "ChangePassword"),109 Action("iam", "CreateVirtualMFADevice"),110 Action("iam", "EnableMFADevice"),111 Action("iam", "GetUser"),112 Action("iam", "ListMFADevices"),113 Action("iam", "ListUsers"),114 Action("iam", "ListVirtualMFADEvices")115 ],116 Resource=["*"],117 Condition=Condition(118 NumericGreaterThan("aws:MultiFactorAuthAge", "43200")119 ),120 ),121 ]122 )123))124t.add_resource(Group(125 "AllUsers",126 GroupName="AllUsers",127 ManagedPolicyArns=[128 Ref("CommonIamPolicy")129 ]130))...

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