// Retrieve a username and password from a .netrc-formatted file.
Retrieve a username and password from a .netrc-formatted file.
// Retrieve a username and password from a . netrc - formatted file .
func (self *Commands) Netrc(machine string, args *NetrcArgs) (*NetrcResponse, error) {
	if args == nil {
		args = &NetrcArgs{}
	}
	defaults.SetDefaults(args)
	if expanded, err := pathutil.ExpandUser(args.Filename); err == nil {
		if nrc, err := netrc.Parse(expanded); err == nil {
			response := &NetrcResponse{
				Machine: machine,
			}
			if entry := nrc.Machine(machine); entry != nil {
				response.OK = true
				response.Login = entry.Get(`login`)
				response.Password = entry.Get(`password`)
				if len(args.ExtraFields) > 0 {
					response.Fields = make(map[string]string)
					for _, field := range args.ExtraFields {
						if field == `login` || field == `password` {
							continue
						} else {
							response.Fields[field] = entry.Get(field)
						}
					}
				}
			}
			return response, nil
		} else {
			return nil, err
		}
	} else {
		return nil, err
	}
}
func ( self * Commands ) Netrc ( machine string , args * NetrcArgs ) ( * NetrcResponse , error ) { if args == nil { args = & NetrcArgs { } } defaults . SetDefaults ( args ) if expanded , err := pathutil . ExpandUser ( args . Filename ) ; err == nil { if nrc , err := netrc . Parse ( expanded ) ; err == nil { response := & NetrcResponse { Machine : machine , } if entry := nrc . Machine ( machine ) ; entry != nil { response . OK = true response . Login = entry . Get ( `login` ) response . Password = entry . Get ( `password` ) if len ( args . ExtraFields ) > 0 { response . Fields = make ( map [ string ] string ) for _ , field := range args . ExtraFields { if field == `login` || field == `password` { continue } else { response . Fields [ field ] = entry . Get ( field ) } } } } return response , nil } else { return nil , err } } else { return nil , err } }
Retrieve a username and password from a .netrc-formatted file.
Retrieve a username and password from a . netrc - formatted file .
// retrieve and populate the machine-specific entry (if present)