Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitddf8c49

Browse files
spezaSkarlso
authored andcommitted
Fix basic Go Report Card issues (#167)
1 parent41ccd5c commitddf8c49

File tree

18 files changed

+72
-60
lines changed

18 files changed

+72
-60
lines changed

‎auth/role.go‎

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ package auth
22

33
import"github.com/gaia-pipeline/gaia"
44

5-
//Constructor for creating new UserRoleEndpoints.
5+
//NewUserRoleEndpoint is a constructor for creating new UserRoleEndpoints.
66
funcNewUserRoleEndpoint(methodstring,pathstring)*gaia.UserRoleEndpoint {
77
return&gaia.UserRoleEndpoint{Path:path,Method:method}
88
}
99

10-
//Createsa full user role name {category}{role}.
10+
//FullUserRoleName returnsa full user role name in the form {category}{role}.
1111
funcFullUserRoleName(category*gaia.UserRoleCategory,role*gaia.UserRole)string {
1212
returncategory.Name+role.Name
1313
}
1414

15-
// Flattens the given user categories into a single slice of {category}{role}s.
15+
// FlattenUserCategoryRoles flattens the given user categories into a single slice with items in the form off
16+
// {category}{role}s.
1617
funcFlattenUserCategoryRoles(cats []*gaia.UserRoleCategory) []string {
1718
varroles []string
1819
for_,category:=rangecats {
@@ -24,15 +25,15 @@ func FlattenUserCategoryRoles(cats []*gaia.UserRoleCategory) []string {
2425
}
2526

2627
var (
27-
//All the default user categories and roles.
28+
//DefaultUserRoles contains all the default user categories and roles.
2829
DefaultUserRoles= []*gaia.UserRoleCategory{
2930
{
3031
Name:"Pipeline",
3132
Description:"Managing and initiating pipelines.",
3233
Roles: []*gaia.UserRole{
3334
{
3435
Name:"Create",
35-
ApiEndpoint: []*gaia.UserRoleEndpoint{
36+
APIEndpoint: []*gaia.UserRoleEndpoint{
3637
NewUserRoleEndpoint("POST","/api/v1/pipeline"),
3738
NewUserRoleEndpoint("POST","/api/v1/pipeline/gitlsremote"),
3839
NewUserRoleEndpoint("GET","/api/v1/pipeline/name"),
@@ -42,7 +43,7 @@ var (
4243
},
4344
{
4445
Name:"List",
45-
ApiEndpoint: []*gaia.UserRoleEndpoint{
46+
APIEndpoint: []*gaia.UserRoleEndpoint{
4647
NewUserRoleEndpoint("GET","/api/v1/pipeline/created"),
4748
NewUserRoleEndpoint("GET","/api/v1/pipeline"),
4849
NewUserRoleEndpoint("GET","/api/v1/pipeline/latest"),
@@ -51,28 +52,28 @@ var (
5152
},
5253
{
5354
Name:"Get",
54-
ApiEndpoint: []*gaia.UserRoleEndpoint{
55+
APIEndpoint: []*gaia.UserRoleEndpoint{
5556
NewUserRoleEndpoint("GET","/api/v1/pipeline/:pipelineid"),
5657
},
5758
Description:"Get created pipelines.",
5859
},
5960
{
6061
Name:"Update",
61-
ApiEndpoint: []*gaia.UserRoleEndpoint{
62+
APIEndpoint: []*gaia.UserRoleEndpoint{
6263
NewUserRoleEndpoint("PUT","/api/v1/pipeline/:pipelineid"),
6364
},
6465
Description:"Update created pipelines.",
6566
},
6667
{
6768
Name:"Delete",
68-
ApiEndpoint: []*gaia.UserRoleEndpoint{
69+
APIEndpoint: []*gaia.UserRoleEndpoint{
6970
NewUserRoleEndpoint("DELETE","/api/v1/pipeline/:pipelineid"),
7071
},
7172
Description:"Delete created pipelines.",
7273
},
7374
{
7475
Name:"Start",
75-
ApiEndpoint: []*gaia.UserRoleEndpoint{
76+
APIEndpoint: []*gaia.UserRoleEndpoint{
7677
NewUserRoleEndpoint("POST","/api/v1/pipeline/:pipelineid/start"),
7778
},
7879
Description:"Start created pipelines.",
@@ -85,29 +86,29 @@ var (
8586
Roles: []*gaia.UserRole{
8687
{
8788
Name:"Stop",
88-
ApiEndpoint: []*gaia.UserRoleEndpoint{
89+
APIEndpoint: []*gaia.UserRoleEndpoint{
8990
NewUserRoleEndpoint("POST","/api/v1/pipelinerun/:pipelineid/:runid/stop"),
9091
},
9192
Description:"Stop running pipelines.",
9293
},
9394
{
9495
Name:"Get",
95-
ApiEndpoint: []*gaia.UserRoleEndpoint{
96+
APIEndpoint: []*gaia.UserRoleEndpoint{
9697
NewUserRoleEndpoint("GET","/api/v1/pipelinerun/:pipelineid/:runid"),
9798
NewUserRoleEndpoint("GET","/api/v1/pipelinerun/:pipelineid/latest"),
9899
},
99100
Description:"Get pipeline runs.",
100101
},
101102
{
102103
Name:"List",
103-
ApiEndpoint: []*gaia.UserRoleEndpoint{
104+
APIEndpoint: []*gaia.UserRoleEndpoint{
104105
NewUserRoleEndpoint("GET","pipelinerun/:pipelineid"),
105106
},
106107
Description:"List pipeline runs.",
107108
},
108109
{
109110
Name:"Logs",
110-
ApiEndpoint: []*gaia.UserRoleEndpoint{
111+
APIEndpoint: []*gaia.UserRoleEndpoint{
111112
NewUserRoleEndpoint("GET","/api/v1/pipelinerun/:pipelineid/:runid/latest"),
112113
},
113114
Description:"Get logs for pipeline runs.",
@@ -120,28 +121,28 @@ var (
120121
Roles: []*gaia.UserRole{
121122
{
122123
Name:"List",
123-
ApiEndpoint: []*gaia.UserRoleEndpoint{
124+
APIEndpoint: []*gaia.UserRoleEndpoint{
124125
NewUserRoleEndpoint("GET","/api/v1/secrets"),
125126
},
126127
Description:"List created secrets.",
127128
},
128129
{
129130
Name:"Delete",
130-
ApiEndpoint: []*gaia.UserRoleEndpoint{
131+
APIEndpoint: []*gaia.UserRoleEndpoint{
131132
NewUserRoleEndpoint("DELETE","/api/v1/secret/:key"),
132133
},
133134
Description:"Delete created secrets.",
134135
},
135136
{
136137
Name:"Create",
137-
ApiEndpoint: []*gaia.UserRoleEndpoint{
138+
APIEndpoint: []*gaia.UserRoleEndpoint{
138139
NewUserRoleEndpoint("POST","/api/v1/secret"),
139140
},
140141
Description:"Create new secrets.",
141142
},
142143
{
143144
Name:"Update",
144-
ApiEndpoint: []*gaia.UserRoleEndpoint{
145+
APIEndpoint: []*gaia.UserRoleEndpoint{
145146
NewUserRoleEndpoint("PUT","/api/v1/secret/update"),
146147
},
147148
Description:"Update created secrets.",
@@ -154,28 +155,28 @@ var (
154155
Roles: []*gaia.UserRole{
155156
{
156157
Name:"Create",
157-
ApiEndpoint: []*gaia.UserRoleEndpoint{
158+
APIEndpoint: []*gaia.UserRoleEndpoint{
158159
NewUserRoleEndpoint("POST","/api/v1/user"),
159160
},
160161
Description:"Create new users.",
161162
},
162163
{
163164
Name:"List",
164-
ApiEndpoint: []*gaia.UserRoleEndpoint{
165+
APIEndpoint: []*gaia.UserRoleEndpoint{
165166
NewUserRoleEndpoint("GET","/api/v1/users"),
166167
},
167168
Description:"List created users.",
168169
},
169170
{
170171
Name:"ChangePassword",
171-
ApiEndpoint: []*gaia.UserRoleEndpoint{
172+
APIEndpoint: []*gaia.UserRoleEndpoint{
172173
NewUserRoleEndpoint("POST","/api/v1/user/password"),
173174
},
174175
Description:"Change created users passwords.",
175176
},
176177
{
177178
Name:"Delete",
178-
ApiEndpoint: []*gaia.UserRoleEndpoint{
179+
APIEndpoint: []*gaia.UserRoleEndpoint{
179180
NewUserRoleEndpoint("DELETE","/api/v1/user/:username"),
180181
},
181182
Description:"Delete created users.",
@@ -188,14 +189,14 @@ var (
188189
Roles: []*gaia.UserRole{
189190
{
190191
Name:"Get",
191-
ApiEndpoint: []*gaia.UserRoleEndpoint{
192+
APIEndpoint: []*gaia.UserRoleEndpoint{
192193
NewUserRoleEndpoint("GET","/api/v1/user/:username/permissions"),
193194
},
194195
Description:"Get created users permissions.",
195196
},
196197
{
197198
Name:"Update",
198-
ApiEndpoint: []*gaia.UserRoleEndpoint{
199+
APIEndpoint: []*gaia.UserRoleEndpoint{
199200
NewUserRoleEndpoint("PUT","/api/v1/user/:username/permissions"),
200201
},
201202
Description:"Update created users permissions.",

‎gaia.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ type User struct {
115115
LastLogin time.Time`json:"lastlogin,omitempty"`
116116
}
117117

118-
//User Permission is stored in its own data structure away from the core user. It represents all permission data
118+
//UserPermission is stored in its own data structure away from the core user. It represents all permission data
119119
// for a single user.
120120
typeUserPermissionstruct {
121121
Usernamestring`json:"username"`
@@ -134,7 +134,7 @@ type UserRoleCategory struct {
134134
typeUserRolestruct {
135135
Namestring`json:"name"`
136136
Descriptionstring`json:"description"`
137-
ApiEndpoint []*UserRoleEndpoint`json:"api_endpoints"`
137+
APIEndpoint []*UserRoleEndpoint`json:"api_endpoints"`
138138
}
139139

140140
// UserRoleEndpoint represents the path and method of the API endpoint to be secured.

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ require (
2929
github.com/mitchellh/go-testing-interfacev0.0.0-20171004221916-a61a99592b77// indirect
3030
github.com/oklog/runv1.0.0// indirect
3131
github.com/pelletier/go-buffruneiov0.2.0// indirect
32-
github.com/pkg/errorsv0.8.1// indirect
32+
github.com/pkg/errorsv0.8.1
3333
github.com/robfig/cronv0.0.0-20180505203441-b41be1df6967
3434
github.com/satori/go.uuidv1.2.0
3535
github.com/sergi/go-diffv1.0.0// indirect

‎handlers/auth.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ var (
1818
errNotAuthorized=errors.New("no or invalid jwt token provided. You are not authorized")
1919
)
2020

21-
// Authentication middleware used for each request. Includes functionality that validates tokens and user permissions.
21+
// AuthMiddleware is middleware used for each request. Includes functionality that validates the JWT tokens and user
22+
// permissions.
2223
funcAuthMiddleware(roleAuth*AuthConfig) echo.MiddlewareFunc {
2324
returnfunc(next echo.HandlerFunc) echo.HandlerFunc {
2425
returnfunc(c echo.Context)error {
@@ -56,8 +57,8 @@ func AuthMiddleware(roleAuth *AuthConfig) echo.MiddlewareFunc {
5657
}
5758
}
5859

59-
//Simple authconfig struct to be passed intotheAuthMiddleware. Currentlyallow the ability to specify the
60-
// permission rolesapplied for each echorequest.
60+
//AuthConfig is a simpleconfig struct to be passed into AuthMiddleware. Currentlyallows the ability to specify
61+
//thepermission rolesrequired for each echoendpoint.
6162
typeAuthConfigstruct {
6263
RoleCategories []*gaia.UserRoleCategory
6364
}
@@ -74,14 +75,14 @@ func (ra *AuthConfig) checkRole(userRoles interface{}, method, path string) erro
7475
returnnil
7576
}
7677
}
77-
returnerrors.New(fmt.Sprintf("Required permission role %s",perm))
78+
returnfmt.Errorf("Required permission role %s",perm)
7879
}
7980

8081
// Iterate over each category to find a permission (if existing) for this API endpoint.
8182
func (ra*AuthConfig)getRequiredRole(method,pathstring)string {
8283
for_,category:=rangera.RoleCategories {
8384
for_,role:=rangecategory.Roles {
84-
for_,endpoint:=rangerole.ApiEndpoint {
85+
for_,endpoint:=rangerole.APIEndpoint {
8586
// If the http method & path match then return the role required for this endpoint
8687
ifmethod==endpoint.Method&&path==endpoint.Path {
8788
returnauth.FullUserRoleName(category,role)

‎handlers/auth_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ var mockRoleAuth = &AuthConfig{
2424
Roles: []*gaia.UserRole{
2525
{
2626
Name:"GetSingle",
27-
ApiEndpoint: []*gaia.UserRoleEndpoint{
27+
APIEndpoint: []*gaia.UserRoleEndpoint{
2828
auth.NewUserRoleEndpoint("GET","/catone/:id"),
2929
auth.NewUserRoleEndpoint("GET","/catone/latest"),
3030
},
3131
},
3232
{
3333
Name:"PostSingle",
34-
ApiEndpoint: []*gaia.UserRoleEndpoint{
34+
APIEndpoint: []*gaia.UserRoleEndpoint{
3535
auth.NewUserRoleEndpoint("POST","/catone"),
3636
},
3737
},
@@ -42,13 +42,13 @@ var mockRoleAuth = &AuthConfig{
4242
Roles: []*gaia.UserRole{
4343
{
4444
Name:"GetSingle",
45-
ApiEndpoint: []*gaia.UserRoleEndpoint{
45+
APIEndpoint: []*gaia.UserRoleEndpoint{
4646
auth.NewUserRoleEndpoint("GET","/cattwo/:first/:second"),
4747
},
4848
},
4949
{
5050
Name:"PostSingle",
51-
ApiEndpoint: []*gaia.UserRoleEndpoint{
51+
APIEndpoint: []*gaia.UserRoleEndpoint{
5252
auth.NewUserRoleEndpoint("POST","/cattwo/:first/:second/start"),
5353
},
5454
},

‎handlers/permission.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/labstack/echo"
88
)
99

10-
//Simply retrievesa list of alluser role categories
10+
//PermissionGetAll simply returnsa list of allthe roles available.
1111
funcPermissionGetAll(c echo.Context)error {
1212
returnc.JSON(http.StatusOK,auth.DefaultUserRoles)
1313
}

‎handlers/user.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func UserAdd(c echo.Context) error {
192192
returnc.String(http.StatusCreated,"User has been added")
193193
}
194194

195+
// UserGetPermissions returns the permissions for a user.
195196
funcUserGetPermissions(c echo.Context)error {
196197
u:=c.Param("username")
197198
storeService,_:=services.StorageService()
@@ -202,6 +203,7 @@ func UserGetPermissions(c echo.Context) error {
202203
returnc.JSON(http.StatusOK,perms)
203204
}
204205

206+
// UserPutPermissions adds or updates permissions for a user.
205207
funcUserPutPermissions(c echo.Context)error {
206208
varperms*gaia.UserPermission
207209
iferr:=c.Bind(&perms);err!=nil {

‎handlers/user_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestUserLoginHMACKey(t *testing.T) {
5959
user:=&gaia.User{}
6060
err=json.Unmarshal(data,user)
6161
iferr!=nil {
62-
t.Fatalf("error unmarshalingresponce %v",err.Error())
62+
t.Fatalf("error unmarshalingresponse %v",err.Error())
6363
}
6464
token,_,err:=new(jwt.Parser).ParseUnverified(user.Tokenstring, jwt.MapClaims{})
6565
iferr!=nil {
@@ -112,7 +112,7 @@ func TestUserLoginRSAKey(t *testing.T) {
112112
user:=&gaia.User{}
113113
err=json.Unmarshal(data,user)
114114
iferr!=nil {
115-
t.Fatalf("error unmarshalingresponce %v",err.Error())
115+
t.Fatalf("error unmarshalingresponse %v",err.Error())
116116
}
117117
token,_,err:=new(jwt.Parser).ParseUnverified(user.Tokenstring, jwt.MapClaims{})
118118
iferr!=nil {

‎plugin/plugin.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (p *Plugin) Execute(j *gaia.Job) error {
205205
timeString:=time.Now().Format(timeFormat)
206206
p.writer.WriteString(fmt.Sprintf("%s Job '%s' threw an error: %s\n",timeString,j.Title,resultObj.Message))
207207
}elseiferr!=nil {
208-
// An erroroccured during the send or somewhere else.
208+
// An erroroccurred during the send or somewhere else.
209209
// The job itself usually does not return an error here.
210210
// We mark the job as failed.
211211
j.Status=gaia.JobFailed

‎plugin/plugin_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ func TestGetJobs(t *testing.T) {
130130

131131
funcTestRebuildDepTree(t*testing.T) {
132132
l:= []gaia.Job{
133-
gaia.Job{ID:12345},
134-
gaia.Job{ID:1234},
135-
gaia.Job{ID:123},
133+
{ID:12345},
134+
{ID:1234},
135+
{ID:123},
136136
}
137137
dep:= []uint32{1234,123}
138138
depTree:=rebuildDepTree(dep,l)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp