<commit_before>from seedbox import pki
from .db import db


# TODO: allow user to belong to more then one cluster (https://kubernetes.io/docs/user-guide/kubeconfig-file/)
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    cluster_id = db.Column(db.Integer, db.ForeignKey('cluster.id'), nullable=False)
    cluster = db.relationship('Cluster', backref=db.backref('users', lazy='dynamic'))
    name = db.Column(db.String(80), nullable=False)  # TODO: unique together with cluster_id
    credentials_id = db.Column(db.Integer, db.ForeignKey('credentials_data.id'), nullable=False)
    credentials = db.relationship('CredentialsData')
    groups = db.Column(db.String(255), nullable=False)      # TODO: rename to k8s_groups
    ssh_key = db.Column(db.Text, nullable=False)

    def __repr__(self):
        return '<User %r>' % self.name

    def __str__(self):
        return self.name

    @property
    def credentials_error(self):
        try:
            pki.verify_certificate_chain(self.cluster.ca_credentials.cert, self.credentials.cert)
            pki.validate_certificate_common_name(self.credentials.cert, self.name)
            if self.groups:
                pki.validate_certificate_organizations(self.credentials.cert, self.groups.split(','))
            pki.validate_certificate_key_usage(self.credentials.cert, is_web_server=False, is_web_client=True)
        except pki.InvalidCertificate as e:
            return str(e)<commit_msg>fix user model<commit_after>from seedbox import pki
from .db import db


# TODO: allow user to belong to more then one cluster (https://kubernetes.io/docs/user-guide/kubeconfig-file/)
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    cluster_id = db.Column(db.Integer, db.ForeignKey('cluster.id'), nullable=False)
    cluster = db.relationship('Cluster', backref=db.backref('users', lazy='dynamic'))
    name = db.Column(db.String(80), nullable=False)  # TODO: unique together with cluster_id
    credentials_id = db.Column(db.Integer, db.ForeignKey('credentials_data.id'), nullable=False)
    credentials = db.relationship('CredentialsData')
    groups = db.Column(db.String(255), nullable=False, default='')      # TODO: rename to k8s_groups
    ssh_key = db.Column(db.Text, nullable=False, default='')

    def __repr__(self):
        return '<User %r>' % self.name

    def __str__(self):
        return self.name

    @property
    def credentials_error(self):
        try:
            pki.verify_certificate_chain(self.cluster.ca_credentials.cert, self.credentials.cert)
            pki.validate_certificate_common_name(self.credentials.cert, self.name)
            if self.groups:
                pki.validate_certificate_organizations(self.credentials.cert, self.groups.split(','))
            pki.validate_certificate_key_usage(self.credentials.cert, is_web_server=False, is_web_client=True)
        except pki.InvalidCertificate as e:
            return str(e)
{'fraction_non_alphanumeric': 0.11871838111298483, 'fraction_numerical': 0.004047217537942664, 'mean_word_length': 3.6416275430359937, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7190765', 'n_tokens_mistral': 933, 'n_tokens_neox': 909, 'n_words': 177}