Skip to content
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1134,18 +1134,19 @@ $ scw inspect myserver | jq '.[0].public_ip.address'
* Support of `scw _userdata name VAR=@/path/to/file` ([#183](https://github.com/scaleway/scaleway-cli/issues/183))
* Support of `scw restart -w` ([#185](https://github.com/scaleway/scaleway-cli/issues/185))
* Restarting multiple servers in parallel ([#185](https://github.com/scaleway/scaleway-cli/issues/185))
* Added _security-groups ([#179](https://github.com/scaleway/scaleway-cli/issues/179))
Copy link
Contributor

Choose a reason for hiding this comment

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

You should replace the "No entry"


View full [commits list](https://github.com/scaleway/scaleway-cli/compare/v1.5.0...master)

### v1.5.0 (2015-09-11)

* Support of `scw tag --bootscript=""` option ([#149](https://github.com/scaleway/scaleway-cli/issues/149)
* `scw info` now prints user/organization info from the API ([#130](https://github.com/scaleway/scaleway-cli/issues/130)
* Support of `scw tag --bootscript=""` option ([#149](https://github.com/scaleway/scaleway-cli/issues/149))
* `scw info` now prints user/organization info from the API ([#130](https://github.com/scaleway/scaleway-cli/issues/130))
* Added helpers to manipulate new `user_data` API ([#150](https://github.com/scaleway/scaleway-cli/issues/150))
* Renamed `create-image-from-s3.sh` example and now auto-filling image metadata (title and bootscript) based on the Makefile configuration
* Support of `scw rm -f/--force` option ([#158](https://github.com/scaleway/scaleway-cli/issues/158))
* Added `scw _userdata local ...` option which interacts with the Metadata API without authentication ([#166](https://github.com/scaleway/scaleway-cli/issues/166))
* Initial version of `scw _billing` (price estimation tool) ([#118](https://github.com/scaleway/scaleway-cli/issues/118)
* Initial version of `scw _billing` (price estimation tool) ([#118](https://github.com/scaleway/scaleway-cli/issues/118))
* Fix: debian-package installation
* Fix: nil pointer dereference ([#155](https://github.com/scaleway/scaleway-cli/pull/155)) ([@ebfe](https://github.com/ebfe))
* Fix: regression on scw create ([#142](https://github.com/scaleway/scaleway-cli/issues/142))
Expand Down
136 changes: 133 additions & 3 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import (

// Default values
var (
ComputeAPI string = "https://api.scaleway.com/"
AccountAPI string = "https://account.scaleway.com/"
MetadataAPI string = "http://169.254.42.42/"
ComputeAPI = "https://api.scaleway.com/"
AccountAPI = "https://account.scaleway.com/"
MetadataAPI = "http://169.254.42.42/"
)

// ScalewayAPI is the interface used to communicate with the Scaleway API
Expand Down Expand Up @@ -381,6 +381,59 @@ type ScalewayTasks struct {
Tasks []ScalewayTask `json:"tasks,omitempty"`
}

// ScalewaySecurityGroupRule definition
type ScalewaySecurityGroupRule struct {
Direction string `json:"direction"`
Protocol string `json:"protocol"`
IPRange string `json:"ip_range"`
DestPortFrom int `json:"dest_port_from,omitempty"`
Action string `json:"action"`
Postion int `json:"position"`
DestPortTo string `json:"dest_port_to"`
Editable bool `json:"editable"`
ID string `json:"id"`
}

// ScalewayGetSecurityGroupRules represents the response of a GET /security_group/{groupID}/rules
type ScalewayGetSecurityGroupRules struct {
Rules []ScalewaySecurityGroupRule `json:"rules"`
}

// ScalewayGetSecurityGroupRule represents the response of a GET /security_group/{groupID}/rules/{ruleID}
type ScalewayGetSecurityGroupRule struct {
Rules ScalewaySecurityGroupRule `json:"rule"`
}

// ScalewayNewSecurityGroupRule definition POST/PUT request /security_group/{groupID}
type ScalewayNewSecurityGroupRule struct {
Action string `json:"action"`
Direction string `json:"direction"`
IPRange string `json:"ip_range"`
Protocol string `json:"protocol"`
DestPortFrom int `json:"dest_port_from,omitempty"`
}

// ScalewaySecurityGroups definition
type ScalewaySecurityGroups struct {
Description string `json:"description"`
EnableDefaultSecurity bool `json:"enable_default_security"`
ID string `json:"id"`
Organization string `json:"organization"`
Name string `json:"name"`
OrganizationDefault bool `json:"organization_default"`
Servers []ScalewaySecurityGroup `json:"servers"`
}

// ScalewayGetSecurityGroups represents the response of a GET /security_groups/
type ScalewayGetSecurityGroups struct {
SecurityGroups []ScalewaySecurityGroups `json:"security_groups"`
}

// ScalewayGetSecurityGroup represents the response of a GET /security_groups/{groupID}
type ScalewayGetSecurityGroup struct {
SecurityGroups ScalewaySecurityGroups `json:"security_group"`
}

// ScalewaySecurityGroup represents a Scaleway security group
type ScalewaySecurityGroup struct {
// Identifier is a unique identifier for the security group
Expand All @@ -390,6 +443,13 @@ type ScalewaySecurityGroup struct {
Name string `json:"name,omitempty"`
}

// ScalewayNewSecurityGroup definition POST/PUT request /security_groups
type ScalewayNewSecurityGroup struct {
Organization string `json:"organization"`
Name string `json:"name"`
Description string `json:"description"`
}

// ScalewayServer represents a Scaleway C1 server
type ScalewayServer struct {
// Identifier is a unique identifier for the server
Expand Down Expand Up @@ -575,6 +635,7 @@ type ScalewayUserDefinition struct {
SSHPublicKeys []ScalewayKeyDefinition `json:"ssh_public_keys"`
}

// ScalewayUsersDefinition represents the response of a GET /user
type ScalewayUsersDefinition struct {
User ScalewayUserDefinition `json:"user"`
}
Expand Down Expand Up @@ -1359,6 +1420,7 @@ func (s *ScalewayAPI) GetBootscript(bootscriptID string) (*ScalewayBootscript, e
return &oneBootscript.Bootscript, nil
}

// ScalewayUserdatas represents the response of a GET /user_data
type ScalewayUserdatas struct {
UserData []string `json:"user_data"`
}
Expand Down Expand Up @@ -1678,6 +1740,74 @@ func (s *ScalewayAPI) GetImageID(needle string, exitIfMissing bool) string {
return ""
}

// GetSecurityGroups returns a ScalewaySecurityGroups
func (s *ScalewayAPI) GetSecurityGroups() (*ScalewayGetSecurityGroups, error) {
resp, err := s.GetResponse("security_groups")
if err != nil {
return nil, err
}
defer resp.Body.Close()

var securityGroups ScalewayGetSecurityGroups
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(&securityGroups)
if err != nil {
return nil, err
}
return &securityGroups, nil
}

// GetSecurityGroupRules returns a ScalewaySecurityGroupRules
func (s *ScalewayAPI) GetSecurityGroupRules(groupID string) (*ScalewayGetSecurityGroupRules, error) {
resp, err := s.GetResponse(fmt.Sprintf("security_groups/%s/rules", groupID))
if err != nil {
return nil, err
}
defer resp.Body.Close()

var securityGroupRules ScalewayGetSecurityGroupRules
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(&securityGroupRules)
if err != nil {
return nil, err
}
return &securityGroupRules, nil
}

// GetASecurityGroupRule returns a ScalewaySecurityGroupRule
func (s *ScalewayAPI) GetASecurityGroupRule(groupID string, rulesID string) (*ScalewayGetSecurityGroupRule, error) {
resp, err := s.GetResponse(fmt.Sprintf("security_groups/%s/rules/%s", groupID, rulesID))
if err != nil {
return nil, err
}
defer resp.Body.Close()

var securityGroupRules ScalewayGetSecurityGroupRule
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(&securityGroupRules)
if err != nil {
return nil, err
}
return &securityGroupRules, nil
}

// GetASecurityGroup returns a ScalewaySecurityGroup
func (s *ScalewayAPI) GetASecurityGroup(groupsID string) (*ScalewayGetSecurityGroup, error) {
resp, err := s.GetResponse(fmt.Sprintf("security_groups/%s", groupsID))
if err != nil {
return nil, err
}
defer resp.Body.Close()

var securityGroups ScalewayGetSecurityGroup
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(&securityGroups)
if err != nil {
return nil, err
}
return &securityGroups, nil
}

// GetBootscriptID returns exactly one bootscript matching or dies
func (s *ScalewayAPI) GetBootscriptID(needle string) string {
// Parses optional type prefix, i.e: "bootscript:name" -> "name"
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ var Commands = []*Command{
cmdCompletion,
cmdFlushCache,
cmdPatch,
cmdSecurityGroups,
}
2 changes: 1 addition & 1 deletion pkg/cli/x_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func runPatch(cmd *Command, args []string) error {
// Parsing FIELD=VALUE
updateParts := strings.SplitN(args[1], "=", 2)
if len(updateParts) != 2 {
cmd.PrintShortUsage()
return cmd.PrintShortUsage()
}
fieldName := updateParts[0]
newValue := updateParts[1]
Expand Down
Loading