Skip to content

Commit 053d0eb

Browse files
committed
display anonymous flag for anonymous API
1 parent e6f2cea commit 053d0eb

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

newmeta/meta.go

+13
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ type API struct {
7575

7676
// {
7777
// "name": "AddEntriesToAcl",
78+
// "security": [
79+
// "AK"
80+
// ],
7881
// "deprecated": false,
7982
// "protocol": "HTTP|HTTPS",
8083
// "method": "GET|POST",
@@ -92,13 +95,23 @@ type API struct {
9295

9396
type APIDetail struct {
9497
Name string `json:"name"`
98+
Auth []string `json:"security"`
9599
Deprecated bool `json:"deprecated"`
96100
Protocol string `json:"protocol"`
97101
Method string `json:"method"`
98102
PathPattern string `json:"pathPattern"`
99103
Parameters []RequestParameter `json:"parameters"`
100104
}
101105

106+
func (api *APIDetail) IsAnonymousAPI() bool {
107+
for _, v := range api.Auth {
108+
if v == "Anonymous" {
109+
return true
110+
}
111+
}
112+
return false
113+
}
114+
102115
type RequestParameter struct {
103116
Name string `json:"name"`
104117
Description string `json:"description"`

newmeta/meta_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,12 @@ func TestGetAPIDetail(t *testing.T) {
4646
assert.Equal(t, "GET|POST", api.Method)
4747
assert.Equal(t, false, api.Deprecated)
4848
}
49+
50+
func TestIsAnonymousAPI(t *testing.T) {
51+
akapi, err := GetAPIDetail("en", "ecs", "DescribeRegions")
52+
assert.Nil(t, err)
53+
assert.False(t, akapi.IsAnonymousAPI())
54+
api, err := GetAPIDetail("en", "sts", "AssumeRoleWithOIDC")
55+
assert.Nil(t, err)
56+
assert.True(t, api.IsAnonymousAPI())
57+
}

openapi/library.go

+4
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,14 @@ func (a *Library) PrintProductUsage(productCode string, withApi bool) error {
106106
} else {
107107
api, _ := newmeta.GetAPI(i18n.GetLanguage(), productCode, apiName)
108108
if api != nil {
109+
apiDetail, _ := newmeta.GetAPIDetail(i18n.GetLanguage(), productCode, apiName)
109110
// use new api metadata
110111
if api.Deprecated {
111112
fmt := fmt.Sprintf(" %%-%ds [Deprecated]%%s\n", maxNameLen+1)
112113
cli.PrintfWithColor(a.writer, cli.Green, fmt, apiName, api.Summary)
114+
} else if apiDetail.IsAnonymousAPI() {
115+
fmt := fmt.Sprintf(" %%-%ds [Anonymous]%%s\n", maxNameLen+1)
116+
cli.PrintfWithColor(a.writer, cli.Green, fmt, apiName, api.Summary)
113117
} else {
114118
fmt := fmt.Sprintf(" %%-%ds %%s\n", maxNameLen+1)
115119
cli.PrintfWithColor(a.writer, cli.Green, fmt, apiName, api.Summary)

0 commit comments

Comments
 (0)