def create_bucket(**kwargs): try: if utils.compatibility(): response = bucket_lib.neo_create_bucket(**kwargs) utils.check_plain(response) else: response = bucket_lib.create_bucket(**kwargs) click.secho( f'Bucket "{kwargs.get("bucket_name")}" created successfully', fg="green" ) except Exception as exc: click.secho( f"Bucket creation failed. \n{exc}", fg="yellow", bold=True, err=True )
def create_bucket(**kwargs): try: name = utils.sanitize("bucket", kwargs.pop("bucket_name")) if not 2 < len(name) < 64: raise ValueError(f"'{name}' too short or too long for bucket name") if utils.compatibility(): response = bucket_lib.neo_create_bucket(**kwargs, bucket_name=name) utils.check_plain(response) else: response = bucket_lib.create_bucket(**kwargs, bucket_name=name) click.secho(f'Bucket "{name}" created successfully', fg="green") except Exception as exc: click.secho(f"Bucket creation failed. \n{exc}", fg="yellow", bold=True, err=True)
def post(self, bucket_name): parser = reqparse.RequestParser() parser.add_argument("access_key", type=str, required=True) parser.add_argument("secret_key", type=str, required=True) parser.add_argument("acl", type=str, default="private") parser.add_argument("policy_id", type=str, default="") parser.add_argument("random_name", type=inputs.boolean, default=False) args = parser.parse_args() secret_key = args["secret_key"].replace(" ", "+") try: bucket_name = utils.sanitize("bucket", bucket_name) if not 2 < len(bucket_name) < 64: return response( 400, f"'{bucket_name}' too short or too long for bucket name") attr = { "auth": get_plain_auth(args["access_key"], secret_key), "resource": get_resources(args["access_key"], secret_key), "bucket_name": bucket_name, "acl": args["acl"], "policy_id": args["policy_id"], "random_name": args["random_name"], } if utils.compatibility(): responses = bucket.neo_create_bucket(**attr) if responses.text: error = xmltodict.parse(responses.text) return response(400, error["Error"]["Message"]) return response(201, f"Bucket created successfully.", responses.text) else: responses = bucket.create_bucket(**attr) return response(201, f"Bucket created successfully.", responses) except Exception as e: current_app.logger.error(f"{e}") return response(500, f"{e}")