{
  "name": "Mountable sandbox job",
  "nodes": [
    {
      "parameters": {},
      "id": "11111111-1111-4111-8111-111111111112",
      "name": "When clicking Test workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "fs",
              "name": "filesystem_id",
              "value": "REPLACE_WITH_FILESYSTEM_ID",
              "type": "string"
            },
            {
              "id": "hook",
              "name": "sandbox_webhook_url",
              "value": "https://example.invalid/mountable-sandbox",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "22222222-2222-4222-8222-222222222223",
      "name": "Job settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://mountable.io/api/v1/me",
        "authentication": "genericCredentialType",
        "options": {},
        "genericAuthType": "httpHeaderAuth",
        "sendBody": false
      },
      "id": "33333333-3333-4333-8333-333333333334",
      "name": "Who am I",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "replace-with-mountable-credential",
          "name": "Mountable API key"
        }
      }
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{ 'https://mountable.io/api/v1/orgs/' + $json.api_key.org_id + '/filesystems/' + $('Job settings').item.json.filesystem_id + '/usage' }}",
        "authentication": "genericCredentialType",
        "options": {},
        "genericAuthType": "httpHeaderAuth",
        "sendBody": false
      },
      "id": "44444444-4444-4444-8444-444444444445",
      "name": "Check usage",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        660,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "replace-with-mountable-credential",
          "name": "Mountable API key"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://mountable.io/api/v1/mount-sessions",
        "authentication": "genericCredentialType",
        "options": {},
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ filesystem_id: $('Job settings').item.json.filesystem_id, mode: 'rw', idempotency_key: String($execution.id), max_duration_seconds: 3600 }) }}"
      },
      "id": "55555555-5555-4555-8555-555555555556",
      "name": "Create mount session",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "replace-with-mountable-credential",
          "name": "Mountable API key"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "66666666",
              "leftValue": "={{ $json.ticket ?? '' }}",
              "rightValue": "",
"operator": {
              "type": "string",
              "operation": "notEmpty",
              "singleValue": true
            }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "66666666-6666-4666-8666-666666666667",
      "name": "Ticket present",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1100,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Job settings').item.json.sandbox_webhook_url }}",
        "authentication": "none",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ session_id: $('Create mount session').item.json.id, ticket: $('Create mount session').item.json.ticket, mount_command: \"mkdir -p /mnt/mountable && printf '%s\\\\n' \\\"$MOUNTABLE_TICKET\\\" | mountable mount --ticket-stdin --json /mnt/mountable\" }) }}"
      },
      "id": "77777777-7777-4777-8777-777777777778",
      "name": "Run sandbox",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1320,
        -120
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "={{ 'https://mountable.io/api/v1/mount-sessions/' + $('Create mount session').item.json.id }}",
        "authentication": "genericCredentialType",
        "options": {},
        "genericAuthType": "httpHeaderAuth",
        "sendBody": false
      },
      "id": "88888888-8888-4888-8888-888888888889",
      "name": "Revoke session",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1540,
        -120
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "replace-with-mountable-credential",
          "name": "Mountable API key"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "99999999",
              "leftValue": "={{ $('Create mount session').item.json.state }}",
              "rightValue": "requested",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "99999999-9999-4999-8999-999999999990",
      "name": "Lost ticket",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1320,
        160
      ]
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "={{ 'https://mountable.io/api/v1/mount-sessions/' + $('Create mount session').item.json.id }}",
        "authentication": "genericCredentialType",
        "options": {},
        "genericAuthType": "httpHeaderAuth",
        "sendBody": false
      },
      "id": "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaab",
      "name": "Revoke lost ticket",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1540,
        160
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "replace-with-mountable-credential",
          "name": "Mountable API key"
        }
      }
    }
  ],
  "connections": {
    "When clicking Test workflow": {
      "main": [
        [
          {
            "node": "Job settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Job settings": {
      "main": [
        [
          {
            "node": "Who am I",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Who am I": {
      "main": [
        [
          {
            "node": "Check usage",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check usage": {
      "main": [
        [
          {
            "node": "Create mount session",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ticket present": {
      "main": [
        [
          {
            "node": "Run sandbox",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Lost ticket",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create mount session": {
      "main": [
        [
          {
            "node": "Ticket present",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run sandbox": {
      "main": [
        [
          {
            "node": "Revoke session",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lost ticket": {
      "main": [
        [
          {
            "node": "Revoke lost ticket",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
