Skip to content

Commit

Permalink
fix: modify jupyter's authority from hash password to token string (#762
Browse files Browse the repository at this point in the history
)

Signed-off-by: zhenguo.li <zhenguo.li@shopee.com>

Signed-off-by: zhenguo.li <zhenguo.li@shopee.com>
Co-authored-by: zhenguo.li <zhenguo.li@shopee.com>
  • Loading branch information
Xiaoaier-Z-L and zhenguo.li committed Aug 11, 2022
1 parent 1f0af98 commit b4a8519
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def build():
"numpy",
])
shell("zsh")
config.jupyter(password="")
config.jupyter(token="")
```

You can get the endpoint of the running Jupyter notebook via `envd envs ls`.
Expand Down
4 changes: 2 additions & 2 deletions envd/api/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def apt_source(mode: Optional[str], source: Optional[str]):
pass


def jupyter(password: str, port: int):
def jupyter(token: str, port: int):
"""
Configure jupyter notebook configuration
Args:
password (str): Password for access authentication
token (str): Token for access authentication
port (int): Port to serve jupyter notebook
"""
pass
Expand Down
2 changes: 1 addition & 1 deletion examples/mnist/build.envd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def build():
"numpy",
])
shell("zsh")
config.jupyter(password="", port=8888)
config.jupyter(token="", port=8888)

def build_gpu():
build()
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/template/python.envd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def build():
# Use ubuntu20.04 as base image and install python
base(os="ubuntu20.04", language="python3")
# Uncomment line below to enable Pypi mirror
# Uncomment line below to enable Pypi mirror
# config.pip_index(url = "https://pypi.tuna.tsinghua.edu.cn/simple")

# Add the packages you are using here
Expand All @@ -11,4 +11,4 @@ def build():
shell("zsh")

# Setup jupyter notebook
config.jupyter(password="", port=8888)
config.jupyter(token="", port=8888)
6 changes: 3 additions & 3 deletions pkg/lang/frontend/starlark/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ func ruleFuncGPU(thread *starlark.Thread, _ *starlark.Builtin,

func ruleFuncJupyter(thread *starlark.Thread, _ *starlark.Builtin,
args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var password starlark.String
var token starlark.String
var port starlark.Int

if err := starlark.UnpackArgs(ruleJupyter, args, kwargs,
"password?", &password, "port?", &port); err != nil {
"token?", &token, "port?", &port); err != nil {
return nil, err
}

pwdStr := password.GoString()
pwdStr := token.GoString()

portInt, ok := port.Int64()
if !ok {
Expand Down
9 changes: 4 additions & 5 deletions pkg/lang/ir/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ func (g Graph) generateJupyterCommand(workingDir string) []string {
"--ip", "0.0.0.0", "--notebook-dir", workingDir,
}

if g.JupyterConfig.Password != "" {
cmd = append(cmd, "--NotebookApp.password", g.JupyterConfig.Password,
"--NotebookApp.token", "''")
if g.JupyterConfig.Token != "" {
cmd = append(cmd, "--NotebookApp.token", g.JupyterConfig.Token)
} else {
cmd = append(cmd, "--NotebookApp.password", "''",
"--NotebookApp.token", "''")
cmd = append(cmd, "--NotebookApp.token", "''")
}

if g.JupyterConfig.Port != 0 {
p := strconv.Itoa(int(config.JupyterPortInContainer))
cmd = append(cmd, "--port", p)
Expand Down
14 changes: 6 additions & 8 deletions pkg/lang/ir/editor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,27 @@ func TestGenerateCommand(t *testing.T) {
{
graph: Graph{
JupyterConfig: &JupyterConfig{
Password: "",
Port: 8888,
Token: "",
Port: 8888,
},
},
dir: "test",
expected: []string{
"python3", "-m", "notebook", "--ip", "0.0.0.0", "--notebook-dir", "test",
"--NotebookApp.password", "''", "--NotebookApp.token", "''",
"--port", "8888",
"--NotebookApp.token", "''", "--port", "8888",
},
},
{
graph: Graph{
JupyterConfig: &JupyterConfig{
Password: "test",
Port: 8888,
Token: "test",
Port: 8888,
},
},
dir: "test",
expected: []string{
"python3", "-m", "notebook", "--ip", "0.0.0.0", "--notebook-dir", "test",
"--NotebookApp.password", "test", "--NotebookApp.token", "''",
"--port", "8888",
"--NotebookApp.token", "test", "--port", "8888",
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions pkg/lang/ir/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func Shell(shell string) error {

func Jupyter(pwd string, port int64) error {
DefaultGraph.JupyterConfig = &JupyterConfig{
Password: pwd,
Port: port,
Token: pwd,
Port: port,
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/lang/ir/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ type GitConfig struct {
}

type JupyterConfig struct {
Password string
Port int64
Token string
Port int64
}

const (
Expand Down

0 comments on commit b4a8519

Please sign in to comment.