> For the complete documentation index, see [llms.txt](https://docs.realmjoin.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.realmjoin.com/pt/dev-reference/simulating-a-runbook-environment.md).

# Simular um ambiente de runbook

Para desenvolver novos runbooks, pode ser necessário ativar o RealmJoin.RunbookHelper para autenticar como se estivesse a executar dentro de um runbook.

## Visão geral

### Criar um Registro de Aplicativo

Criamos um Registro de Aplicativo do Azure para simular o início de sessão no estilo de aplicativo no Microsoft Entra.

<figure><img src="https://686519968-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MkrcM7cKOpXKri1kVrh%2Fuploads%2FAELajVV85Wm6a1Mwtmew%2Fimage.png?alt=media&amp;token=15d94203-906f-4d0f-8c7b-77e8e032201b" alt=""><figcaption><p>Criar um Registro de Aplicativo</p></figcaption></figure>

### Conceder permissões

Concederemos as mesmas permissões que a identidade gerenciada teria. Usaremos o mesmo [AppRoleGranter Toolkit](https://github.com/hcoberdalhoff/approle-and-directoryrole-granter) para esse fim.

Substitua `{AppRegObjectId}` com o ID de objeto do seu registro de aplicativo.

```powershell
git clone https://github.com/hcoberdalhoff/approle-and-directoryrole-granter.git
cd "approle-and-directoryrole-granter\RealmJoinVnext"
. .\AllInOne.ps1 -appRegObjectId "{AppRegObjectId}"
```

### Criar e carregar um certificado de desenvolvimento

Ver [aqui ](https://github.com/realmjoin/RealmJoin.RunbookHelper/blob/main/DevCertificates.ps1)para um exemplo de como criar um certificado de desenvolvimento do RunbookHelper. Substitua `{Variables}` conforme necessário.

A `{AppID}` refere-se ao ID do aplicativo/cliente do Application Regsitrations.

Se você não tiver um ID de assinatura específico, basta usar uma assinatura padrão do seu Tenant. (Na maioria dos casos, isso não importa.)

```powershell
New-SelfSignedCertificate -Subject 'CN=AzureRunAsConnection, OU={AppID}, DC={TenantID}, O={SubscriptionID}' `
    -CertStoreLocation "cert:\CurrentUser\My" -NotAfter (Get-Date).AddYears(10) -KeySpec Signature | `
    Export-Certificate -FilePath "AzureRunAsConnection.cer"
```

Você obterá um arquivo `AzureRunAsConnection.cer` que você carregará nos segredos do registro de aplicativos.

{% hint style="info" %}
Se você quiser atender a vários aplicativos/ambientes, pode substituir o padrão "AzureRunAsConnection" em`CN=AzureRunAsConnection` por um nome personalizado ao criar o certificado para esse ambiente.

Você pode então selecionar qual ambiente/certificado (por exemplo, "OtherEnv") usar para se conectar usando `Connect-RjRbGraph -AutomationConnectionName "OtherEnv"`

Dessa forma, você pode acessar vários ambientes a partir da mesma máquina.
{% endhint %}

<figure><img src="https://686519968-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MkrcM7cKOpXKri1kVrh%2Fuploads%2Fo2vVY6YO0gimSWg4XOfV%2Fimage.png?alt=media&amp;token=958b8b21-c0fa-464e-aba9-954c008eea8c" alt=""><figcaption><p>Carregamento do certificado</p></figcaption></figure>

### Utilização

Basta usar `Connect-RjRbGraph` para autenticar no aplicativo.

Certifique-se de remover certificados de desenvolvimento antigos usando o mmc.exe do seu conjunto de certificados pessoais, se houver, para evitar conflitos/falhas de login.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.realmjoin.com/pt/dev-reference/simulating-a-runbook-environment.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
