netrc-0.1.0.0: Parser for .netrc files

Safe HaskellSafe-Inferred
LanguageHaskell2010

Network.NetRc

Contents

Description

Provides parser for $HOME/.netrc files

The implemented grammar is approximately:

NETRC := (WS|<comment>)* (ENTRY (WS+ <comment>*)+)* ENTRY?

ENTRY := 'machine' WS+ <value> WS+ ((account|username|password) WS+ <value>)*
       | 'default' WS+ (('account'|'username'|'password') WS+ <value>)*
       | 'macdef' <value> LF (<line> LF)* LF

WS := (LF|SPC|TAB)

<line>  := !LF+
<value> := !WS+
<comment> := '#' !LF* LF

As an extension to the .netrc-format as described in .e.g. netrc(5), #-style comments are supported. For simplicity, such comments are only allowed between entries.

Synopsis

Types

data NetRc Source

Represents (semantic) contents of a .netrc file

Constructors

NetRc [NetRcHost] [NetRcMacDef] 

data NetRcHost Source

machine and default entries describe remote accounts

Invariant: fields must not contain any TABs, SPACE, or LFs.

Constructors

NetRcHost 

Fields

nrhName :: !ByteString

Remote machine name ("" for default-entries)

nrhLogin :: !ByteString

login property ("" if missing)

nrhPassword :: !ByteString

password property ("" if missing)

nrhAccount :: !ByteString

account property ("" if missing)

data NetRcMacDef Source

macdef entries defining ftp macros

Constructors

NetRcMacDef 

Fields

nrmName :: !ByteString

Name of macdef entry (Invariant: must not contain any TABs, SPACE, or LFs)

nrmBody :: !ByteString

Raw macdef body (Invariant: must not contain null-lines)

Formatters

netRcToByteString :: NetRc -> ByteString Source

Format NetRc into a ByteString

This is currently just a convenience wrapper around netRcToBuilder

Parsers

parseNetRc :: SourceName -> ByteString -> Either ParseError NetRc Source

Convenience wrapper for netRcParsec parser

This is basically just

parseNetRc = parse (netRcParsec <* eof)

This wrapper is mostly useful for avoiding to have to import Parsec modules (and to build-depend explicitly on parsec).

Utilities

readUserNetRc :: IO (Maybe (Either ParseError NetRc)) Source

Reads and parses default $HOME/.netrc

Returns Nothing if $HOME variable undefined and/or if .netrc if missing. Throws standard IO exceptions in case of other filesystem-errors.

Note: This function performs no permission sanity-checking on the .netrc file