Skip to content

Commit

Permalink
feat: support RoleSessionExpiration for OIDCCredential
Browse files Browse the repository at this point in the history
  • Loading branch information
yndu13 committed Nov 17, 2023
1 parent f9ce06a commit 0f50690
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions credentials/oidc_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"os"
"strconv"
"time"

"github.com/alibabacloud-go/tea/tea"
Expand Down Expand Up @@ -154,6 +155,9 @@ func (r *OIDCCredential) updateCredential() (err error) {
if r.Policy != "" {
request.QueryParams["Policy"] = r.Policy
}
if r.RoleSessionExpiration > 0 {
request.QueryParams["DurationSeconds"] = strconv.Itoa(r.RoleSessionExpiration)
}
request.QueryParams["RoleSessionName"] = r.RoleSessionName
request.QueryParams["Version"] = "2015-04-01"
request.QueryParams["SignatureNonce"] = utils.GetUUID()
Expand Down
3 changes: 2 additions & 1 deletion credentials/oidc_credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ func Test_oidcCredential_updateCredential(t *testing.T) {
assert.Equal(t, 1027, len(*token))
assert.Equal(t, "test_long_oidc_token_eyJhbGciOiJSUzI1NiIsImtpZCI6ImFQaXlpNEVGSU8wWnlGcFh1V0psQUNWbklZVlJsUkNmM2tlSzNMUlhWT1UifQ.eyJhdWQiOlsic3RzLmFsaXl1bmNzLmNvbSJdLCJleHAiOjE2NDUxMTk3ODAsImlhdCI6MTY0NTA4Mzc4MCwiaXNzIjoiaHR0cHM6Ly9vaWRjLWFjay1jbi1oYW5nemhvdS5vc3MtY24taGFuZ3pob3UtaW50ZXJuYWwuYWxpeXVuY3MuY29tL2NmMWQ4ZGIwMjM0ZDk0YzEyOGFiZDM3MTc4NWJjOWQxNSIsImt1YmVybmV0ZXMuaW8iOnsibmFtZXNwYWNlIjoidGVzdC1ycnNhIiwicG9kIjp7Im5hbWUiOiJydW4tYXMtcm9vdCIsInVpZCI6ImIzMGI0MGY2LWNiZTAtNGY0Yy1hZGYyLWM1OGQ4ZmExZTAxMCJ9LCJzZXJ2aWNlYWNjb3VudCI6eyJuYW1lIjoidXNlcjEiLCJ1aWQiOiJiZTEyMzdjYS01MTY4LTQyMzYtYWUyMC00NDM1YjhmMGI4YzAifX0sIm5iZiI6MTY0NTA4Mzc4MCwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50OnRlc3QtcnJzYTp1c2VyMSJ9.XGP-wgLj-iMiAHjLe0lZLh7y48Qsj9HzsEbNh706WwerBoxnssdsyGFb9lzd2FyM8CssbAOCstr7OuAMWNdJmDZgpiOGGSbQ-KXXmbfnIS4ix-V3pQF6LVBFr7xJlj20J6YY89um3rv_04t0iCGxKWs2ZMUyU1FbZpIPRep24LVKbUz1saiiVGgDBTIZdHA13Z-jUvYAnsxK_Kj5tc1K-IuQQU0IwSKJh5OShMcdPugMV5LwTL3ogCikfB7yljq5vclBhCeF2lXLIibvwF711TOhuJ5lMlh-a2KkIgwBHhANg_U9k4Mt_VadctfUGc4hxlSbBD0w9o9mDGKwgGmW5Q", *token)

oidcCredential = newOIDCRoleArnCredential("accessKeyId", "accessKeySecret", "RoleArn", "OIDCProviderArn", "tokenFilePath", "roleSessionName", "Policy", 3600, &utils.Runtime{STSEndpoint: "www.aliyun.com"})
oidcCredential = newOIDCRoleArnCredential("accessKeyId", "accessKeySecret", "RoleArn", "OIDCProviderArn", "tokenFilePath", "roleSessionName", "Policy", 7200, &utils.Runtime{STSEndpoint: "www.aliyun.com"})
hookDo = func(fn func(req *http.Request) (*http.Response, error)) func(req *http.Request) (*http.Response, error) {
return func(req *http.Request) (*http.Response, error) {
assert.Equal(t, "www.aliyun.com", req.Host)
assert.Contains(t, req.URL.RawQuery, "DurationSeconds=7200")
return mockResponse(400, ``, errors.New("sdk test"))
}
}
Expand Down

0 comments on commit 0f50690

Please sign in to comment.