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

# Policy Management

> Deploy and manage Polar authorization policies in Oso Cloud. 

## Update Policy

Deploy or update your authorization policy in Oso Cloud.

**Node.js**

```javascript theme={null}
// Update policy with Polar code
await oso.policy("actor User {}");

// Example with a complete policy
const policyCode = `
  actor User {}
  resource Repository {
    permissions = ["read", "write"];
    roles = ["owner", "maintainer"];
  }
  has_role(user: User, "owner", repo: Repository) if
    user.id = repo.owner_id;
`;
await oso.policy(policyCode);
```

**Signature:** `oso.policy(policy)`

```python theme={null}
# Update policy with Polar code
oso.policy("actor User {}")

# Example with a complete policy
policy_code = """
actor User {}
resource Repository {
    permissions = ["read", "write"];
    roles = ["owner", "maintainer"];
}
has_role(user: User, "owner", repo: Repository) if
    user.id = repo.owner_id;
"""
oso.policy(policy_code)
```

**Signature:** `oso.policy(policy)`

```go theme={null}
// Update policy with Polar code
err := osoClient.Policy("actor User {}")
if err != nil {
    log.Fatal(err)
}

// Example with a complete policy
policyCode := `
actor User {}
resource Repository {
    permissions = ["read", "write"];
    roles = ["owner", "maintainer"];
}
has_role(user: User, "owner", repo: Repository) if
    user.id = repo.owner_id;
`
err = osoClient.Policy(policyCode)
```

**Signature:** `osoClient.Policy(policy)`

```java theme={null}
// Update policy with Polar code
oso.policy("actor User {}");

// Example with a complete policy
String policyCode = """
    actor User {}
    resource Repository {
        permissions = ["read", "write"];
        roles = ["owner", "maintainer"];
    }
    has_role(user: User, "owner", repo: Repository) if
        user.id = repo.owner_id;
    """;
oso.policy(policyCode);
```

**Signature:** `oso.policy(policy)`

```ruby theme={null}
# Update policy with Polar code
oso.policy("actor User {}")

# Example with a complete policy
policy_code = <<~POLAR
  actor User {}
  resource Repository {
    permissions = ["read", "write"];
    roles = ["owner", "maintainer"];
  }
  has_role(user: User, "owner", repo: Repository) if
    user.id = repo.owner_id;
POLAR
oso.policy(policy_code)
```

**Signature:** `oso.policy(policy)`

```csharp theme={null}
// Update policy with Polar code
await oso.Policy("actor User {}");

// Example with a complete policy
var policyCode = @"
    actor User {}
    resource Repository {
        permissions = [""read"", ""write""];
        roles = [""owner"", ""maintainer""];
    }
    has_role(user: User, ""owner"", repo: Repository) if
        user.id = repo.owner_id;
";
await oso.Policy(policyCode);
```

**Signature:** `oso.Policy(policy)`

**CLI**

```bash theme={null}
# Update policy from file
oso-cloud policy main.polar

# Update with multiple files
oso-cloud policy main.polar secondary.polar

# Force update (skip confirmation)
oso-cloud policy main.polar --force

# Preview changes without applying
oso-cloud policy main.polar --preview
```

**Signature:** `oso-cloud policy <policy-file> <policy-file2> ...`

### Test Policy

```bash theme={null}
# Test policy files
oso-cloud test main.polar

# Test multiple files
oso-cloud test main.polar secondary.polar
```

**Signature:** `oso-cloud test <policy-file> <policy-file2> ...`

## Get Policy Metadata

Retrieve metadata about your deployed policy, including available resources, permissions, and roles.

**Node.js**

```javascript theme={null}
// Get policy metadata
const metadata = await oso.getPolicyMetadata();

// Access resource information
console.log(metadata.resources.keys());        // List all resources
console.log(metadata.resources.get("Repository")); // Get specific resource metadata
```

**Signature:** `oso.getPolicyMetadata()`

```python theme={null}
# Get policy metadata
metadata = oso.get_policy_metadata()

# Access resource information
print(metadata.resources.keys())               # List all resources
print(metadata.resources["Repository"])        # Get specific resource metadata
```

**Signature:** `oso.get_policy_metadata()`

```go theme={null}
// Get policy metadata
metadata, err := osoClient.GetPolicyMetadata()
if err != nil {
    log.Fatal(err)
}

// Access resource information
for resourceName := range metadata.Resources {
    fmt.Printf("Resource: %s\n", resourceName)
}
```

**Signature:** `osoClient.GetPolicyMetadata()`

```java theme={null}
// Get policy metadata
PolicyMetadata metadata = oso.getPolicyMetadata();

// Access resource information
System.out.println(metadata.getResources().keySet());  // List all resources
System.out.println(metadata.getResources().get("Repository")); // Get specific resource
```

**Signature:** `oso.getPolicyMetadata()`

```ruby theme={null}
# Get policy metadata
metadata = oso.get_policy_metadata

# Access resource information
puts metadata.resources.keys                   # List all resources
puts metadata.resources["Repository"]          # Get specific resource metadata
```

**Signature:** `oso.get_policy_metadata`

```csharp theme={null}
// Get policy metadata
var metadata = await oso.GetPolicyMetadata();

// Access resource information
Console.WriteLine(string.Join(", ", metadata.Resources.Keys)); // List all resources
Console.WriteLine(metadata.Resources["Repository"]);           // Get specific resource
```

**Signature:** `oso.GetPolicyMetadata()`


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