netrc-0.2.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 tolerated. Comments are currently only allowed before, between, and after machine/default/macdef entries. Be aware though that such #-comment are not supported by all .netrc-aware applications, including ftp(1).

Synopsis

Types

data NetRc Source

Represents (semantic) contents of a .netrc file

Constructors

NetRc 

Fields

nrHosts :: [NetRcHost]

machine/default entries

Note: If it exists, the default entry ought to be the last entry, otherwise it can cause later entries to become invisible for some implementations (e.g. ftp(1))

nrMacros :: [NetRcMacDef]

Non-associated macdef entries

Note: macdef entries not associated with host-entries are invisible to some applications (e.g. ftp(1)).

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)

nrhMacros :: [NetRcMacDef]

associated macdef entries

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, i.e. consecutive LFs

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