Exemplo n.º 1
0
    def post(self, kid):
        if SuperUserPermission().can():
            notes = request.get_json().get("notes", "")
            approver = get_authenticated_user()
            try:
                key = pre_oci_model.approve_service_key(
                    kid, approver, ServiceKeyApprovalType.SUPERUSER, notes=notes
                )

                # Log the approval of the service key.
                key_log_metadata = {
                    "kid": kid,
                    "service": key.service,
                    "name": key.name,
                    "expiration_date": key.expiration_date,
                }

                log_action("service_key_approve", None, key_log_metadata)
            except ServiceKeyDoesNotExist:
                raise NotFound()
            except ServiceKeyAlreadyApproved:
                pass

            return make_response("", 201)

        raise Unauthorized()
Exemplo n.º 2
0
    def post(self):
        if SuperUserPermission().can():
            body = request.get_json()
            key_name = body.get("name", "")
            if not validate_service_key_name(key_name):
                raise InvalidRequest("Invalid service key friendly name: %s" % key_name)

            # Ensure we have a valid expiration date if specified.
            expiration_date = body.get("expiration", None)
            if expiration_date is not None:
                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("Expiration date cannot be in the past")

            # Create the metadata for the key.
            user = get_authenticated_user()
            metadata = body.get("metadata", {})
            metadata.update(
                {
                    "created_by": "Quay Superuser Panel",
                    "creator": user.username,
                    "ip": get_request_ip(),
                }
            )

            # Generate a key with a private key that we *never save*.
            (private_key, key_id) = pre_oci_model.generate_service_key(
                body["service"], expiration_date, metadata=metadata, name=key_name
            )
            # Auto-approve the service key.
            pre_oci_model.approve_service_key(
                key_id, user, ServiceKeyApprovalType.SUPERUSER, notes=body.get("notes", "")
            )

            # Log the creation and auto-approval of the service key.
            key_log_metadata = {
                "kid": key_id,
                "preshared": True,
                "service": body["service"],
                "name": key_name,
                "expiration_date": expiration_date,
                "auto_approved": True,
            }

            log_action("service_key_create", None, key_log_metadata)
            log_action("service_key_approve", None, key_log_metadata)

            return jsonify(
                {
                    "kid": key_id,
                    "name": key_name,
                    "service": body["service"],
                    "public_key": private_key.publickey().exportKey("PEM").decode("ascii"),
                    "private_key": private_key.exportKey("PEM").decode("ascii"),
                }
            )

        raise Unauthorized()
Exemplo n.º 3
0
    def post(self):
        if SuperUserPermission().can():
            body = request.get_json()
            key_name = body.get('name', '')
            if not validate_service_key_name(key_name):
                raise InvalidRequest('Invalid service key friendly name: %s' %
                                     key_name)

            # Ensure we have a valid expiration date if specified.
            expiration_date = body.get('expiration', None)
            if expiration_date is not None:
                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(
                        'Expiration date cannot be in the past')

            # Create the metadata for the key.
            user = get_authenticated_user()
            metadata = body.get('metadata', {})
            metadata.update({
                'created_by': 'Quay Superuser Panel',
                'creator': user.username,
                'ip': get_request_ip(),
            })

            # Generate a key with a private key that we *never save*.
            (private_key,
             key_id) = pre_oci_model.generate_service_key(body['service'],
                                                          expiration_date,
                                                          metadata=metadata,
                                                          name=key_name)
            # Auto-approve the service key.
            pre_oci_model.approve_service_key(key_id,
                                              user,
                                              ServiceKeyApprovalType.SUPERUSER,
                                              notes=body.get('notes', ''))

            # Log the creation and auto-approval of the service key.
            key_log_metadata = {
                'kid': key_id,
                'preshared': True,
                'service': body['service'],
                'name': key_name,
                'expiration_date': expiration_date,
                'auto_approved': True,
            }

            log_action('service_key_create', None, key_log_metadata)
            log_action('service_key_approve', None, key_log_metadata)

            return jsonify({
                'kid':
                key_id,
                'name':
                key_name,
                'service':
                body['service'],
                'public_key':
                private_key.publickey().exportKey('PEM'),
                'private_key':
                private_key.exportKey('PEM'),
            })

        raise Unauthorized()