> ## Documentation Index
> Fetch the complete documentation index at: https://docs.truthlocks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# إنشاء سياسة MAIP

> إنشاء سياسة جديدة لفرض الوكيل مع قواعد شرطية للتحكم في الوصول في وقت التشغيل

# إنشاء سياسة MAIP

`POST /v1/maip/policies`

ينشئ سياسة إنفاذ وكيل MAIP جديدة للمستأجر المصادق عليه. تحدد السياسات قواعد وقت التشغيل التي يتم تقييمها عندما تطلب الوكلاء الوصول إلى الموارد المحددة النطاق عبر نقطة نهاية [Evaluate Policy](https://docs.truthlocks.com/ar/api-reference/machine-identity/policies/evaluate.md).

> [!NOTE]
>
> تختلف سياسات MAIP عن [إصدار RBAC
> السياسات](https://docs.truthlocks.com/ar/api-reference/policies/create.md). تحكم سياسات MAIP \*\*الآلة
> سلوك **الوكيل** في وقت التشغيل بناءً على درجات الثقة، وعمق التفويض، والنطاقات،
> ونوع الوكيل. تحكم سياسات التحكم في الوصول المستند إلى الدور (RBAC) إصدار بيانات الاعتماد ووصول المستخدم البشري
> الوصول.

### المصادقة

يتطلب رأس `X-API-Key` أو رمز Bearer JWT. نطاق المستأجر عبر ملف تعريف الارتباط أو مطالبة JWT.

### الاستجابة

يعرض كائن السياسة الذي تم إنشاؤه مع الحقول التي تم إنشاؤها بواسطة الخادم (`id`، `tenant_id`، `status`، الطوابع الزمنية).

**id** `string`

المفتاح الأساسي UUID للسياسة التي تم إنشاؤها.

**tenant\_id** `string`

معرف UUID للمستأجر المالك.

**name** `string`

اسم السياسة كما هو مقدم.

**description** `string`

وصف السياسة، إذا تم توفيره.

**category** `string`

فئة السياسة.

**status** `string`

دائمًا `"active"` عند الإنشاء.

**priority** `integer`

أولوية التقييم.

**rules** `object`

مصفوفة القواعد كما تم توفيرها.

**created\_at** `string`

طابع زمني لإنشاء ISO 8601.

**updated\_at** `string`

طابع زمني لآخر تحديث ISO 8601.

### مثال

```bash theme={null}
curl -X POST https://api.truthlocks.com/v1/maip/policies \
  -H "X-API-Key: tl_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Block Low-Trust Write Operations",
    "description": "Deny data:write scope access for agents with trust score below 0.5",
    "category": "trust",
    "priority": 10,
    "rules": [
      {
        "conditions": [
          {"field": "trust_score", "op": "lt", "value": 0.5},
          {"field": "scope", "op": "eq", "value": "data:write"}
        ],
        "effect": "deny",
        "requires_approval": false
      }
    ]
  }'
```

```javascript theme={null}
const response = await fetch("https://api.truthlocks.com/v1/maip/policies", {
  method: "POST",
  headers: {
    "X-API-Key": "tl_live_...",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    name: "Block Low-Trust Write Operations",
    description:
      "Deny data:write scope access for agents with trust score below 0.5",
    category: "trust",
    priority: 10,
    rules: [
      {
        conditions: [
          { field: "trust_score", op: "lt", value: 0.5 },
          { field: "scope", op: "eq", value: "data:write" },
        ],
        effect: "deny",
        requires_approval: false,
      },
    ],
  }),
});
const policy = await response.json();
```

```python theme={null}
import requests

response = requests.post(
    "https://api.truthlocks.com/v1/maip/policies",
    headers={
        "X-API-Key": "tl_live_...",
        "Content-Type": "application/json",
    },
    json={
        "name": "Block Low-Trust Write Operations",
        "description": "Deny data:write scope access for agents with trust score below 0.5",
        "category": "trust",
        "priority": 10,
        "rules": [
            {
                "conditions": [
                    {"field": "trust_score", "op": "lt", "value": 0.5},
                    {"field": "scope", "op": "eq", "value": "data:write"},
                ],
                "effect": "deny",
                "requires_approval": False,
            }
        ],
    },
)
policy = response.json()
```


## OpenAPI

````yaml ar/mint-openapi.yaml POST /v1/maip/policies
openapi: 3.0.3
info:
  title: Truthlocks API
  description: >
    Truthlocks هي بنية تحتية عالمية للتحقق من المستندات وبيانات الاعتماد والأصول
    الرقمية.يحدد هذا المواصفات واجهة برمجة التطبيقات (API) الأساسية للتفاعل مع
    خدمات Truthlocks.


    ## عناوين URL الأساسية

    - **الإنتاج**: `https://api.truthlocks.com`

    - **البيئة التجريبية (Sandbox)**: `https://sandbox-api.truthlocks.com`


    ## المصادقة

    - **مفاتيح API**: استخدم رأس `X-API-Key` للعمليات من جهاز إلى جهاز

    - **رموز Bearer**: استخدم `Authorization: Bearer <jwt>` للعمليات التي يبدأها
    المستخدم


    ## هوية المستأجر

    في بيئة الإنتاج، تُستمد هوية المستأجر من السياق المصادق عليه (مفتاح API أو
    JWT).

    يتم تجاهل رأس `X-Tenant-ID` في بيئة الإنتاج لمنع الانتحال.
  version: 1.0.0
  contact:
    name: Truthlocks Support
    url: https://truthlocks.com/support
    email: support@truthlocks.com
servers:
  - url: https://api.truthlocks.com
    description: واجهة برمجة تطبيقات الإنتاج
  - url: https://sandbox-api.truthlocks.com
    description: بيئة اختبار (Sandbox)
security:
  - APIKey: []
  - BearerAuth: []
tags:
  - name: Authentication
    description: إدارة مفاتيح ورموز API
  - name: Issuers
    description: تسجيل المصدر وإدارة الثقة
  - name: Keys
    description: إدارة المفاتيح التشفيرية لجهات الإصدار
  - name: Attestations
    description: دورة حياة الإشهاد (السك، الإلغاء، الاستبدال)
  - name: Verification
    description: حزم التحقق والإثبات للإشهاد
  - name: Governance
    description: سير عمل حوكمة المصدر (للمسؤول فقط)
  - name: Identity
    description: إدارة المنظمة والمستخدمين والأدوار
  - name: Audit
    description: استعلامات أحداث التدقيق
  - name: Tenant Console
    description: ملف تعريف المستأجر ونقاط نهاية دورة الحياة
  - name: Health
    description: نقاط نهاية صحة الخدمة وجاهزيتها
  - name: Risk
    description: استيعاب إشارة المخاطر واكتشاف الاحتيال
  - name: Risk Enforcement
    description: إجراءات إنفاذ المخاطر — الحظر والتحدي والحجر والتكوين
  - name: Billing
    description: إدارة الفوترة والاشتراكات والإضافات
  - name: Machine Identity
    description: >-
      بروتوكول هوية وكيل الآلة (MAIP) — تسجيل الوكيل، الجلسات، الثقة، الشهادة،
      الامتثال، التنسيق، والمراقبة
externalDocs:
  description: واجهة برمجة تطبيقات الشفافية للقراءة فقط (مواصفات خدمة منفصلة)
  url: >-
    https://github.com/truthlocks/truthlock/blob/main/docs/transparency/openapi.yaml
paths:
  /v1/maip/policies:
    post:
      tags:
        - Machine Identity
      summary: إنشاء سياسة MAIP
      description: >-
        ينشئ سياسة إنفاذ وكيل MAIP جديدة. تحدد السياسات قواعد وقت التشغيل التي
        يتم تقييمها عندما تطلب الوكلاء الوصول إلى الموارد المحددة النطاق.
      operationId: maip.policies.create
      requestBody:
        required: true
        content:
          application/json:
            schema:
              properties:
                category:
                  type: string
                  enum:
                    - scope
                    - trust
                    - rate
                    - custom
                  description: فئة السياسة
                description:
                  type: string
                  description: وصف تفصيلي للسياسة
                  maxLength: 2048
                name:
                  type: string
                  description: اسم السياسة المقروء بشريًا
                  maxLength: 256
                priority:
                  type: integer
                  description: أولوية التقييم (الأقل = الأول)
                  minimum: 1
                  maximum: 1000
                rules:
                  description: مصفوفة من قواعد السياسة
              type: object
              required:
                - name
      responses:
        '201':
          description: تم إنشاء السياسة
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MaipPolicy'
        '400':
          description: طلب غير صالح
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '401':
          description: المصادقة مطلوبة
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
      security:
        - APIKey: []
components:
  schemas:
    MaipPolicy:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: مفتاح أساسي UUID
        tenant_id:
          type: string
          format: uuid
          description: معرف UUID للمستأجر المالك
        name:
          type: string
          description: اسم السياسة المقروء بشريًا
        description:
          type: string
          description: وصف مفصل للسياسة
        category:
          type: string
          enum:
            - scope
            - trust
            - rate
            - custom
          description: فئة السياسة
        status:
          type: string
          enum:
            - active
            - disabled
            - archived
          description: حالة دورة حياة السياسة
        priority:
          type: integer
          description: أولوية التقييم (الأقل = الأول)
        rules:
          type: array
          items:
            $ref: '#/components/schemas/MaipPolicyRule'
          description: مصفوفة من قواعد السياسة
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    ErrorEnvelope:
      type: object
      required:
        - code
        - message
        - http_status
      properties:
        code:
          type: string
          description: رمز خطأ قابل للقراءة آليًا
          enum:
            - AUTH_REQUIRED
            - AUTH_INVALID
            - PERMISSION_DENIED
            - TENANT_IDENTITY_UNVERIFIED
            - NOT_FOUND
            - VALIDATION_ERROR
            - CONFLICT
            - PAYLOAD_TOO_LARGE
            - RATE_LIMIT_EXCEEDED
            - QUOTA_EXCEEDED
            - SERVICE_UNAVAILABLE
            - INTERNAL_ERROR
        message:
          type: string
          description: رسالة خطأ مقروءة بشريًا
        http_status:
          type: integer
          description: رمز حالة HTTP
        retry_after_ms:
          type: integer
          description: عدد المللي ثانية للانتظار قبل إعادة المحاولة (لحدود المعدل)
        details:
          type: object
          description: سياق خطأ إضافي
      example:
        code: AUTH_REQUIRED
        message: Authentication required
        http_status: 401
    MaipPolicyRule:
      type: object
      properties:
        conditions:
          type: array
          items:
            $ref: '#/components/schemas/MaipPolicyCondition'
          description: الشروط التي يجب أن تتطابق جميعها (منطق AND)
        effect:
          type: string
          enum:
            - allow
            - deny
            - require_approval
          description: الإجراء الذي يجب اتخاذه عند تطابق الشروط
        requires_approval:
          type: boolean
          description: ما إذا كانت الموافقة البشرية مطلوبة
    MaipPolicyCondition:
      type: object
      properties:
        field:
          type: string
          enum:
            - trust_score
            - scope
            - agent_type
            - delegation_depth
          description: الحقل المراد تقييمه
        op:
          type: string
          enum:
            - eq
            - ne
            - lt
            - gt
            - le
            - ge
            - in
            - contains
          description: عامل المقارنة
        value:
          description: القيمة للمقارنة بها (يعتمد النوع على الحقل)
  securitySchemes:
    APIKey:
      type: apiKey
      in: header
      name: X-API-Key
      description: مفتاح API للمصادقة من جهاز إلى جهاز
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT للعمليات التي يبدأها المستخدم

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.