Exemplo n.º 1
0
    def mutate(root, info, input_object):

        name = input_object.name
        credential_type = CredentialType.get(input_object.credential_type)

        comment = input_object.comment
        allow_insecure = input_object.allow_insecure

        certificate = input_object.certificate
        key_phrase = input_object.key_phrase
        private_key = input_object.private_key

        login = input_object.login
        password = input_object.password

        community = input_object.community

        if input_object.auth_algorithm is not None:
            auth_algorithm = AuthAlgorithm.get(input_object.auth_algorithm)
        else:
            auth_algorithm = None

        if input_object.privacy_algorithm is not None:
            privacy_algorithm = PrivacyAlgorithm.get(
                input_object.privacy_algorithm
            )
        else:
            privacy_algorithm = None

        privacy_password = input_object.privacy_password

        public_key = input_object.public_key

        gmp = get_gmp(info)

        resp = gmp.create_credential(
            name,
            credential_type,
            comment=comment,
            allow_insecure=allow_insecure,
            certificate=certificate,
            key_phrase=key_phrase,
            private_key=private_key,
            login=login,
            password=password,
            community=community,
            auth_algorithm=auth_algorithm,
            privacy_algorithm=privacy_algorithm,
            privacy_password=privacy_password,
            public_key=public_key,
        )
        return CreateCredential(credential_id=resp.get('id'))
Exemplo n.º 2
0
    def mutate(root, info, input_object):
        credential_id = str(input_object.credential_id)
        name = input_object.name

        comment = input_object.comment
        allow_insecure = input_object.allow_insecure

        certificate = input_object.certificate
        key_phrase = input_object.key_phrase
        private_key = input_object.private_key

        login = input_object.login
        password = input_object.password

        community = input_object.community

        if input_object.auth_algorithm is not None:
            auth_algorithm = AuthAlgorithm.get(input_object.auth_algorithm)
        else:
            auth_algorithm = None

        if input_object.privacy_algorithm is not None:
            privacy_algorithm = PrivacyAlgorithm.get(
                input_object.privacy_algorithm
            )
        else:
            privacy_algorithm = None

        privacy_password = input_object.privacy_password

        public_key = input_object.public_key

        gmp = get_gmp(info)

        gmp.modify_credential(
            credential_id,
            name=name,
            comment=comment,
            allow_insecure=allow_insecure,
            certificate=certificate,
            key_phrase=key_phrase,
            private_key=private_key,
            login=login,
            password=password,
            auth_algorithm=auth_algorithm,
            community=community,
            privacy_algorithm=privacy_algorithm,
            privacy_password=privacy_password,
            public_key=public_key,
        )
        return ModifyCredential(ok=True)
Exemplo n.º 3
0
class CreateCredentialInput(graphene.InputObjectType):
    """Input object for createCredential.

    Args:
        name (str): Name of the new credential
        credential_type (CredentialType): The credential type.
        comment (str, optional): Comment for the credential
        allow_insecure (bool, optional): Whether to allow insecure use of
            the credential
        certificate (str, optional): Certificate for the credential. Required
            for client-certificate and smime credential types.
        key_phrase (str, optional): Key passphrase for the private key. Used
            for the username+ssh-key credential type.
        private_key (str, optional): Private key to use for login. Required
            for usk credential type. Also used for the cc credential type.
            The supported key types (dsa, rsa, ecdsa, …) and formats
            (PEM, PKC#12, OpenSSL, …) depend on your installed GnuTLS version.
        login (str, optional): Username for the credential. Required for
            username+password, username+ssh-key and snmp credential type.
        password (str, optional): Password for the credential. Used for
            username+password and snmp credential types.
        community (str, optional): The SNMP community
        auth_algorithm (SnmpAuthAlgorithm, optional): The SNMP authentication
            algorithm. Required for snmp credential type.
        privacy_algorithm (SnmpPrivacyAlgorithm, optional): The SNMP privacy
            algorithm
        privacy_password (str, optional): The SNMP privacy
            password
        public_key (str, optional): PGP public key in armor plain text format.
            Required for pgp credential type.

    """

    name = graphene.String(required=True, description="Credential name.")
    credential_type = CredentialType(
        required=True, description="Credential type", name="type"
    )

    comment = graphene.String(description="Comment for the credential.")
    allow_insecure = graphene.Boolean(
        description="Whether to allow insecure use"
    )

    certificate = graphene.String(
        description=(
            "Certificate for the credential."
            "Required for client-certificate"
            "and smime credential types."
        )
    )
    key_phrase = graphene.String(
        description=(
            "Key passphrase for the private key. Used"
            "for the username+ssh-key credential type."
        )
    )
    private_key = graphene.String(
        description=(
            "Private key to use for login. Required"
            "for usk credential type. Also used for"
            "the cc credential type."
        )
    )

    login = graphene.String(
        description=(
            "Username for the credential. Required for"
            "username+password, username+ssh-key and"
            "snmp credential type."
        )
    )
    password = graphene.String(
        description=(
            "Password for the credential. Used for"
            "username+password and snmp credential types."
        )
    )

    community = graphene.String(description="SNMP community")
    auth_algorithm = AuthAlgorithm(
        description=(
            "The SNMP authentication algorithm."
            "Required for snmp credential type."
        )
    )
    privacy_algorithm = PrivacyAlgorithm(description="SNMP privacy algorithm")
    privacy_password = graphene.String(description="SNMP privacy password")

    public_key = graphene.String(
        description=(
            "PGP public key in armor plain text format."
            "Required for pgp credential type."
        )
    )