summaryrefslogtreecommitdiff
path: root/src/leap/base/providers.py
blob: 1f6ab54b5c261d891b3767cd2b2ca86a1f762011 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""all dealing with leap-providers: definition files, updating"""
import configuration

from leap.base.config import JSONLeapConfig

##########################################################
# hacking in progress:

# Specs are instances of configuration.Configuration class
# -yeah, that's an external app, not ours-
# and have to carry an options attr.
#
# Configs have:
# - a slug (from where a filename/folder is derived)
# - a spec (for validation and defaults).

# all config objects, as BaseConfig derived, implment basic
# useful methods:
# - save
# - load
# - get_config (returns a optparse.OptionParser object)

# TODO:
# - have a good type cast repertory (uris, version, hashes...)
# - raise validation errors
# - multilingual objects

##########################################################


class LeapProviderSpec(configuration.Configuration):
    options = {
        'serial': {
            'type': int,
            'default': 1,
            'required': True,
        },
        'version': {
            'type': unicode,
            'default': '0.1.0'
            #'required': True
        },
        'domain': {
            'type': unicode,  # XXX define uri type
            'default': 'testprovider.example.org'
            #'required': True,
        },
        'display_name': {
            'type': unicode,  # XXX multilingual object?
            'default': 'test provider'
            #'required': True
        },
        'description': {
            'default': 'test provider'
        },
        'enrollment_policy': {
            'type': unicode,  # oneof ??
            'default': 'open'
        },
        'services': {
            'type': list,  # oneof ??
            'default': ['eip']
        },
        'api_version': {
            'type': unicode,
            'default': '0.1.0'  # version regexp
        },
        'api_uri': {
            'type': unicode  # uri
        },
        'public_key': {
            'type': unicode  # fingerprint
        },
        'ca_cert': {
            'type': unicode
        },
        'ca_cert_uri': {
            'type': unicode
        },
    }


class LeapProviderDefinition(JSONLeapConfig):
    slug = 'definition.json'
    spec = LeapProviderSpec


class LeapProvider(object):
    # bring slug here (property)
    # constructor: pass name

    # constructor: init definition class
    # (__cls__.__name__ + Definition)
    # initializes a JSONLeapConfig with slug and
    # initializes also cls.name + Spec

    # and Abstract this thing out!

    # how can we hook here the network fetching stuff?
    # maybe (bstorming a little bit):

    # config = LeapProviderDefinition
    # fetcher = foo.FetcherClass
    pass


class LeapProviderSet(object):
    # we gather them from the filesystem
    def __init__(self):
        self.count = 0