Skip to content

Commit

Permalink
display anonymous flag for anonymous API
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian authored and yndu13 committed Jan 31, 2024
1 parent e6f2cea commit d4bafad
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions newmeta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ type API struct {

// {
// "name": "AddEntriesToAcl",
// "security": [
// "AK"
// ],
// "deprecated": false,
// "protocol": "HTTP|HTTPS",
// "method": "GET|POST",
Expand All @@ -92,13 +95,23 @@ type API struct {

type APIDetail struct {
Name string `json:"name"`
Auth []string `json:"security"`
Deprecated bool `json:"deprecated"`
Protocol string `json:"protocol"`
Method string `json:"method"`
PathPattern string `json:"pathPattern"`
Parameters []RequestParameter `json:"parameters"`
}

func (api *APIDetail) IsAnonymousAPI() bool {
for _, v := range api.Auth {
if v == "Anonymous" {
return true
}
}
return false
}

type RequestParameter struct {
Name string `json:"name"`
Description string `json:"description"`
Expand Down
9 changes: 9 additions & 0 deletions newmeta/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ func TestGetAPIDetail(t *testing.T) {
assert.Equal(t, "GET|POST", api.Method)
assert.Equal(t, false, api.Deprecated)
}

func TestIsAnonymousAPI(t *testing.T) {
akapi, err := GetAPIDetail("en", "ecs", "DescribeRegions")
assert.Nil(t, err)
assert.False(t, akapi.IsAnonymousAPI())
api, err := GetAPIDetail("en", "sts", "AssumeRoleWithOIDC")
assert.Nil(t, err)
assert.True(t, api.IsAnonymousAPI())
}
4 changes: 4 additions & 0 deletions openapi/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,14 @@ func (a *Library) PrintProductUsage(productCode string, withApi bool) error {
} else {
api, _ := newmeta.GetAPI(i18n.GetLanguage(), productCode, apiName)
if api != nil {
apiDetail, _ := newmeta.GetAPIDetail(i18n.GetLanguage(), productCode, apiName)
// use new api metadata
if api.Deprecated {
fmt := fmt.Sprintf(" %%-%ds [Deprecated]%%s\n", maxNameLen+1)
cli.PrintfWithColor(a.writer, cli.Green, fmt, apiName, api.Summary)
} else if apiDetail.IsAnonymousAPI() {
fmt := fmt.Sprintf(" %%-%ds [Anonymous]%%s\n", maxNameLen+1)
cli.PrintfWithColor(a.writer, cli.Green, fmt, apiName, api.Summary)
} else {
fmt := fmt.Sprintf(" %%-%ds %%s\n", maxNameLen+1)
cli.PrintfWithColor(a.writer, cli.Green, fmt, apiName, api.Summary)
Expand Down

0 comments on commit d4bafad

Please sign in to comment.