登录
首页 >  Golang >  Go问答

如何在AWS CLI中打开浏览器,等待响应后继续执行?

来源:stackoverflow

时间:2024-02-08 14:32:26 405浏览 收藏

哈喽!大家好,很高兴又见面了,我是golang学习网的一名作者,今天由我给大家带来一篇《如何在AWS CLI中打开浏览器,等待响应后继续执行?》,本文主要会讲到等等知识点,希望大家一起学习进步,也欢迎大家关注、点赞、收藏、转发! 下面就一起来看看吧!

问题内容

我正在尝试为我的公司构建一个 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


正确答案


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

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
            }
        }

编辑:

运行 AWS sso login —debug 后,我注意到日志实际上在循环并一遍又一遍地运行 createToken 查询,因此 AWS 正在执行与上述类似的操作。

文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《如何在AWS CLI中打开浏览器,等待响应后继续执行?》文章吧,也可关注golang学习网公众号了解相关技术文章。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>