mirror of https://github.com/OpenKMIP/PyKMIP.git
Add operation policy name to demo scripts
This change adds the ability to set the operation policy name attribute to object creation demo scripts, including demos for the Create, CreateKeyPair, and Register operations.
This commit is contained in:
parent
6bda8ec999
commit
a75f0e3666
|
@ -46,7 +46,11 @@ if __name__ == '__main__':
|
||||||
# Build the client and connect to the server
|
# Build the client and connect to the server
|
||||||
with client.ProxyKmipClient(config=config) as client:
|
with client.ProxyKmipClient(config=config) as client:
|
||||||
try:
|
try:
|
||||||
uid = client.create(algorithm, length)
|
uid = client.create(
|
||||||
|
algorithm,
|
||||||
|
length,
|
||||||
|
operation_policy_name=opts.operation_policy_name
|
||||||
|
)
|
||||||
logger.info("Successfully created symmetric key with ID: "
|
logger.info("Successfully created symmetric key with ID: "
|
||||||
"{0}".format(uid))
|
"{0}".format(uid))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -45,7 +45,11 @@ if __name__ == '__main__':
|
||||||
# Build the client and connect to the server
|
# Build the client and connect to the server
|
||||||
with client.ProxyKmipClient(config=config) as client:
|
with client.ProxyKmipClient(config=config) as client:
|
||||||
try:
|
try:
|
||||||
public_uid, private_uid = client.create_key_pair(algorithm, length)
|
public_uid, private_uid = client.create_key_pair(
|
||||||
|
algorithm,
|
||||||
|
length,
|
||||||
|
operation_policy_name=opts.operation_policy_name
|
||||||
|
)
|
||||||
logger.info("Successfully created public key with ID: {0}".format(
|
logger.info("Successfully created public key with ID: {0}".format(
|
||||||
public_uid))
|
public_uid))
|
||||||
logger.info("Successfully created private key with ID: {0}".format(
|
logger.info("Successfully created private key with ID: {0}".format(
|
||||||
|
|
|
@ -88,6 +88,7 @@ if __name__ == '__main__':
|
||||||
name = 'Demo X.509 Certificate'
|
name = 'Demo X.509 Certificate'
|
||||||
|
|
||||||
cert = objects.X509Certificate(value, usage_mask, name)
|
cert = objects.X509Certificate(value, usage_mask, name)
|
||||||
|
cert.operation_policy_name = opts.operation_policy_name
|
||||||
|
|
||||||
# Build the client and connect to the server
|
# Build the client and connect to the server
|
||||||
with client.ProxyKmipClient(config=config) as client:
|
with client.ProxyKmipClient(config=config) as client:
|
||||||
|
|
|
@ -36,6 +36,7 @@ if __name__ == '__main__':
|
||||||
name = 'Demo Opaque Object'
|
name = 'Demo Opaque Object'
|
||||||
|
|
||||||
obj = objects.OpaqueObject(value, opaque_type, name)
|
obj = objects.OpaqueObject(value, opaque_type, name)
|
||||||
|
obj.operation_policy_name = opts.operation_policy_name
|
||||||
|
|
||||||
# Build the client and connect to the server
|
# Build the client and connect to the server
|
||||||
with client.ProxyKmipClient(config=config) as client:
|
with client.ProxyKmipClient(config=config) as client:
|
||||||
|
|
|
@ -115,6 +115,7 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
key = objects.PrivateKey(
|
key = objects.PrivateKey(
|
||||||
algorithm, length, value, format_type, usage_mask, name)
|
algorithm, length, value, format_type, usage_mask, name)
|
||||||
|
key.operation_policy_name = opts.operation_policy_name
|
||||||
|
|
||||||
# Build the client and connect to the server
|
# Build the client and connect to the server
|
||||||
with client.ProxyKmipClient(config=config) as client:
|
with client.ProxyKmipClient(config=config) as client:
|
||||||
|
|
|
@ -57,6 +57,7 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
key = objects.PublicKey(
|
key = objects.PublicKey(
|
||||||
algorithm, length, value, format_type, usage_mask, name)
|
algorithm, length, value, format_type, usage_mask, name)
|
||||||
|
key.operation_policy_name = opts.operation_policy_name
|
||||||
|
|
||||||
# Build the client and connect to the server
|
# Build the client and connect to the server
|
||||||
with client.ProxyKmipClient(config=config) as client:
|
with client.ProxyKmipClient(config=config) as client:
|
||||||
|
|
|
@ -38,6 +38,7 @@ if __name__ == '__main__':
|
||||||
name = 'Demo Secret Data'
|
name = 'Demo Secret Data'
|
||||||
|
|
||||||
secret = objects.SecretData(value, data_type, usage_mask, name)
|
secret = objects.SecretData(value, data_type, usage_mask, name)
|
||||||
|
secret.operation_policy_name = opts.operation_policy_name
|
||||||
|
|
||||||
# Build the client and connect to the server
|
# Build the client and connect to the server
|
||||||
with client.ProxyKmipClient(config=config) as client:
|
with client.ProxyKmipClient(config=config) as client:
|
||||||
|
|
|
@ -41,6 +41,7 @@ if __name__ == '__main__':
|
||||||
name = 'Demo Symmetric Key'
|
name = 'Demo Symmetric Key'
|
||||||
|
|
||||||
key = objects.SymmetricKey(algorithm, length, value, usage_mask, name)
|
key = objects.SymmetricKey(algorithm, length, value, usage_mask, name)
|
||||||
|
key.operation_policy_name = opts.operation_policy_name
|
||||||
|
|
||||||
# Build the client and connect to the server
|
# Build the client and connect to the server
|
||||||
with client.ProxyKmipClient(config=config) as client:
|
with client.ProxyKmipClient(config=config) as client:
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from kmip.core import enums
|
||||||
from kmip.core.enums import AttributeType
|
from kmip.core.enums import AttributeType
|
||||||
from kmip.core.enums import CredentialType
|
from kmip.core.enums import CredentialType
|
||||||
from kmip.core.enums import CryptographicAlgorithm
|
from kmip.core.enums import CryptographicAlgorithm
|
||||||
|
@ -108,6 +109,14 @@ if __name__ == '__main__':
|
||||||
name = Attribute(attribute_name=name, attribute_value=value)
|
name = Attribute(attribute_name=name, attribute_value=value)
|
||||||
|
|
||||||
attributes = [algorithm_obj, usage_mask, length_obj, name]
|
attributes = [algorithm_obj, usage_mask, length_obj, name]
|
||||||
|
|
||||||
|
if opts.operation_policy_name is not None:
|
||||||
|
opn = attribute_factory.create_attribute(
|
||||||
|
enums.AttributeType.OPERATION_POLICY_NAME,
|
||||||
|
opts.operation_policy_name
|
||||||
|
)
|
||||||
|
attributes.append(opn)
|
||||||
|
|
||||||
template_attribute = TemplateAttribute(attributes=attributes)
|
template_attribute = TemplateAttribute(attributes=attributes)
|
||||||
|
|
||||||
# Create the SYMMETRIC_KEY object
|
# Create the SYMMETRIC_KEY object
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from kmip.core import enums
|
||||||
from kmip.core.enums import AttributeType
|
from kmip.core.enums import AttributeType
|
||||||
from kmip.core.enums import CredentialType
|
from kmip.core.enums import CredentialType
|
||||||
from kmip.core.enums import CryptographicAlgorithm
|
from kmip.core.enums import CryptographicAlgorithm
|
||||||
|
@ -108,6 +109,14 @@ if __name__ == '__main__':
|
||||||
length)
|
length)
|
||||||
|
|
||||||
attributes = [algorithm_obj, length_obj, name, usage_mask]
|
attributes = [algorithm_obj, length_obj, name, usage_mask]
|
||||||
|
|
||||||
|
if opts.operation_policy_name is not None:
|
||||||
|
opn = attribute_factory.create_attribute(
|
||||||
|
enums.AttributeType.OPERATION_POLICY_NAME,
|
||||||
|
opts.operation_policy_name
|
||||||
|
)
|
||||||
|
attributes.append(opn)
|
||||||
|
|
||||||
common = CommonTemplateAttribute(attributes=attributes)
|
common = CommonTemplateAttribute(attributes=attributes)
|
||||||
private = PrivateKeyTemplateAttribute(attributes=attributes)
|
private = PrivateKeyTemplateAttribute(attributes=attributes)
|
||||||
public = PublicKeyTemplateAttribute(attributes=attributes)
|
public = PublicKeyTemplateAttribute(attributes=attributes)
|
||||||
|
|
|
@ -13,11 +13,13 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from kmip.core import enums
|
||||||
from kmip.core.enums import KeyFormatType
|
from kmip.core.enums import KeyFormatType
|
||||||
from kmip.core.enums import ObjectType
|
from kmip.core.enums import ObjectType
|
||||||
from kmip.core.enums import Operation
|
from kmip.core.enums import Operation
|
||||||
from kmip.core.enums import ResultStatus
|
from kmip.core.enums import ResultStatus
|
||||||
|
|
||||||
|
from kmip.core.factories.attributes import AttributeFactory
|
||||||
from kmip.core.objects import TemplateAttribute
|
from kmip.core.objects import TemplateAttribute
|
||||||
|
|
||||||
from kmip.demos import utils
|
from kmip.demos import utils
|
||||||
|
@ -51,9 +53,19 @@ if __name__ == '__main__':
|
||||||
logger.error(
|
logger.error(
|
||||||
"Invalid key format type specified; exiting early from demo")
|
"Invalid key format type specified; exiting early from demo")
|
||||||
|
|
||||||
|
attribute_factory = AttributeFactory()
|
||||||
|
|
||||||
# Create the template attribute for the secret and then build the secret
|
# Create the template attribute for the secret and then build the secret
|
||||||
usage_mask = utils.build_cryptographic_usage_mask(logger, object_type)
|
usage_mask = utils.build_cryptographic_usage_mask(logger, object_type)
|
||||||
attributes = [usage_mask]
|
attributes = [usage_mask]
|
||||||
|
|
||||||
|
if opts.operation_policy_name is not None:
|
||||||
|
opn = attribute_factory.create_attribute(
|
||||||
|
enums.AttributeType.OPERATION_POLICY_NAME,
|
||||||
|
opts.operation_policy_name
|
||||||
|
)
|
||||||
|
attributes.append(opn)
|
||||||
|
|
||||||
template_attribute = TemplateAttribute(attributes=attributes)
|
template_attribute = TemplateAttribute(attributes=attributes)
|
||||||
|
|
||||||
secret = utils.build_object(logger, object_type, key_format_type)
|
secret = utils.build_object(logger, object_type, key_format_type)
|
||||||
|
|
|
@ -104,6 +104,15 @@ def build_cli_parser(operation=None):
|
||||||
default=None,
|
default=None,
|
||||||
dest="length",
|
dest="length",
|
||||||
help="Key length in bits (e.g., 128, 256)")
|
help="Key length in bits (e.g., 128, 256)")
|
||||||
|
parser.add_option(
|
||||||
|
"-o",
|
||||||
|
"--operation-policy-name",
|
||||||
|
action="store",
|
||||||
|
type="str",
|
||||||
|
default=None,
|
||||||
|
dest="operation_policy_name",
|
||||||
|
help="Operation policy name for the secret (e.g., 'default')"
|
||||||
|
)
|
||||||
elif operation is Operation.CREATE_KEY_PAIR:
|
elif operation is Operation.CREATE_KEY_PAIR:
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
"-a",
|
"-a",
|
||||||
|
@ -129,6 +138,16 @@ def build_cli_parser(operation=None):
|
||||||
default=None,
|
default=None,
|
||||||
dest="name",
|
dest="name",
|
||||||
help="Name of key pair to create")
|
help="Name of key pair to create")
|
||||||
|
parser.add_option(
|
||||||
|
"-o",
|
||||||
|
"--operation-policy-name",
|
||||||
|
action="store",
|
||||||
|
type="str",
|
||||||
|
default=None,
|
||||||
|
dest="operation_policy_name",
|
||||||
|
help="Operation policy name for the secrets (e.g., 'default')"
|
||||||
|
)
|
||||||
|
|
||||||
elif operation is Operation.DESTROY:
|
elif operation is Operation.DESTROY:
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
"-i",
|
"-i",
|
||||||
|
@ -212,6 +231,15 @@ def build_cli_parser(operation=None):
|
||||||
help=("Type of the object to register. Supported types include: "
|
help=("Type of the object to register. Supported types include: "
|
||||||
"CERTIFICATE, PRIVATE_KEY, PUBLIC_KEY, SYMMETRIC_KEY, "
|
"CERTIFICATE, PRIVATE_KEY, PUBLIC_KEY, SYMMETRIC_KEY, "
|
||||||
"SECRET_DATA"))
|
"SECRET_DATA"))
|
||||||
|
parser.add_option(
|
||||||
|
"-o",
|
||||||
|
"--operation-policy-name",
|
||||||
|
action="store",
|
||||||
|
type="str",
|
||||||
|
default=None,
|
||||||
|
dest="operation_policy_name",
|
||||||
|
help="Operation policy name for the secret (e.g., 'default')"
|
||||||
|
)
|
||||||
elif operation is Operation.DISCOVER_VERSIONS:
|
elif operation is Operation.DISCOVER_VERSIONS:
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
"-v",
|
"-v",
|
||||||
|
|
Loading…
Reference in New Issue