@@ -1040,10 +1040,8 @@ func (s *ScalewayAPI) PostServerAction(serverID, action string) error {
1040
1040
}
1041
1041
defer resp .Body .Close ()
1042
1042
1043
- if _ , err = s .handleHTTPError ([]int {202 }, resp ); err != nil {
1044
- return err
1045
- }
1046
- return nil
1043
+ _ , err = s .handleHTTPError ([]int {202 }, resp )
1044
+ return err
1047
1045
}
1048
1046
1049
1047
// DeleteServer deletes a server
@@ -1205,10 +1203,8 @@ func (s *ScalewayAPI) PutVolume(volumeID string, definition ScalewayVolumePutDef
1205
1203
}
1206
1204
defer resp .Body .Close ()
1207
1205
1208
- if _ , err := s .handleHTTPError ([]int {200 }, resp ); err != nil {
1209
- return err
1210
- }
1211
- return nil
1206
+ _ , err = s .handleHTTPError ([]int {200 }, resp )
1207
+ return err
1212
1208
}
1213
1209
1214
1210
// ResolveServer attempts the find a matching Identifier for the input string
@@ -1575,11 +1571,8 @@ func (s *ScalewayAPI) DeleteUserdata(serverID string, key string) error {
1575
1571
}
1576
1572
defer resp .Body .Close ()
1577
1573
1578
- // Succeed POST code
1579
- if resp .StatusCode == 204 {
1580
- return nil
1581
- }
1582
- return fmt .Errorf ("cannot delete user_data (%d)" , resp .StatusCode )
1574
+ _ , err = s .handleHTTPError ([]int {204 }, resp )
1575
+ return err
1583
1576
}
1584
1577
1585
1578
// GetTasks get the list of tasks from the ScalewayAPI
@@ -1896,6 +1889,78 @@ func (s *ScalewayAPI) GetASecurityGroup(groupsID string) (*ScalewayGetSecurityGr
1896
1889
return & securityGroups , nil
1897
1890
}
1898
1891
1892
+ // PostSecurityGroup posts a group on a server
1893
+ func (s * ScalewayAPI ) PostSecurityGroup (group ScalewayNewSecurityGroup ) error {
1894
+ resp , err := s .PostResponse ("security_groups" , group )
1895
+ if err != nil {
1896
+ return err
1897
+ }
1898
+ defer resp .Body .Close ()
1899
+
1900
+ _ , err = s .handleHTTPError ([]int {201 }, resp )
1901
+ return err
1902
+ }
1903
+
1904
+ // PostSecurityGroupRule posts a rule on a server
1905
+ func (s * ScalewayAPI ) PostSecurityGroupRule (SecurityGroupID string , rules ScalewayNewSecurityGroupRule ) error {
1906
+ resp , err := s .PostResponse (fmt .Sprintf ("security_groups/%s/rules" , SecurityGroupID ), rules )
1907
+ if err != nil {
1908
+ return err
1909
+ }
1910
+ defer resp .Body .Close ()
1911
+
1912
+ _ , err = s .handleHTTPError ([]int {201 }, resp )
1913
+ return err
1914
+ }
1915
+
1916
+ // DeleteSecurityGroup deletes a SecurityGroup
1917
+ func (s * ScalewayAPI ) DeleteSecurityGroup (securityGroupID string ) error {
1918
+ resp , err := s .DeleteResponse (fmt .Sprintf ("security_groups/%s" , securityGroupID ))
1919
+ if err != nil {
1920
+ return err
1921
+ }
1922
+ defer resp .Body .Close ()
1923
+
1924
+ _ , err = s .handleHTTPError ([]int {204 }, resp )
1925
+ return err
1926
+ }
1927
+
1928
+ // PutSecurityGroup updates a SecurityGroup
1929
+ func (s * ScalewayAPI ) PutSecurityGroup (group ScalewayNewSecurityGroup , securityGroupID string ) error {
1930
+ resp , err := s .PutResponse (fmt .Sprintf ("security_groups/%s" , securityGroupID ), group )
1931
+ if err != nil {
1932
+ return err
1933
+ }
1934
+ defer resp .Body .Close ()
1935
+
1936
+ _ , err = s .handleHTTPError ([]int {200 }, resp )
1937
+ return err
1938
+ }
1939
+
1940
+ // PutSecurityGroupRule updates a SecurityGroupRule
1941
+ func (s * ScalewayAPI ) PutSecurityGroupRule (rules ScalewayNewSecurityGroupRule , securityGroupID , RuleID string ) error {
1942
+ resp , err := s .PutResponse (fmt .Sprintf ("security_groups/%s/rules/%s" , securityGroupID , RuleID ), rules )
1943
+ if err != nil {
1944
+ return err
1945
+ }
1946
+ defer resp .Body .Close ()
1947
+
1948
+ _ , err = s .handleHTTPError ([]int {200 }, resp )
1949
+ return err
1950
+ }
1951
+
1952
+ // DeleteSecurityGroupRule deletes a SecurityGroupRule
1953
+ func (s * ScalewayAPI ) DeleteSecurityGroupRule (SecurityGroupID , RuleID string ) error {
1954
+ resp , err := s .DeleteResponse (fmt .Sprintf ("security_groups/%s/rules/%s" , SecurityGroupID , RuleID ))
1955
+ if err != nil {
1956
+ return err
1957
+ }
1958
+ defer resp .Body .Close ()
1959
+
1960
+ _ , err = s .handleHTTPError ([]int {204 }, resp )
1961
+ return err
1962
+ }
1963
+
1899
1964
// GetContainers returns a ScalewayGetContainers
1900
1965
func (s * ScalewayAPI ) GetContainers () (* ScalewayGetContainers , error ) {
1901
1966
resp , err := s .GetResponse ("containers" )
@@ -2002,10 +2067,8 @@ func (s *ScalewayAPI) AttachIP(ipID, serverID string) error {
2002
2067
if err != nil {
2003
2068
return err
2004
2069
}
2005
- if _ , err := s .handleHTTPError ([]int {200 }, resp ); err != nil {
2006
- return err
2007
- }
2008
- return nil
2070
+ _ , err = s .handleHTTPError ([]int {200 }, resp )
2071
+ return err
2009
2072
}
2010
2073
2011
2074
// DeleteIP deletes an IP
0 commit comments