<commit_before>import boto3
import json
import os
from utils.utils import randuuid
from flask import jsonify, request
from dynamorm import DynaModel
from dynamorm.indexes import GlobalIndex, ProjectKeys, ProjectAll
from dynamorm.exceptions import ValidationError
from flask_restplus import Namespace, Resource
from datetime import datetime, timezone
from schematics.models import Model
from schematics.types import StringType as String, IntType as Number
from schematics.types import DateTimeType, ModelType, BooleanType, BaseType, DictType, ListType, PolyModelType

api=Namespace('asset_group',
                description='create, list, update, delete asset',
                path='/api/v1/asset-group')

class AssetGroup(DynaModel):
    class Table:
        name = '{env}-AssetGroups'.format(env=os.environ.get('ENVIRONMENT', 'dev'))
        hash_key = 'id'

        resource_kwargs = {
            'region_name': os.environ.get('REGION', 'us-west-2')
        }
        read=5
        write=5

    class Schema:
        id = String(default=randuuid)
        service_id = String()
        timestamp_utc = String(default=datetime.now(timezone.utc).isoformat())
        name = String(required=True)
        description = String()

#create table if needed
inittable = AssetGroup(name='init')
if not inittable.Table.exists:
    inittable.Table.create_table(wait=True)

@api.route("/status")
class status(Resource):
    @api.doc('a klingon test/status endpoint')
    def get(self):
        body = {
            "message": "Qapla'!"
        }
        return jsonify(body)

# asset group creation is handled through the interlink.rules file uploaded to the s3 bucket
# so no endpoint for creation/deletion
@api.route("s/<name>")
@api.route("s/",defaults={'name':None})
class search(Resource):
    @api.doc("/<name> partial or full asset group id to return all matches for this word/term")
    def get(self, name):
        try:
            asset_groups=[]

            if name is not None:
                for asset_group in AssetGroup.scan(name__contains=name):
                    asset_groups.append(asset_group.to_dict())
            else:
                for asset_group in AssetGroup.scan(name__exists=True):
                    asset_groups.append(asset_group.to_dict())

            return json.dumps(asset_group),200
        except Exception as e:
            message = {"exception": "{}".format(e)}
            return json.dumps(message),500

@api.route("/<uuid>")
class remove(Resource):
    @api.doc("get /asset/uuid to retrieve a single asset group")
    def get(self,uuid):
        try:
            asset_groups=[]
            if uuid is not None:
                for asset_group in AssetGroup.scan(id__eq=uuid):
                    asset_groups.append(asset_group.to_dict())
            return json.dumps(asset_groups),200
        except Exception as e:
            message = {"exception": "{}".format(e)}
            return json.dumps(message),500<commit_msg>naming updates<commit_after>import boto3
import json
import os
from utils.utils import randuuid
from flask import jsonify, request
from dynamorm import DynaModel
from dynamorm.indexes import GlobalIndex, ProjectKeys, ProjectAll
from dynamorm.exceptions import ValidationError
from flask_restplus import Namespace, Resource
from datetime import datetime, timezone
from schematics.models import Model
from schematics.types import StringType as String, IntType as Number
from schematics.types import DateTimeType, ModelType, BooleanType, BaseType, DictType, ListType, PolyModelType

api=Namespace('asset_group',
                description='list asset groups (created through interllink.rules)',
                path='/api/v1/asset-group')

class AssetGroup(DynaModel):
    class Table:
        name = '{env}-AssetGroups'.format(env=os.environ.get('ENVIRONMENT', 'dev'))
        hash_key = 'id'

        resource_kwargs = {
            'region_name': os.environ.get('REGION', 'us-west-2')
        }
        read=5
        write=5

    class Schema:
        id = String(default=randuuid)
        service_id = String()
        timestamp_utc = String(default=datetime.now(timezone.utc).isoformat())
        name = String(required=True)
        description = String()

#create table if needed
inittable = AssetGroup(name='init')
if not inittable.Table.exists:
    inittable.Table.create_table(wait=True)

@api.route("/status")
class status(Resource):
    @api.doc('a klingon test/status endpoint')
    def get(self):
        body = {
            "message": "Qapla'!"
        }
        return jsonify(body)

# asset group creation is handled through the interlink.rules file uploaded to the s3 bucket
# so no endpoint for creation/deletion
@api.route("s/<name>")
@api.route("s/",defaults={'name':None})
class search(Resource):
    @api.doc("/<name> partial or full asset group id to return all matches for this word/term")
    def get(self, name):
        try:
            asset_groups=[]

            if name is not None:
                for asset_group in AssetGroup.scan(name__contains=name):
                    asset_groups.append(asset_group.to_dict())
            else:
                for asset_group in AssetGroup.scan(name__exists=True):
                    asset_groups.append(asset_group.to_dict())

            return json.dumps(asset_group),200
        except Exception as e:
            message = {"exception": "{}".format(e)}
            return json.dumps(message),500

@api.route("/<uuid>")
class specific(Resource):
    @api.doc("get /asset/uuid to retrieve a single asset group")
    def get(self,uuid):
        try:
            asset_groups=[]
            if uuid is not None:
                for asset_group in AssetGroup.scan(id__eq=uuid):
                    asset_groups.append(asset_group.to_dict())
            return json.dumps(asset_groups),200
        except Exception as e:
            message = {"exception": "{}".format(e)}
            return json.dumps(message),500
{'fraction_non_alphanumeric': 0.1057224366504447, 'fraction_numerical': 0.006041282094311126, 'mean_word_length': 2.781725888324873, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '655613', 'n_tokens_mistral': 1716, 'n_tokens_neox': 1669, 'n_words': 451}