Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use POST for user sensitive calls #86

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cloudstack/UserService.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (s *UserService) NewCreateUserParams(account string, email string, firstnam

// Creates a user for an account that already exists
func (s *UserService) CreateUser(p *CreateUserParams) (*CreateUserResponse, error) {
resp, err := s.cs.newRequest("createUser", p.toURLValues())
resp, err := s.cs.newPostRequest("createUser", p.toURLValues())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1478,7 +1478,7 @@ func (s *UserService) NewUpdateUserParams(id string) *UpdateUserParams {

// Updates a user account
func (s *UserService) UpdateUser(p *UpdateUserParams) (*UpdateUserResponse, error) {
resp, err := s.cs.newRequest("updateUser", p.toURLValues())
resp, err := s.cs.newPostRequest("updateUser", p.toURLValues())
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion cloudstack/VPNService.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (s *VPNService) NewAddVpnUserParams(password string, username string) *AddV

// Adds vpn users
func (s *VPNService) AddVpnUser(p *AddVpnUserParams) (*AddVpnUserResponse, error) {
resp, err := s.cs.newRequest("addVpnUser", p.toURLValues())
resp, err := s.cs.newPostRequest("addVpnUser", p.toURLValues())
if err != nil {
return nil, err
}
Expand Down
16 changes: 15 additions & 1 deletion generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ var detailsRequireZeroIndex = map[string]bool{
"updateAccount": true,
}

// requiresPost is a prefilled set of API names that require POST
// for security or size purposes
var requiresPostMethod = map[string]bool{
"login": true,
"deployVirtualMachine": true,
"updateVirtualMachine": true,
"createUser": true,
"updateUser": true,
"addVpnUser": true,
"registerUserData": true,
"setupUserTwoFactorAuthentication": true,
"validateUserTwoFactorAuthenticationCode": true,
Comment on lines +70 to +72
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code for these 3 commands is not being generated since they are not defined in generate/layout.go.

Copy link
Contributor Author

@mlsorensen mlsorensen May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, but they're calls that I wanted to ensure use post when and if they do get added.

}

var mapRequireList = map[string]map[string]bool{
"deployVirtualMachine": map[string]bool{
"dhcpoptionsnetworklist": true,
Expand Down Expand Up @@ -1698,7 +1712,7 @@ func (s *service) generateNewAPICallFunc(a *API) {
pn(" time.Sleep(500 * time.Millisecond)")
pn(" }")
} else {
if a.Name == "deployVirtualMachine" || a.Name == "login" || a.Name == "updateVirtualMachine" {
if requiresPostMethod[a.Name] {
pn(" resp, err := s.cs.newPostRequest(\"%s\", p.toURLValues())", a.Name)
} else {
pn(" resp, err := s.cs.newRequest(\"%s\", p.toURLValues())", a.Name)
Expand Down
6 changes: 3 additions & 3 deletions generate/listApis.json
Original file line number Diff line number Diff line change
Expand Up @@ -44786,7 +44786,7 @@
]
},
{
"description": "Lists OpenDyalight controllers",
"description": "Lists OpenDaylight controllers",
"isasync": false,
"name": "listOpenDaylightControllers",
"params": [
Expand Down Expand Up @@ -55892,7 +55892,7 @@
"since": "4.15.0"
},
{
"description": "Removes an OpenDyalight controler",
"description": "Removes an OpenDaylight controller",
"isasync": true,
"name": "deleteOpenDaylightController",
"params": [
Expand Down Expand Up @@ -117752,7 +117752,7 @@
]
},
{
"description": "Adds an OpenDyalight controler",
"description": "Adds an OpenDaylight controller",
"isasync": true,
"name": "addOpenDaylightController",
"params": [
Expand Down
Loading