Fix gpg key usage when uploading config to multiple deployers
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Lint Checks / Run linter (pull_request) Successful in 40s
				
			
		
			
				
	
				Webapp Test / Run webapp test suite (pull_request) Successful in 5m17s
				
			
		
			
				
	
				Deploy Test / Run deploy test suite (pull_request) Successful in 6m10s
				
			
		
			
				
	
				K8s Deployment Control Test / Run deployment control suite on kind/k8s (pull_request) Successful in 8m35s
				
			
		
			
				
	
				K8s Deploy Test / Run deploy test suite on kind/k8s (pull_request) Successful in 9m47s
				
			
		
			
				
	
				Smoke Test / Run basic test suite (pull_request) Successful in 4m14s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Lint Checks / Run linter (pull_request) Successful in 40s
				
			Webapp Test / Run webapp test suite (pull_request) Successful in 5m17s
				
			Deploy Test / Run deploy test suite (pull_request) Successful in 6m10s
				
			K8s Deployment Control Test / Run deployment control suite on kind/k8s (pull_request) Successful in 8m35s
				
			K8s Deploy Test / Run deploy test suite on kind/k8s (pull_request) Successful in 9m47s
				
			Smoke Test / Run basic test suite (pull_request) Successful in 4m14s
				
			This commit is contained in:
		
							parent
							
								
									2bf1ed5653
								
							
						
					
					
						commit
						9810b46f7f
					
				| @ -97,69 +97,70 @@ def command(  # noqa: C901 | ||||
|     if env_file and config_ref: | ||||
|         fatal("Cannot use --env-file and --config-ref at the same time.") | ||||
| 
 | ||||
|     tempdir = tempfile.mkdtemp() | ||||
|     try: | ||||
|         laconic = LaconicRegistryClient(laconic_config) | ||||
|     laconic = LaconicRegistryClient(laconic_config) | ||||
| 
 | ||||
|         app_record = laconic.get_record(app) | ||||
|         if not app_record: | ||||
|             fatal(f"Unable to locate app: {app}") | ||||
|     app_record = laconic.get_record(app) | ||||
|     if not app_record: | ||||
|         fatal(f"Unable to locate app: {app}") | ||||
| 
 | ||||
|         # Deployers to send requests to | ||||
|         deployer_records = [] | ||||
|     # Deployers to send requests to | ||||
|     deployer_records = [] | ||||
| 
 | ||||
|         auction = None | ||||
|         auction_winners = None | ||||
|         if auction_id: | ||||
|             # Fetch auction details | ||||
|             auction = laconic.get_auction(auction_id) | ||||
|             if not auction: | ||||
|                 fatal(f"Unable to locate auction: {auction_id}") | ||||
|     auction = None | ||||
|     auction_winners = None | ||||
|     if auction_id: | ||||
|         # Fetch auction details | ||||
|         auction = laconic.get_auction(auction_id) | ||||
|         if not auction: | ||||
|             fatal(f"Unable to locate auction: {auction_id}") | ||||
| 
 | ||||
|             # Check auction owner | ||||
|             if auction.ownerAddress != laconic.whoami().address: | ||||
|                 fatal(f"Auction {auction_id} owner mismatch") | ||||
|         # Check auction owner | ||||
|         if auction.ownerAddress != laconic.whoami().address: | ||||
|             fatal(f"Auction {auction_id} owner mismatch") | ||||
| 
 | ||||
|             # Check auction kind | ||||
|             if auction.kind != AUCTION_KIND_PROVIDER: | ||||
|                 fatal(f"Auction kind needs to be ${AUCTION_KIND_PROVIDER}, got {auction.kind}") | ||||
|         # Check auction kind | ||||
|         if auction.kind != AUCTION_KIND_PROVIDER: | ||||
|             fatal(f"Auction kind needs to be ${AUCTION_KIND_PROVIDER}, got {auction.kind}") | ||||
| 
 | ||||
|             # Check auction status | ||||
|             if auction.status != AuctionStatus.COMPLETED: | ||||
|                 fatal(f"Auction {auction_id} not completed yet, status {auction.status}") | ||||
|         # Check auction status | ||||
|         if auction.status != AuctionStatus.COMPLETED: | ||||
|             fatal(f"Auction {auction_id} not completed yet, status {auction.status}") | ||||
| 
 | ||||
|             # Check that winner list is not empty | ||||
|             if len(auction.winnerAddresses) == 0: | ||||
|                 fatal(f"Auction {auction_id} has no winners") | ||||
|         # Check that winner list is not empty | ||||
|         if len(auction.winnerAddresses) == 0: | ||||
|             fatal(f"Auction {auction_id} has no winners") | ||||
| 
 | ||||
|             auction_winners = auction.winnerAddresses | ||||
|         auction_winners = auction.winnerAddresses | ||||
| 
 | ||||
|             # Get deployer record for all the auction winners | ||||
|             for auction_winner in auction_winners: | ||||
|                 # TODO: Match auction winner address with provider address? | ||||
|                 deployer_records_by_owner = laconic.webapp_deployers({"paymentAddress": auction_winner}) | ||||
|                 if len(deployer_records_by_owner) == 0: | ||||
|                     print(f"WARNING: Unable to locate deployer for auction winner {auction_winner}") | ||||
|         # Get deployer record for all the auction winners | ||||
|         for auction_winner in auction_winners: | ||||
|             # TODO: Match auction winner address with provider address? | ||||
|             deployer_records_by_owner = laconic.webapp_deployers({"paymentAddress": auction_winner}) | ||||
|             if len(deployer_records_by_owner) == 0: | ||||
|                 print(f"WARNING: Unable to locate deployer for auction winner {auction_winner}") | ||||
| 
 | ||||
|                 # Take first record with name set | ||||
|                 target_deployer_record = deployer_records_by_owner[0] | ||||
|                 for r in deployer_records_by_owner: | ||||
|                     if len(r.names) > 0: | ||||
|                         target_deployer_record = r | ||||
|                         break | ||||
|                 deployer_records.append(target_deployer_record) | ||||
|         else: | ||||
|             deployer_record = laconic.get_record(deployer) | ||||
|             if not deployer_record: | ||||
|                 fatal(f"Unable to locate deployer: {deployer}") | ||||
|             # Take first record with name set | ||||
|             target_deployer_record = deployer_records_by_owner[0] | ||||
|             for r in deployer_records_by_owner: | ||||
|                 if len(r.names) > 0: | ||||
|                     target_deployer_record = r | ||||
|                     break | ||||
|             print("target_deployer_record", target_deployer_record) | ||||
|             deployer_records.append(target_deployer_record) | ||||
|     else: | ||||
|         deployer_record = laconic.get_record(deployer) | ||||
|         if not deployer_record: | ||||
|             fatal(f"Unable to locate deployer: {deployer}") | ||||
| 
 | ||||
|             deployer_records.append(deployer_record) | ||||
|         deployer_records.append(deployer_record) | ||||
| 
 | ||||
|         # Create and send request to each deployer | ||||
|         deployment_requests = [] | ||||
|         for deployer_record in deployer_records: | ||||
|             # If env_file | ||||
|             if env_file: | ||||
|     # Create and send request to each deployer | ||||
|     deployment_requests = [] | ||||
|     for deployer_record in deployer_records: | ||||
|         # Upload config to deployers if env_file is passed | ||||
|         if env_file: | ||||
|             tempdir = tempfile.mkdtemp() | ||||
|             try: | ||||
|                 gpg = gnupg.GPG(gnupghome=tempdir) | ||||
| 
 | ||||
|                 # Import the deployer's public key | ||||
| @ -194,59 +195,59 @@ def command(  # noqa: C901 | ||||
|                     response.raise_for_status() | ||||
| 
 | ||||
|                 config_ref = response.json()["id"] | ||||
|             finally: | ||||
|                 shutil.rmtree(tempdir, ignore_errors=True) | ||||
| 
 | ||||
|             target_deployer = deployer | ||||
|             if (not deployer) and len(deployer_record.names): | ||||
|                 target_deployer = deployer_record.names[0] | ||||
|         target_deployer = deployer | ||||
|         if (not deployer) and len(deployer_record.names): | ||||
|             target_deployer = deployer_record.names[0] | ||||
| 
 | ||||
|             deployment_request = { | ||||
|                 "record": { | ||||
|                     "type": "ApplicationDeploymentRequest", | ||||
|                     "application": app, | ||||
|                     "version": "1.0.0", | ||||
|                     "name": f"{app_record.attributes.name}@{app_record.attributes.version}", | ||||
|                     "deployer": target_deployer, | ||||
|                     "meta": {"when": str(datetime.utcnow())}, | ||||
|                 } | ||||
|         deployment_request = { | ||||
|             "record": { | ||||
|                 "type": "ApplicationDeploymentRequest", | ||||
|                 "application": app, | ||||
|                 "version": "1.0.0", | ||||
|                 "name": f"{app_record.attributes.name}@{app_record.attributes.version}", | ||||
|                 "deployer": target_deployer, | ||||
|                 "meta": {"when": str(datetime.utcnow())}, | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|             if auction_id: | ||||
|                 deployment_request["record"]["auction"] = auction_id | ||||
|         if auction_id: | ||||
|             deployment_request["record"]["auction"] = auction_id | ||||
| 
 | ||||
|             if config_ref: | ||||
|                 deployment_request["record"]["config"] = {"ref": config_ref} | ||||
|         if config_ref: | ||||
|             deployment_request["record"]["config"] = {"ref": config_ref} | ||||
| 
 | ||||
|             if dns: | ||||
|                 deployment_request["record"]["dns"] = dns.lower() | ||||
|         if dns: | ||||
|             deployment_request["record"]["dns"] = dns.lower() | ||||
| 
 | ||||
|             if make_payment: | ||||
|                 amount = 0 | ||||
|                 if dry_run: | ||||
|                     deployment_request["record"]["payment"] = "DRY_RUN" | ||||
|                 elif "auto" == make_payment: | ||||
|                     if "minimumPayment" in deployer_record.attributes: | ||||
|                         amount = int( | ||||
|                             deployer_record.attributes.minimumPayment.replace("alnt", "") | ||||
|                         ) | ||||
|                 else: | ||||
|                     amount = make_payment | ||||
|                 if amount: | ||||
|                     receipt = laconic.send_tokens( | ||||
|                         deployer_record.attributes.paymentAddress, amount | ||||
|                     ) | ||||
|                     deployment_request["record"]["payment"] = receipt.tx.hash | ||||
|                     print("Payment TX:", receipt.tx.hash) | ||||
|             elif use_payment: | ||||
|                 deployment_request["record"]["payment"] = use_payment | ||||
| 
 | ||||
|             deployment_requests.append(deployment_request) | ||||
| 
 | ||||
|         # Send all requests | ||||
|         for deployment_request in deployment_requests: | ||||
|         if make_payment: | ||||
|             amount = 0 | ||||
|             if dry_run: | ||||
|                 print(yaml.dump(deployment_request)) | ||||
|                 continue | ||||
|                 deployment_request["record"]["payment"] = "DRY_RUN" | ||||
|             elif "auto" == make_payment: | ||||
|                 if "minimumPayment" in deployer_record.attributes: | ||||
|                     amount = int( | ||||
|                         deployer_record.attributes.minimumPayment.replace("alnt", "") | ||||
|                     ) | ||||
|             else: | ||||
|                 amount = make_payment | ||||
|             if amount: | ||||
|                 receipt = laconic.send_tokens( | ||||
|                     deployer_record.attributes.paymentAddress, amount | ||||
|                 ) | ||||
|                 deployment_request["record"]["payment"] = receipt.tx.hash | ||||
|                 print("Payment TX:", receipt.tx.hash) | ||||
|         elif use_payment: | ||||
|             deployment_request["record"]["payment"] = use_payment | ||||
| 
 | ||||
|             laconic.publish(deployment_request) | ||||
|     finally: | ||||
|         shutil.rmtree(tempdir, ignore_errors=True) | ||||
|         deployment_requests.append(deployment_request) | ||||
| 
 | ||||
|     # Send all requests | ||||
|     for deployment_request in deployment_requests: | ||||
|         if dry_run: | ||||
|             print(yaml.dump(deployment_request)) | ||||
|             continue | ||||
| 
 | ||||
|         laconic.publish(deployment_request) | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user