Skip to content

Latest commit

 

History

History
105 lines (77 loc) · 2.72 KB

File metadata and controls

105 lines (77 loc) · 2.72 KB

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import SdkVersion from '@site/src/components/SdkVersion';

Create an Attribute

Signature

client.Attributes.CreateAttribute(ctx, &attributes.CreateAttributeRequest{...})
sdk.getServices().attributes().createAttributeBlocking(req, metadata).execute()
await platform.v1.attributes.createAttribute({ ... })

Parameters

Parameter Type Required Description
namespaceId string (UUID) Yes The parent namespace ID.
name string Yes Attribute name (e.g., classification, department).
rule string Yes Access rule: ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF, ANY_OF, or HIERARCHY.
values []string No Initial values to create with the attribute. Can also be added later via Create an Attribute Value.
metadata Metadata No Optional labels.

Example

import (
	"github.com/opentdf/platform/protocol/go/policy"
	"github.com/opentdf/platform/protocol/go/policy/attributes"
)

resp, err := client.Attributes.CreateAttribute(context.Background(),
	&attributes.CreateAttributeRequest{
		NamespaceId: "f47ac10b-58cc-4372-a567-0e02b2c3d479",
		Name:        "classification",
		Rule:        policy.RuleAnyOf,
		Values:      []string{"public", "confidential", "secret"},
	},
)
if err != nil {
	log.Fatal(err)
}
log.Printf("Created attribute: %s (ID: %s)\n",
	resp.GetAttribute().GetName(), resp.GetAttribute().GetId())

import CreateAttributeExample from '@site/code_samples/java/create-attribute.mdx';

import { AttributeRuleTypeEnum } from '@opentdf/sdk';

const resp = await platform.v1.attributes.createAttribute({
  namespaceId: 'f47ac10b-58cc-4372-a567-0e02b2c3d479',
  name: 'classification',
  rule: AttributeRuleTypeEnum.ANY_OF,
  values: ['public', 'confidential', 'secret'],
});
console.log('Created attribute:', resp.attribute?.name, 'ID:', resp.attribute?.id);

Returns

The created Attribute object.