Example #1
0
    def put(self, kid):
        if SuperUserPermission().can():
            body = request.get_json()
            try:
                key = pre_oci_model.get_service_key(kid,
                                                    approved_only=False,
                                                    alive_only=False)
            except ServiceKeyDoesNotExist:
                raise NotFound()

            key_log_metadata = {
                "kid": key.kid,
                "service": key.service,
                "name": body.get("name", key.name),
                "expiration_date": key.expiration_date,
            }

            if "expiration" in body:
                expiration_date = body["expiration"]
                if expiration_date is not None and expiration_date != "":
                    try:
                        expiration_date = datetime.utcfromtimestamp(
                            float(expiration_date))
                    except ValueError as ve:
                        raise InvalidRequest("Invalid expiration date: %s" %
                                             ve)

                    if expiration_date <= datetime.now():
                        raise InvalidRequest(
                            "Cannot have an expiration date in the past")

                key_log_metadata.update({
                    "old_expiration_date": key.expiration_date,
                    "expiration_date": expiration_date,
                })

                log_action("service_key_extend", None, key_log_metadata)
                pre_oci_model.set_key_expiration(kid, expiration_date)

            if "name" in body or "metadata" in body:
                key_name = body.get("name")
                if not validate_service_key_name(key_name):
                    raise InvalidRequest(
                        "Invalid service key friendly name: %s" % key_name)

                pre_oci_model.update_service_key(kid, key_name,
                                                 body.get("metadata"))
                log_action("service_key_modify", None, key_log_metadata)

            updated_key = pre_oci_model.get_service_key(kid,
                                                        approved_only=False,
                                                        alive_only=False)
            return jsonify(updated_key.to_dict())

        raise Unauthorized()
Example #2
0
    def put(self, kid):
        if SuperUserPermission().can():
            body = request.get_json()
            try:
                key = pre_oci_model.get_service_key(kid,
                                                    approved_only=False,
                                                    alive_only=False)
            except ServiceKeyDoesNotExist:
                raise NotFound()

            key_log_metadata = {
                'kid': key.kid,
                'service': key.service,
                'name': body.get('name', key.name),
                'expiration_date': key.expiration_date,
            }

            if 'expiration' in body:
                expiration_date = body['expiration']
                if expiration_date is not None and expiration_date != '':
                    try:
                        expiration_date = datetime.utcfromtimestamp(
                            float(expiration_date))
                    except ValueError as ve:
                        raise InvalidRequest('Invalid expiration date: %s' %
                                             ve)

                    if expiration_date <= datetime.now():
                        raise InvalidRequest(
                            'Cannot have an expiration date in the past')

                key_log_metadata.update({
                    'old_expiration_date': key.expiration_date,
                    'expiration_date': expiration_date,
                })

                log_action('service_key_extend', None, key_log_metadata)
                pre_oci_model.set_key_expiration(kid, expiration_date)

            if 'name' in body or 'metadata' in body:
                key_name = body.get('name')
                if not validate_service_key_name(key_name):
                    raise InvalidRequest(
                        'Invalid service key friendly name: %s' % key_name)

                pre_oci_model.update_service_key(kid, key_name,
                                                 body.get('metadata'))
                log_action('service_key_modify', None, key_log_metadata)

            updated_key = pre_oci_model.get_service_key(kid,
                                                        approved_only=False,
                                                        alive_only=False)
            return jsonify(updated_key.to_dict())

        raise Unauthorized()
Example #3
0
    def get(self, kid):
        if SuperUserPermission().can():
            try:
                key = pre_oci_model.get_service_key(kid, approved_only=False, alive_only=False)
                return jsonify(key.to_dict())
            except ServiceKeyDoesNotExist:
                raise NotFound()

        raise Unauthorized()