Skip to content

Latest commit

 

History

History
103 lines (79 loc) · 2.52 KB

File metadata and controls

103 lines (79 loc) · 2.52 KB

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

Create Subject Mapping
package main

import (
	"context"
	"log"

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

func main() {

	platformEndpoint := "http://localhost:8080"

	// Create a new client
	client, err := sdk.New(
		platformEndpoint,
		sdk.WithClientCredentials("opentdf", "secret", nil),
	)

	if err != nil {
		log.Fatal(err)
	}

	// Create Subject Mapping
	subjectMapping := &subjectmapping.CreateSubjectMappingRequest{
		AttributeValueId: "224c9d29-2cd4-4a38-b6ad-5f025ca93a8c",
		Actions: []*policy.Action{
			{
				Value: &policy.Action_Standard{
					Standard: policy.Action_STANDARD_ACTION_DECRYPT,
				},
			},
		},
		ExistingSubjectConditionSetId: "890b26db-4ee4-447f-ae8a-2862d922eeef",
	}

	_, err = client.SubjectMapping.CreateSubjectMapping(context.Background(), subjectMapping)
	if err != nil {
		log.Fatal(err)
	}
}
package io.opentdf.platform;
import io.opentdf.platform.sdk.*;

import java.util.concurrent.ExecutionException;

import io.opentdf.platform.policy.subjectmapping.*;
import io.opentdf.platform.policy.SubjectMapping;
import io.opentdf.platform.policy.Action;

public class CreateSubjectMapping {
    public static void main(String[] args) throws ExecutionException, InterruptedException{

        String clientId = "opentdf";
        String clientSecret = "secret";
        String platformEndpoint = "http://localhost:8080";

        SDKBuilder builder = new SDKBuilder();
        SDK sdk = builder.platformEndpoint(platformEndpoint)
                .clientSecret(clientId, clientSecret).useInsecurePlaintextConnection(true)
                .build();

        CreateSubjectMappingRequest request = CreateSubjectMappingRequest.newBuilder()
        .setAttributeValueId("33c47777-f3b6-492d-bcd2-5329e0aab642")
        .addActions(Action.newBuilder().setStandard(Action.StandardAction.STANDARD_ACTION_DECRYPT))
        .setExistingSubjectConditionSetId("9009fde8-d22b-4dfb-a456-f9ce6943244a")
        .build();

        CreateSubjectMappingResponse resp = sdk.getServices().subjectMappings().createSubjectMapping(request).get();

        SubjectMapping sm = resp.getSubjectMapping();

        System.out.println(sm.getId());
    }
}