Add auth factory, expose driver on conn #108

Closed
freman wants to merge 1 commits from freman/goftp-server:master into master
First-time contributor

A possible solution to #106 that doesn't break backwards compatability.

Means I can define an auth factory that can check with the driver, or even have the auth method in the driver.

type driver struct {
	webdav *gowebdav.Client
}

// CheckPasswd will check user's password
func (d *driver) CheckPasswd(name, pass string) (bool, error) {
	c := gowebdav.NewClient("https://example.com/webdav", name, pass)
	if err := c.Connect(); err != nil {
		return false, err
	}
	d.webdav = c
	return true, nil
}

type authFactory struct{}

func (a *authFactory) NewAuth(c *server.Conn) (server.Auth, error) {
	if d, isa := c.Driver().(*driver); isa {
		return d, nil
	}
	return nil, errors.New("wrong type of driver")
}

only catch is I patched it to use the new 1.13 errors in go out of habit, please feel free to not do that

A possible solution to #106 that doesn't break backwards compatability. Means I can define an auth factory that can check with the driver, or even have the auth method in the driver. ``` type driver struct { webdav *gowebdav.Client } // CheckPasswd will check user's password func (d *driver) CheckPasswd(name, pass string) (bool, error) { c := gowebdav.NewClient("https://example.com/webdav", name, pass) if err := c.Connect(); err != nil { return false, err } d.webdav = c return true, nil } type authFactory struct{} func (a *authFactory) NewAuth(c *server.Conn) (server.Auth, error) { if d, isa := c.Driver().(*driver); isa { return d, nil } return nil, errors.New("wrong type of driver") } ``` only catch is I patched it to use the new 1.13 errors in go out of habit, please feel free to not do that
Author
First-time contributor

Hmmmm might need to add something like a

type Closer interface{
	Close()
}

and add a check in conn.Close()

func (conn *Conn) Close() {
	if c, isa := conn.driver.(Closer); isa {
		c.Close()
	}
	conn.conn.Close()
	conn.closed = true
	conn.reqUser = ""
	conn.user = ""
	if conn.dataConn != nil {
		conn.dataConn.Close()
		conn.dataConn = nil
	}
}
Hmmmm might need to add something like a ``` type Closer interface{ Close() } ``` and add a check in conn.Close() ``` func (conn *Conn) Close() { if c, isa := conn.driver.(Closer); isa { c.Close() } conn.conn.Close() conn.closed = true conn.reqUser = "" conn.user = "" if conn.dataConn != nil { conn.dataConn.Close() conn.dataConn = nil } } ```
lunny added this to the 0.4 milestone 2020-04-18 03:48:43 +00:00
lunny added the
feature
label 2020-04-18 03:49:13 +00:00
lunny modified the milestone from 0.4 to 0.6 2020-07-07 16:05:02 +00:00
Owner

#119 closed this.

https://gitea.com/goftp/server/pulls/119 closed this.
lunny closed this pull request 2020-12-01 06:21:04 +00:00
lunny removed this from the 0.6 milestone 2020-12-04 11:38:38 +00:00
Some checks are pending
continuous-integration/drone/pr Build is passing
checks / check and test (pull_request)
Required

Pull request closed

Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: goftp/server#108
No description provided.