-
Notifications
You must be signed in to change notification settings - Fork 152
Added permissions scw info
#195
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -665,6 +665,14 @@ type ScalewayDashboard struct { | |
IPsCount int `json:"ips_count"` | ||
} | ||
|
||
type ScalewayPermissions map[string]ScalewayPermCategory | ||
type ScalewayPermCategory map[string][]string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported type ScalewayPermCategory should have comment or be unexported |
||
|
||
// ScalewayPermissionDefinition represents the permissions | ||
type ScalewayPermissionDefinition struct { | ||
Permissions ScalewayPermissions `json:"permissions"` | ||
} | ||
|
||
// FuncMap used for json inspection | ||
var FuncMap = template.FuncMap{ | ||
"json": func(v interface{}) string { | ||
|
@@ -1674,6 +1682,28 @@ func (s *ScalewayAPI) GetUser() (*ScalewayUserDefinition, error) { | |
return &user.User, nil | ||
} | ||
|
||
func (s *ScalewayAPI) GetPermissions() (*ScalewayPermissionDefinition, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported method ScalewayAPI.GetPermissions should have comment or be unexported |
||
s.EnableAccountAPI() | ||
defer s.DisableAccountAPI() | ||
resp, err := s.GetResponse(fmt.Sprintf("tokens/%s/permissions", s.Token)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != 200 { | ||
return nil, fmt.Errorf("[%d] no such user", resp.StatusCode) | ||
} | ||
var permissions ScalewayPermissionDefinition | ||
|
||
decoder := json.NewDecoder(resp.Body) | ||
err = decoder.Decode(&permissions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &permissions, nil | ||
} | ||
|
||
// GetDashboard returns the dashboard | ||
func (s *ScalewayAPI) GetDashboard() (*ScalewayDashboard, error) { | ||
resp, err := s.GetResponse("dashboard") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,9 +59,10 @@ func RunInfo(ctx CommandContext, args InfoArgs) error { | |
if err != nil { | ||
return err | ||
} else { | ||
fmt.Fprintf(ctx.Stdout, " [%d] %s\n", id, fingerprint) | ||
fmt.Fprintf(ctx.Stdout, " [%d] %s", id, fingerprint) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you removed the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because fingerprint has already a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok LGTM |
||
} | ||
} | ||
fmt.Fprintf(ctx.Stdout, "\n") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this change ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To add a space between the two sections There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
dashboard, err := ctx.API.GetDashboard() | ||
|
@@ -74,7 +75,20 @@ func RunInfo(ctx CommandContext, args InfoArgs) error { | |
fmt.Fprintf(ctx.Stdout, " Images:\t\t%d\n", dashboard.ImagesCount) | ||
fmt.Fprintf(ctx.Stdout, " Snapshots:\t\t%d\n", dashboard.SnapshotsCount) | ||
fmt.Fprintf(ctx.Stdout, " Servers:\t\t%d\n", dashboard.ServersCount) | ||
fmt.Fprintf(ctx.Stdout, " Ips:\t\t\t%d\n", dashboard.IPsCount) | ||
fmt.Fprintf(ctx.Stdout, " Ips:\t\t\t%d\n\n", dashboard.IPsCount) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add the |
||
|
||
permissions, err := ctx.API.GetPermissions() | ||
if err != nil { | ||
return fmt.Errorf("Unable to get your permisssions") | ||
} | ||
fmt.Fprintln(ctx.Stdout, "Permissions:") | ||
for _, service := range permissions.Permissions { | ||
for key, serviceName := range service { | ||
fmt.Fprintf(ctx.Stdout, " %s\n", key) | ||
for _, perm := range serviceName { | ||
fmt.Fprintf(ctx.Stdout, " %s\n", perm) | ||
} | ||
} | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported type ScalewayPermissions should have comment or be unexported