kopia lustrzana https://github.com/bugout-dev/moonstream
Add fixes.
rodzic
2bf3ced7a5
commit
c16d9d6f0e
|
@ -31,6 +31,7 @@ def cli_migrate_subscriptions(args: argparse.Namespace) -> None:
|
|||
drop_keys = []
|
||||
|
||||
if args.file is not None:
|
||||
|
||||
with open(args.file) as migration_json_file:
|
||||
migration_json = json.load(migration_json_file)
|
||||
|
||||
|
@ -276,9 +277,7 @@ This CLI is configured to work with the following API URLs:
|
|||
type=str,
|
||||
help="Command for migration",
|
||||
)
|
||||
parser_subscription_migrate.set_defaults(
|
||||
func=lambda _: parser_subscription.print_help()
|
||||
)
|
||||
parser_subscription_migrate.set_defaults(func=cli_migrate_subscriptions)
|
||||
|
||||
args = parser.parse_args()
|
||||
args.func(args)
|
||||
|
|
|
@ -41,9 +41,11 @@ def migrate_subscriptions(
|
|||
content=descriptions,
|
||||
tags=["subscriptions", "migration", f"migration_file:{file}"],
|
||||
)
|
||||
print(f"Affected resources: {len(old_resources)}")
|
||||
|
||||
try:
|
||||
for resource in old_resources:
|
||||
for resource in old_resources:
|
||||
try:
|
||||
print(f"Updating resource: {resource.id}")
|
||||
|
||||
new_resource = bc.update_resource(
|
||||
token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
|
||||
|
@ -52,16 +54,17 @@ def migrate_subscriptions(
|
|||
timeout=BUGOUT_REQUEST_TIMEOUT_SECONDS,
|
||||
)
|
||||
new_resources.append(new_resource)
|
||||
except Exception as err:
|
||||
reporter.error_report(
|
||||
err,
|
||||
tags=[
|
||||
"subscriptions",
|
||||
"migration",
|
||||
"error",
|
||||
f"resource_id:{resource.id}",
|
||||
f"migration_file:{file}",
|
||||
],
|
||||
)
|
||||
except Exception as err:
|
||||
print(err)
|
||||
reporter.error_report(
|
||||
err,
|
||||
tags=[
|
||||
"subscriptions",
|
||||
"migration",
|
||||
"error",
|
||||
f"resource_id:{resource.id}",
|
||||
f"migration_file:{file}",
|
||||
],
|
||||
)
|
||||
|
||||
return new_resources
|
||||
|
|
|
@ -230,6 +230,7 @@ async def update_subscriptions_handler(
|
|||
subscription_id: str,
|
||||
color: Optional[str] = Form(None),
|
||||
label: Optional[str] = Form(None),
|
||||
abi: Optional[str] = Form(None),
|
||||
) -> data.SubscriptionResourceData:
|
||||
"""
|
||||
Get user's subscriptions.
|
||||
|
@ -244,6 +245,58 @@ async def update_subscriptions_handler(
|
|||
if label:
|
||||
update["label"] = label
|
||||
|
||||
if abi:
|
||||
|
||||
try:
|
||||
validate_abi(json.loads(abi))
|
||||
except json.JSONDecodeError:
|
||||
raise MoonstreamHTTPException(status_code=400, detail="Malformed abi body.")
|
||||
except ValueError as e:
|
||||
raise MoonstreamHTTPException(status_code=400, detail=e)
|
||||
except:
|
||||
raise MoonstreamHTTPException(
|
||||
status_code=400, detail="Error on abi valiadation."
|
||||
)
|
||||
|
||||
try:
|
||||
subscription_resource: BugoutResource = bc.get_resource(
|
||||
token=token,
|
||||
resource_id=subscription_id,
|
||||
)
|
||||
except BugoutResponseException as e:
|
||||
raise MoonstreamHTTPException(status_code=e.status_code, detail=e.detail)
|
||||
except Exception as e:
|
||||
logger.error(f"Error creating subscription resource: {str(e)}")
|
||||
raise MoonstreamHTTPException(status_code=500, internal_error=e)
|
||||
|
||||
if subscription_resource.resource_data["abi"] is not None:
|
||||
raise MoonstreamHTTPException(
|
||||
status_code=400,
|
||||
detail="Subscription already have ABI. For add a new ABI create new subscription.",
|
||||
)
|
||||
|
||||
s3_client = boto3.client("s3")
|
||||
|
||||
bucket = MOONSTREAM_SMARTCONTRACTS_ABI_BUCKET
|
||||
|
||||
result_bytes = abi.encode("utf-8")
|
||||
result_key = f"v1/{subscription_resource.resource_data['address']}/{subscription_resource.id}/abi.json"
|
||||
|
||||
s3_client.put_object(
|
||||
Body=result_bytes,
|
||||
Bucket=bucket,
|
||||
Key=result_key,
|
||||
ContentType="application/json",
|
||||
Metadata={"Moonstream": "Abi data"},
|
||||
)
|
||||
|
||||
update["abi"] = True
|
||||
|
||||
update["bucket"] = MOONSTREAM_SMARTCONTRACTS_ABI_BUCKET
|
||||
update[
|
||||
"s3_path"
|
||||
] = f"v1/{subscription_resource.resource_data['address']}/{subscription_resource.id}/abi.json"
|
||||
|
||||
try:
|
||||
resource: BugoutResource = bc.update_resource(
|
||||
token=token,
|
||||
|
|
Ładowanie…
Reference in New Issue