AWS CLI 如何打开浏览器并等待响应然后再继续?

问题描述 投票:0回答:1

我正在尝试为我的公司构建一个 golang cli 工具,并将其作为构建登录和该工具的其他一些功能的一部分。我一生都无法弄清楚 AWS 如何能够打开浏览器窗口并等待单击几次按钮,然后再从 CLI 继续操作。

https://docs.aws.amazon.com/singlesignon/latest/OIDCAPIReference/API_StartDeviceAuthorization.html

这是我输入的 CLI 命令

aws sso login --profile login                                                                                                    

Attempting to automatically open the SSO authorization page in your default browser.
If the browser does not open or you wish to use a different device to authorize this request, open the following URL:

https://device.sso.us-east-1.amazonaws.com/

Then enter the code:

abcd-efgh
Successfully logged into Start URL: https://d-1421421423.awsapps.com/start

这里还有用于启动设备身份验证和创建令牌的 Python 文档

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sso-oidc/client/start_device_authorization.html https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sso-oidc/client/create_token.html

python go aws-sdk aws-cli aws-sdk-go
1个回答
0
投票

我刚刚组合在一起的一个似乎有效的选项是一个每分钟检查一次的循环

        for attempts <= 30 {
            fmt.Println(attempts)
            token, err := idc.CreateToken(context.TODO(), &createTokenInput)
            if err != nil {
                // if debug is enabled show error
                log.Debug(err.Error())
                attempts++
                // wait 1 second
                time.Sleep(1 * time.Second)
            } else {
                response = *token
                break
            }
        }
© www.soinside.com 2019 - 2024. All rights reserved.