Skip to content

Commit

Permalink
Add GeneratorRecipe.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdb committed Jul 24, 2022
1 parent e57fcde commit 93cc190
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 3 deletions.
14 changes: 12 additions & 2 deletions example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time

import onepasswordconnectsdk
from onepasswordconnectsdk.models import (ItemVault, Field)
from onepasswordconnectsdk.models import (ItemVault, Field, GeneratorRecipe)

op_connect_token = os.environ["OP_CONNECT_TOKEN"]
default_vault = os.environ["OP_VAULT"]
Expand All @@ -21,7 +21,17 @@
title="Secret String",
category="LOGIN",
tags=["1password-connect"],
fields=[Field(value=secret_string)])
fields=[
Field(
value=secret_string
),
Field(
purpose="PASSWORD",
generate=True,
recipe=GeneratorRecipe(length=10, character_sets=['LETTERS'])
)
]
)
print(steps.steps["step2"])

# ADD THE ITEM TO THE 1P VAULT
Expand Down
1 change: 1 addition & 0 deletions src/onepasswordconnectsdk/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from onepasswordconnectsdk.models.field import Field
from onepasswordconnectsdk.models.field_section import FieldSection
from onepasswordconnectsdk.models.file import File
from onepasswordconnectsdk.models.generator_recipe import GeneratorRecipe
from onepasswordconnectsdk.models.section import Section
from onepasswordconnectsdk.models.summary_item import SummaryItem
from onepasswordconnectsdk.models.item_urls import ItemUrls
Expand Down
28 changes: 27 additions & 1 deletion src/onepasswordconnectsdk/models/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Field(object):
'label': 'str',
'value': 'str',
'generate': 'bool',
'recipe': 'GeneratorRecipe',
'entropy': 'float',
'totp': 'str'
}
Expand All @@ -50,18 +51,20 @@ class Field(object):
'label': 'label',
'value': 'value',
'generate': 'generate',
'recipe': 'recipe',
'entropy': 'entropy',
'totp': 'totp'
}

def __init__(self, id=None, section=None, type='STRING', purpose=None, label=None, value=None, generate=False, entropy=None, totp=None): # noqa: E501
def __init__(self, id=None, section=None, type='STRING', purpose=None, label=None, value=None, generate=False, recipe=None, entropy=None, totp=None): # noqa: E501
self._id = None
self._section = None
self._type = None
self._purpose = None
self._label = None
self._value = None
self._generate = None
self._recipe = None
self._entropy = None
self._totp = None
self.discriminator = None
Expand All @@ -79,6 +82,8 @@ def __init__(self, id=None, section=None, type='STRING', purpose=None, label=Non
self.value = value
if generate is not None:
self.generate = generate
if recipe is not None:
self.recipe = recipe
if entropy is not None:
self.entropy = entropy
if totp is not None:
Expand Down Expand Up @@ -247,6 +252,27 @@ def generate(self, generate):

self._generate = generate

@property
def recipe(self):
"""Gets the recipe of this Field. # noqa: E501
:return: The recipe of this Field. # noqa: E501
:rtype: GeneratorRecipe
"""
return self._recipe

@recipe.setter
def recipe(self, recipe):
"""Sets the recipe of this Field.
:param recipe: The recipe of this Field. # noqa: E501
:type: GeneratorRecipe
"""

self._recipe = recipe

@property
def entropy(self):
"""Gets the entropy of this Field. # noqa: E501
Expand Down
165 changes: 165 additions & 0 deletions src/onepasswordconnectsdk/models/generator_recipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# coding: utf-8

"""
1Password Connect
REST API interface for 1Password Connect. # noqa: E501
The version of the OpenAPI document: 1.3.0
Contact: [email protected]
Generated by: https://openapi-generator.tech
"""


try:
from inspect import getfullargspec
except ImportError:
from inspect import getargspec as getfullargspec
import pprint
import re # noqa: F401
import six

class GeneratorRecipe(object):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""

"""
Attributes:
openapi_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
openapi_types = {
'length': 'int',
'character_sets': 'list[str]'
}

attribute_map = {
'length': 'length',
'character_sets': 'characterSets'
}

def __init__(self, length=32, character_sets=None, local_vars_configuration=None): # noqa: E501
"""GeneratorRecipe - a model defined in OpenAPI""" # noqa: E501

self._length = None
self._character_sets = None
self.discriminator = None

if length is not None:
self.length = length
if character_sets is not None:
self.character_sets = character_sets

@property
def length(self):
"""Gets the length of this GeneratorRecipe. # noqa: E501
Length of the generated value # noqa: E501
:return: The length of this GeneratorRecipe. # noqa: E501
:rtype: int
"""
return self._length

@length.setter
def length(self, length):
"""Sets the length of this GeneratorRecipe.
Length of the generated value # noqa: E501
:param length: The length of this GeneratorRecipe. # noqa: E501
:type length: int
"""
if (length is not None and length > 64): # noqa: E501
raise ValueError("Invalid value for `length`, must be a value less than or equal to `64`") # noqa: E501
if (length is not None and length < 1): # noqa: E501
raise ValueError("Invalid value for `length`, must be a value greater than or equal to `1`") # noqa: E501

self._length = length

@property
def character_sets(self):
"""Gets the character_sets of this GeneratorRecipe. # noqa: E501
:return: The character_sets of this GeneratorRecipe. # noqa: E501
:rtype: list[str]
"""
return self._character_sets

@character_sets.setter
def character_sets(self, character_sets):
"""Sets the character_sets of this GeneratorRecipe.
:param character_sets: The character_sets of this GeneratorRecipe. # noqa: E501
:type character_sets: list[str]
"""
allowed_values = ["LETTERS", "DIGITS", "SYMBOLS"] # noqa: E501
if (not set(character_sets).issubset(set(allowed_values))): # noqa: E501
raise ValueError(
"Invalid values for `character_sets` [{0}], must be a subset of [{1}]" # noqa: E501
.format(", ".join(map(str, set(character_sets) - set(allowed_values))), # noqa: E501
", ".join(map(str, allowed_values)))
)

self._character_sets = character_sets

def to_dict(self, serialize=False):
"""Returns the model properties as a dict"""
result = {}

def convert(x):
if hasattr(x, "to_dict"):
args = getfullargspec(x.to_dict).args
if len(args) == 1:
return x.to_dict()
else:
return x.to_dict(serialize)
else:
return x

for attr, _ in six.iteritems(self.openapi_types):
value = getattr(self, attr)
attr = self.attribute_map.get(attr, attr) if serialize else attr
if isinstance(value, list):
result[attr] = list(map(
lambda x: convert(x),
value
))
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], convert(item[1])),
value.items()
))
else:
result[attr] = convert(value)

return result

def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())

def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()

def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, GeneratorRecipe):
return False

return self.to_dict() == other.to_dict()

def __ne__(self, other):
"""Returns true if both objects are not equal"""
if not isinstance(other, GeneratorRecipe):
return True

return self.to_dict() != other.to_dict()

1 comment on commit 93cc190

@French-Guy007
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.