Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions code_samples/policy_code/create_attribute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ package main

import (
"context"
"crypto/rand"
"log"

"github.com/opentdf/platform/protocol/go/policy"
"github.com/opentdf/platform/protocol/go/policy/attributes"
"github.com/opentdf/platform/protocol/go/policy/namespaces"
"github.com/opentdf/platform/sdk"
)

Expand All @@ -32,20 +34,31 @@ func main() {
log.Fatal(err)
}

// Create a new attribute
namespaceID := "f9ac9403-a12f-4ed3-b3c9-a46910361b4d"
// List namespaces to get a namespace ID
listResponse, err := client.Namespaces.ListNamespaces(context.Background(), &namespaces.ListNamespacesRequest{})
if err != nil {
log.Fatalf("failed to list namespaces: %s", err)
}

if len(listResponse.GetNamespaces()) == 0 {
log.Fatal("no namespaces found")
}

namespaceID := listResponse.GetNamespaces()[0].GetId()

// Create a new attribute
attrRequest := &attributes.CreateAttributeRequest{
NamespaceId: namespaceID,
Name: "role",
Name: "role" + "-" + rand.Text()[:4],
Rule: policy.AttributeRuleTypeEnum_ATTRIBUTE_RULE_TYPE_ENUM_ANY_OF,
Values: []string{"admin", "developer", "guest"},
}

_, err = client.Attributes.CreateAttribute(context.Background(), attrRequest)
attribute, err := client.Attributes.CreateAttribute(context.Background(), attrRequest)
if err != nil {
log.Fatal(err)
}
log.Printf("Created attribute: %s with ID: %s in namespace: %s\n", attribute.GetAttribute().Name, attribute.GetAttribute().GetId(), namespaceID)
}
```

Expand Down
2 changes: 1 addition & 1 deletion code_samples/policy_code/create_namespace.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

func main() {

platformEndpoint := "https://opentdf.io"
platformEndpoint := "http://localhost:9002"
Comment thread
cassandrabailey293 marked this conversation as resolved.

// Create a new client
client, err := sdk.New(
Expand Down
3 changes: 2 additions & 1 deletion code_samples/policy_code/create_subject_condition_set.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ func main() {
},
}

_, err = client.SubjectMapping.CreateSubjectConditionSet(context.Background(), coditionset)
log, err := client.SubjectMapping.CreateSubjectConditionSet(context.Background(), coditionset)
if err != nil {
log.Fatal(err)
}

log.Printf("Created Subject Condition Set with ID: %s\n", resp.GetSubjectConditionSet().GetId())
}
```

Expand Down
37 changes: 20 additions & 17 deletions code_samples/tdf/encryption_ztdf.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,67 @@ import TabItem from '@theme/TabItem';
package main

import (
"bufio"
"bytes"
"log"
"os"
"strings"

"github.com/opentdf/platform/sdk"
)

func main() {
log.Println("๐Ÿš€ Starting OpenTDF example...")

platformEndpoint := "http://localhost:9002"
log.Printf("๐Ÿ“ก Connecting to platform: %s", platformEndpoint)

// Create a new client
log.Println("๐Ÿ” Initializing new SDK client...")
client, err := sdk.New(
platformEndpoint,
sdk.WithClientCredentials("opentdf", "secret", nil),
)

if err != nil {
log.Fatal(err)
log.Fatalf("โŒ Client initialization failed: %v", err)
}

// Encrypt ztdf

log.Println("๐Ÿ“ Preparing sensitive data for encryption...")
str := strings.NewReader("Sensitive data!")
buf := &bytes.Buffer{}
out := bufio.NewWriter(buf)

manifest, err := client.CreateTDF(out, str,
log.Println("๐Ÿ”’ Encrypting data...")
manifest, err := client.CreateTDF(buf, str,
//sdk.WithDataAttributes("https://opentdf.io/attr/role/value/developer"),
sdk.WithKasInformation(
sdk.KASInfo{
URL: "http://localhost:9002",
URL: platformEndpoint,
},
),
)

if err != nil {
log.Fatal(err)
log.Fatalf("โŒ Encryption failed: %v", err)
}

//Flush data to buffer
out.Flush()

log.Printf("TDF Manifest: %v", manifest)
log.Println("โœ… Data successfully encrypted")
log.Printf("๐Ÿ“‹ TDF Manifest details:\n\n%v\n\n", manifest)

// Decrypt ztdf
log.Println("๐Ÿ”“ Decrypting data...")
tdfReader, err := client.LoadTDF(bytes.NewReader(buf.Bytes()))
if err != nil {
log.Fatal(err)
log.Fatalf("โŒ Decryption failed: %v", err)
}

// Write decrypted data to stdout
_, err = tdfReader.WriteTo(os.Stdout)
if err != nil {
log.Fatal(err)
// Create a buffer to capture the decrypted data
var decryptedBuf bytes.Buffer
if _, err = tdfReader.WriteTo(&decryptedBuf); err != nil {
log.Fatalf("โŒ Failed to write decrypted data: %v", err)
}

log.Printf("๐Ÿ“ค Decrypted content: \n\n%s\n\n", decryptedBuf.String())
log.Println("โœ… Example complete!")
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/components/authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Two versions of Authorization Service are currently served simultaneously by the
Version 2 of Authorization Service introduced the following changes:
- consideration of policy [actions](./policy/actions.md) contained in [subject mappings](./policy/subject_mappings.md) within entitlement decisioning
- API structure and clarity improvements
- [entity identifier](#entityidentifier)
- [entity identifier](#entity-identifier)
- multiplexing design within decisioning
- removal of scopes when retrieving entitlements, in deference to decision APIs

Expand Down