Skip to content

Commit a8b1dbf

Browse files
committed
Add GetContainers
1 parent 417c35e commit a8b1dbf

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

pkg/api/api.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,26 @@ type ScalewayTokensDefinition struct {
631631
Token ScalewayTokenDefinition `json:"token"`
632632
}
633633

634+
type ScalewayContainerData struct {
635+
LastModified string `json:"last_modified"`
636+
Name string `json:"name"`
637+
Size string `json:"size"`
638+
}
639+
640+
type ScalewayGetContainerDatas struct {
641+
Container []ScalewayContainerData `json:"container"`
642+
}
643+
644+
type ScalewayContainer struct {
645+
ScalewayOrganizationDefinition `json:"organization"`
646+
Name string `json:"name"`
647+
Size string `json:"size"`
648+
}
649+
650+
type ScalewayGetContainers struct {
651+
Containers []ScalewayContainer `json:"containers"`
652+
}
653+
634654
// ScalewayConnectResponse represents the answer from POST /tokens
635655
type ScalewayConnectResponse struct {
636656
Token ScalewayTokenDefinition `json:"token"`
@@ -1861,6 +1881,46 @@ func (s *ScalewayAPI) GetASecurityGroup(groupsID string) (*ScalewayGetSecurityGr
18611881
return &securityGroups, nil
18621882
}
18631883

1884+
// GetContainers returns a ScalewayGetContainers
1885+
func (s *ScalewayAPI) GetContainers() (*ScalewayGetContainers, error) {
1886+
resp, err := s.GetResponse("containers")
1887+
if err != nil {
1888+
return nil, err
1889+
}
1890+
defer resp.Body.Close()
1891+
1892+
body, err := s.handleHTTPError([]int{200}, resp)
1893+
if err != nil {
1894+
return nil, err
1895+
}
1896+
var containers ScalewayGetContainers
1897+
1898+
if err = json.Unmarshal(body, &containers); err != nil {
1899+
return nil, err
1900+
}
1901+
return &containers, nil
1902+
}
1903+
1904+
// GetContainerDatas returns a ScalewayGetContainerDatas
1905+
func (s *ScalewayAPI) GetContainerDatas(container string) (*ScalewayGetContainerDatas, error) {
1906+
resp, err := s.GetResponse(fmt.Sprintf("containers/%s", container))
1907+
if err != nil {
1908+
return nil, err
1909+
}
1910+
defer resp.Body.Close()
1911+
1912+
body, err := s.handleHTTPError([]int{200}, resp)
1913+
if err != nil {
1914+
return nil, err
1915+
}
1916+
var datas ScalewayGetContainerDatas
1917+
1918+
if err = json.Unmarshal(body, &datas); err != nil {
1919+
return nil, err
1920+
}
1921+
return &datas, nil
1922+
}
1923+
18641924
// GetIPS returns a ScalewayGetIPS
18651925
func (s *ScalewayAPI) GetIPS() (*ScalewayGetIPS, error) {
18661926
resp, err := s.GetResponse("ips")

0 commit comments

Comments
 (0)