@@ -21,7 +21,7 @@ class WebHDFS(AbstractFileSystem):
21
21
"""
22
22
Interface to HDFS over HTTP using the WebHDFS API. Supports also HttpFS gateways.
23
23
24
- Three auth mechanisms are supported:
24
+ Four auth mechanisms are supported:
25
25
26
26
insecure: no auth is done, and the user is assumed to be whoever they
27
27
say they are (parameter ``user``), or a predefined value such as
@@ -34,6 +34,8 @@ class WebHDFS(AbstractFileSystem):
34
34
service. Indeed, this client can also generate such tokens when
35
35
not insecure. Note that tokens expire, but can be renewed (by a
36
36
previously specified user) and may allow for proxying.
37
+ basic-auth: used when both parameter ``user`` and parameter ``password``
38
+ are provided.
37
39
38
40
"""
39
41
@@ -47,6 +49,7 @@ def __init__(
47
49
kerberos = False ,
48
50
token = None ,
49
51
user = None ,
52
+ password = None ,
50
53
proxy_to = None ,
51
54
kerb_kwargs = None ,
52
55
data_proxy = None ,
@@ -68,6 +71,9 @@ def __init__(
68
71
given
69
72
user: str or None
70
73
If given, assert the user name to connect with
74
+ password: str or None
75
+ If given, assert the password to use for basic auth. If password
76
+ is provided, user must be provided also
71
77
proxy_to: str or None
72
78
If given, the user has the authority to proxy, and this value is
73
79
the user in who's name actions are taken
@@ -102,8 +108,19 @@ def __init__(
102
108
" token"
103
109
)
104
110
self .pars ["delegation" ] = token
105
- if user is not None :
106
- self .pars ["user.name" ] = user
111
+ self .user = user
112
+ self .password = password
113
+
114
+ if password is not None :
115
+ if user is None :
116
+ raise ValueError (
117
+ "If passing a password, the user must also be"
118
+ "set in order to set up the basic-auth"
119
+ )
120
+ else :
121
+ if user is not None :
122
+ self .pars ["user.name" ] = user
123
+
107
124
if proxy_to is not None :
108
125
self .pars ["doas" ] = proxy_to
109
126
if kerberos and user is not None :
@@ -126,8 +143,13 @@ def _connect(self):
126
143
127
144
self .session .auth = HTTPKerberosAuth (** self .kerb_kwargs )
128
145
146
+ if self .user is not None and self .password is not None :
147
+ from requests .auth import HTTPBasicAuth
148
+
149
+ self .session .auth = HTTPBasicAuth (self .user , self .password )
150
+
129
151
def _call (self , op , method = "get" , path = None , data = None , redirect = True , ** kwargs ):
130
- url = self .url + quote (path or "" )
152
+ url = self ._apply_proxy ( self . url + quote (path or "" ) )
131
153
args = kwargs .copy ()
132
154
args .update (self .pars )
133
155
args ["op" ] = op .upper ()
0 commit comments