summaryrefslogtreecommitdiffstats
path: root/examples/fileparsing
blob: f9766b9f6cb58991073e028e645d204d2b7857a3 (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
111
112
113
114
115
116
# $Id$

# this will eventually parse different config files

# this creates the 'passwd' type, but it does not create any instances
filetype { "passwd":
    linesplit => "\n",
    escapednewlines => false
}


# this creates the 'PasswdUser' type, but again, no instances
filerecord { "user":
    filetype => passwd,
    fields => [name, password, uid, gid, gcos, home, shell],
    namevar => name,
    splitchar => ":"

}

filetype { ini:
    linesplit => "\n\n"
}

# ini files are different because we don't really care about validating fields
# or at least, we can't do it for most files...
filerecord { "initrecord":
    filetype => ini,
    fields => [name, password, uid, gid, gcos, home, shell],
    namevar => name,
    splitchar => ":"

}

# this won't work for multiple record types, will it?
# or at least, it requires that we specify multiple times
# ah, and it doesn't specify which of the available record types
# it works for...
passwd { user:
    complete => true, # manage the whole file
    path => "/etc/passwd"
}

user { yaytest:
    password => x,
    uid => 10000,
    gid => 10000,
    home => "/home/yaytest",
    gcos => "The Yaytest",
    shell => "/bin/sh"
}
    # there seems to be an intrinsic problem here -- i've got subtypes that only
    # make sense when an instance of the super type already exists, and i need
    # to associate the instances of the subtype with the instances of the supertype
    # even if i created the parsers manually, I'd have the same problem

# this is the crux of it -- i want to be able to say 'user' here without having
# to specify the file, which leaves two options:
#   1) associate the record type with a filetype instance (BAD)
#   2) once the filetype and record type are created, have another command
#       that specifically creates a filetype instance and gives names for instances
#       of its record types

define syslog {

    # create a new type, with all defaults
    filetype { "syslog":
        escapednewlines => true
    }

    filerecord { "log":
        filetype => syslog,
        regex => "^([^#\s]+)\s+(\S+)$",
        joinchar => "\t",
        fields => [logs, dest]
    }

    # these two should just be supported within the filetypes
    filerecord { "comment":
        filetype => syslog,
        regex => "^(#.*)$",
        joinchar => "s",
        fields => [comment]
    }

    filerecord { "blank":
        filetype => syslog,
        regex => "^(\s*)$",
        joinchar => "s",
        fields => blank
    }
}

define cron {
    filetype { "usercrontab":
    }

    # this won't actually work, of course
    filerecord { "cronjob":
        filetype => crontab,
        regex => "^([^#\s]+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.+)$",
        joinchar => " ",
        fields => [minute, hour, day, month, weekday, command],
        defaults => ["*", "*", "*", "*", "*", nil],
        optional => [minute, hour, day, month, weekday]
    }

    crontab { "luke":
    }
}

# XXX this doesn't work in the slightest
define crontab(name,path) {
    usercrontab { "${path}/${name}":
    }
}