@@ -6,8 +6,19 @@ Base type which defines location and version for MLFlow API service.
6
6
# Fields
7
7
- `apiroot::String`: API root URL, e.g. `http://localhost:5000/api`
8
8
- `apiversion::Union{Integer, AbstractFloat}`: used API version, e.g. `2.0`
9
- - `headers::Dict`: HTTP headers to be provided with the REST API requests (useful for
10
- authetication tokens) Default is `false`, using the REST API endpoint.
9
+ - `headers::Dict`: HTTP headers to be provided with the REST API requests.
10
+ - `username::Union{Nothing, String}`: username for basic authentication.
11
+ - `password::Union{Nothing, String}`: password for basic authentication.
12
+
13
+ !!! warning
14
+ You cannot provide an `Authorization` header when an `username` and `password` are
15
+ provided. An error will be thrown in that case.
16
+
17
+ !!! note
18
+ - If `MLFLOW_TRACKING_URI` is set, the provided `apiroot` will be ignored.
19
+ - If `MLFLOW_TRACKING_USERNAME` is set, the provided `username` will be ignored.
20
+ - If `MLFLOW_TRACKING_PASSWORD` is set, the provided `password` will be ignored.
21
+ These indications will be displayed as warnings.
11
22
12
23
# Examples
13
24
@@ -19,17 +30,49 @@ mlf = MLFlow()
19
30
remote_url="https://<your-server>.cloud.databricks.com"; # address of your remote server
20
31
mlf = MLFlow(remote_url, headers=Dict("Authorization" => "Bearer <your-secret-token>"))
21
32
```
22
-
23
33
"""
24
34
struct MLFlow
25
35
apiroot:: String
26
36
apiversion:: AbstractFloat
27
37
headers:: Dict
38
+ username:: Union{Nothing,String}
39
+ password:: Union{Nothing,String}
40
+
41
+ function MLFlow (apiroot, apiversion, headers, username, password)
42
+ if haskey (ENV , " MLFLOW_TRACKING_URI" )
43
+ @warn " The provided apiroot will be ignored as MLFLOW_TRACKING_URI is set."
44
+ apiroot = ENV [" MLFLOW_TRACKING_URI" ]
45
+ end
46
+
47
+ if haskey (ENV , " MLFLOW_TRACKING_USERNAME" )
48
+ @warn " The provided username will be ignored as MLFLOW_TRACKING_USERNAME is set."
49
+ username = ENV [" MLFLOW_TRACKING_USERNAME" ]
50
+ end
51
+
52
+ if haskey (ENV , " MLFLOW_TRACKING_PASSWORD" )
53
+ @warn " The provided password will be ignored as MLFLOW_TRACKING_PASSWORD is set."
54
+ password = ENV [" MLFLOW_TRACKING_PASSWORD" ]
55
+ end
56
+
57
+ if username |> ! isnothing && password |> ! isnothing
58
+ if haskey (headers, " Authorization" )
59
+ error (" You cannot provide an Authorization header when an username and password are provided." )
60
+ end
61
+ encoded_credentials = Base64. base64encode (" $(username) :$(password) " )
62
+ headers =
63
+ merge (headers, Dict (" Authorization" => " Basic $(encoded_credentials) " ))
64
+ end
65
+ new (apiroot, apiversion, headers, username, password)
66
+ end
28
67
end
29
- MLFlow (apiroot; apiversion= 2.0 , headers= Dict ()) = MLFlow (apiroot, apiversion, headers)
30
- MLFlow (; apiroot= " http://localhost:5000/api" , apiversion= 2.0 , headers= Dict ()) =
31
- MLFlow ((haskey (ENV , " MLFLOW_TRACKING_URI" ) ?
32
- ENV [" MLFLOW_TRACKING_URI" ] : apiroot), apiversion, headers)
68
+ MLFlow (apiroot:: String ; apiversion:: AbstractFloat = 2.0 , headers:: Dict = Dict (),
69
+ username:: Union{Nothing,String} = nothing ,
70
+ password:: Union{Nothing,String} = nothing ):: MLFlow =
71
+ MLFlow (apiroot, apiversion, headers, username, password)
72
+ MLFlow (; apiroot:: String = " http://localhost:5000/api" , apiversion:: AbstractFloat = 2.0 ,
73
+ headers:: Dict = Dict (), username:: Union{Nothing,String} = nothing ,
74
+ password:: Union{Nothing,String} = nothing ):: MLFlow =
75
+ MLFlow (apiroot, apiversion, headers, username, password)
33
76
34
77
Base. show (io:: IO , t:: MLFlow ) =
35
78
show (io, ShowCase (t, [:apiroot , :apiversion ], new_lines= true ))
0 commit comments