Code Monkey home page Code Monkey logo

csh_ldap's Introduction

csh_ldap

PyPI version Build Status

Python 3 ORM for CSH LDAP

Installation

pip install csh_ldap

Usage

import csh_ldap

# Create an unbatched instance
instance = csh_ldap.CSHLDAP(bind_dn, bind_pw)

# Create an batched instance
instance_batched = csh_ldap.CSHLDAP(bind_dn, bind_pw, batch_mods=True)

# Create a Read-Only instance that will only echo your changes
instance_ro = csh_ldap.CSHLDAP(bind_dn, bind_pw, ro=True)

# Get member by UUID
liam = instance.get_member(uuid_of_liam)

# Get member by UID
liam = instance.get_member(uid_of_liam, uid=True)

# Get member by iButton ID
liam = instance.get_member_ibutton(ibutton_id)

# Get member by Slack UID
liam = instance.get_member_slackuid(slack_uid)

# Get group by cn
rtp = instance.get_group('rtp')

# Get cn of member
print(liam.cn)

# Set cn of member
liam.cn = "Liam Middlebrook"

# Setting attributes to None removes them
liam.roomNumber = None

# Process batched writes per-dn
instance_batched.flush_mod()

# Get EBoard Directorship
# Directorships: ['chairman', 'evaluations', 'financial', 'history', 'imps', 'opcomm', 'research', 'social']
social = instance.get_directorship_heads('social')

for director in social:
    # Directorships are always lists, since it can be multiple people.
    print(director.cn)

csh_ldap's People

Contributors

adamhb123 avatar com6056 avatar dependabot[bot] avatar devinmatte avatar galenguyer avatar liam-middlebrook avatar mbillow avatar mfrancis95 avatar mxmeinhold avatar wasv avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

csh_ldap's Issues

Investigate SERVER_DOWN issue on bullseye

Something wonky happened between libldap 2.4.47 and 2.4.59 that causes bullseye's libldap 2.4.57 to give us SERVER_DOWN errors when attempting to connect:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/ldap/ldapobject.py", line 1196, in _apply_method_s
    return func(self,*args,**kwargs)
  File "/usr/local/lib/python3.9/site-packages/ldap/ldapobject.py", line 443, in simple_bind_s
    msgid = self.simple_bind(who,cred,serverctrls,clientctrls)
  File "/usr/local/lib/python3.9/site-packages/ldap/ldapobject.py", line 437, in simple_bind
    return self._ldap_call(self._l.simple_bind,who,cred,RequestControlTuples(serverctrls),RequestControlTuples(clientctrls))
  File "/usr/local/lib/python3.9/site-packages/ldap/ldapobject.py", line 329, in _ldap_call
    reraise(exc_type, exc_value, exc_traceback)
  File "/usr/local/lib/python3.9/site-packages/ldap/compat.py", line 44, in reraise
    raise exc_value
  File "/usr/local/lib/python3.9/site-packages/ldap/ldapobject.py", line 313, in _ldap_call
    result = func(*args,**kwargs)
ldap.SERVER_DOWN: {'desc': "Can't contact LDAP server", 'errno': 9, 'info': '(unknown error code)'}

This isn't great because we tend not to pin our container images to a particular release. We have a lot of things that have python:3.9.7 instead of python:3.9.7-buster. When these projects get rebuilt by OKD, stuff breaks because it can't talk to LDAP.

JSON/YAML Backed Spoofing of Servers

It would be useful for local development and for continuous integration for csh_ldap to be able to spoof server data. Once this is implemented applications (as well as csh_ldap) would be able to add automated testing for their csh_ldap usage.

I'm not sure how we'd want to structure the local spoof data, but at first thought JSON or YAML would probably be sufficient. As an argument to the CSHLDAP constructor we could just add a spoof_file named parameter that bypasses making a server connection.

__repr__ for Members (possibly Groups)

image

When working with groups or a collection of user objects, it would be helpful to be able to check which users you've actually got on hand just by yeeting them to stdout without much effort. A simple __repr__() that provides a user's uid or something else identifiable would be a nice QOL update. Something like <CSHMember [zach - "Zach Hart"]> might be nice.

Not sure what you'd put in the groups, maybe the group name and count of members in it.

Add custom exceptions

It would be useful for csh_ldap to expose more specific exceptions to applications in order to help differentiate issues for server-side permissions, versus invalid input to csh_ldap from the application.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.