|
| 1 | +package auth |
| 2 | + |
| 3 | +import "github.com/gaia-pipeline/gaia" |
| 4 | + |
| 5 | +// Constructor for creating new UserRoleEndpoints. |
| 6 | +func NewUserRoleEndpoint(method string, path string) *gaia.UserRoleEndpoint { |
| 7 | + return &gaia.UserRoleEndpoint{Path: path, Method: method} |
| 8 | +} |
| 9 | + |
| 10 | +// Creates a full user role name {category}{role}. |
| 11 | +func FullUserRoleName(category *gaia.UserRoleCategory, role *gaia.UserRole) string { |
| 12 | + return category.Name + role.Name |
| 13 | +} |
| 14 | + |
| 15 | +// Flattens the given user categories into a single slice of {category}{role}s. |
| 16 | +func FlattenUserCategoryRoles(cats []*gaia.UserRoleCategory) []string { |
| 17 | + var roles []string |
| 18 | + for _, category := range cats { |
| 19 | + for _, r := range category.Roles { |
| 20 | + roles = append(roles, FullUserRoleName(category, r)) |
| 21 | + } |
| 22 | + } |
| 23 | + return roles |
| 24 | +} |
| 25 | + |
| 26 | +var ( |
| 27 | + // All the default user categories and roles. |
| 28 | + DefaultUserRoles = []*gaia.UserRoleCategory{ |
| 29 | + { |
| 30 | + Name: "Pipeline", |
| 31 | + Description: "Managing and initiating pipelines.", |
| 32 | + Roles: []*gaia.UserRole{ |
| 33 | + { |
| 34 | + Name: "Create", |
| 35 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 36 | + NewUserRoleEndpoint("POST", "/api/v1/pipeline"), |
| 37 | + NewUserRoleEndpoint("POST", "/api/v1/pipeline/gitlsremote"), |
| 38 | + NewUserRoleEndpoint("GET", "/api/v1/pipeline/name"), |
| 39 | + NewUserRoleEndpoint("POST", "/api/v1/pipeline/githook"), |
| 40 | + }, |
| 41 | + Description: "Create new pipelines.", |
| 42 | + }, |
| 43 | + { |
| 44 | + Name: "List", |
| 45 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 46 | + NewUserRoleEndpoint("GET", "/api/v1/pipeline/created"), |
| 47 | + NewUserRoleEndpoint("GET", "/api/v1/pipeline"), |
| 48 | + NewUserRoleEndpoint("GET", "/api/v1/pipeline/latest"), |
| 49 | + }, |
| 50 | + Description: "List created pipelines.", |
| 51 | + }, |
| 52 | + { |
| 53 | + Name: "Get", |
| 54 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 55 | + NewUserRoleEndpoint("GET", "/api/v1/pipeline/:pipelineid"), |
| 56 | + }, |
| 57 | + Description: "Get created pipelines.", |
| 58 | + }, |
| 59 | + { |
| 60 | + Name: "Update", |
| 61 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 62 | + NewUserRoleEndpoint("PUT", "/api/v1/pipeline/:pipelineid"), |
| 63 | + }, |
| 64 | + Description: "Update created pipelines.", |
| 65 | + }, |
| 66 | + { |
| 67 | + Name: "Delete", |
| 68 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 69 | + NewUserRoleEndpoint("DELETE", "/api/v1/pipeline/:pipelineid"), |
| 70 | + }, |
| 71 | + Description: "Delete created pipelines.", |
| 72 | + }, |
| 73 | + { |
| 74 | + Name: "Start", |
| 75 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 76 | + NewUserRoleEndpoint("POST", "/api/v1/pipeline/:pipelineid/start"), |
| 77 | + }, |
| 78 | + Description: "Start created pipelines.", |
| 79 | + }, |
| 80 | + }, |
| 81 | + }, |
| 82 | + { |
| 83 | + Name: "PipelineRun", |
| 84 | + Description: "Managing of pipeline runs.", |
| 85 | + Roles: []*gaia.UserRole{ |
| 86 | + { |
| 87 | + Name: "Stop", |
| 88 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 89 | + NewUserRoleEndpoint("POST", "/api/v1/pipelinerun/:pipelineid/:runid/stop"), |
| 90 | + }, |
| 91 | + Description: "Stop running pipelines.", |
| 92 | + }, |
| 93 | + { |
| 94 | + Name: "Get", |
| 95 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 96 | + NewUserRoleEndpoint("GET", "/api/v1/pipelinerun/:pipelineid/:runid"), |
| 97 | + NewUserRoleEndpoint("GET", "/api/v1/pipelinerun/:pipelineid/latest"), |
| 98 | + }, |
| 99 | + Description: "Get pipeline runs.", |
| 100 | + }, |
| 101 | + { |
| 102 | + Name: "List", |
| 103 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 104 | + NewUserRoleEndpoint("GET", "pipelinerun/:pipelineid"), |
| 105 | + }, |
| 106 | + Description: "List pipeline runs.", |
| 107 | + }, |
| 108 | + { |
| 109 | + Name: "Logs", |
| 110 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 111 | + NewUserRoleEndpoint("GET", "/api/v1/pipelinerun/:pipelineid/:runid/latest"), |
| 112 | + }, |
| 113 | + Description: "Get logs for pipeline runs.", |
| 114 | + }, |
| 115 | + }, |
| 116 | + }, |
| 117 | + { |
| 118 | + Name: "Secret", |
| 119 | + Description: "Managing of stored secrets used within pipelines.", |
| 120 | + Roles: []*gaia.UserRole{ |
| 121 | + { |
| 122 | + Name: "List", |
| 123 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 124 | + NewUserRoleEndpoint("GET", "/api/v1/secrets"), |
| 125 | + }, |
| 126 | + Description: "List created secrets.", |
| 127 | + }, |
| 128 | + { |
| 129 | + Name: "Delete", |
| 130 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 131 | + NewUserRoleEndpoint("DELETE", "/api/v1/secret/:key"), |
| 132 | + }, |
| 133 | + Description: "Delete created secrets.", |
| 134 | + }, |
| 135 | + { |
| 136 | + Name: "Create", |
| 137 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 138 | + NewUserRoleEndpoint("POST", "/api/v1/secret"), |
| 139 | + }, |
| 140 | + Description: "Create new secrets.", |
| 141 | + }, |
| 142 | + { |
| 143 | + Name: "Update", |
| 144 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 145 | + NewUserRoleEndpoint("PUT", "/api/v1/secret/update"), |
| 146 | + }, |
| 147 | + Description: "Update created secrets.", |
| 148 | + }, |
| 149 | + }, |
| 150 | + }, |
| 151 | + { |
| 152 | + Name: "User", |
| 153 | + Description: "Managing of users.", |
| 154 | + Roles: []*gaia.UserRole{ |
| 155 | + { |
| 156 | + Name: "Create", |
| 157 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 158 | + NewUserRoleEndpoint("POST", "/api/v1/user"), |
| 159 | + }, |
| 160 | + Description: "Create new users.", |
| 161 | + }, |
| 162 | + { |
| 163 | + Name: "List", |
| 164 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 165 | + NewUserRoleEndpoint("GET", "/api/v1/users"), |
| 166 | + }, |
| 167 | + Description: "List created users.", |
| 168 | + }, |
| 169 | + { |
| 170 | + Name: "ChangePassword", |
| 171 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 172 | + NewUserRoleEndpoint("POST", "/api/v1/user/password"), |
| 173 | + }, |
| 174 | + Description: "Change created users passwords.", |
| 175 | + }, |
| 176 | + { |
| 177 | + Name: "Delete", |
| 178 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 179 | + NewUserRoleEndpoint("DELETE", "/api/v1/user/:username"), |
| 180 | + }, |
| 181 | + Description: "Delete created users.", |
| 182 | + }, |
| 183 | + }, |
| 184 | + }, |
| 185 | + { |
| 186 | + Name: "UserPermission", |
| 187 | + Description: "Managing of user permissions.", |
| 188 | + Roles: []*gaia.UserRole{ |
| 189 | + { |
| 190 | + Name: "Get", |
| 191 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 192 | + NewUserRoleEndpoint("GET", "/api/v1/user/:username/permissions"), |
| 193 | + }, |
| 194 | + Description: "Get created users permissions.", |
| 195 | + }, |
| 196 | + { |
| 197 | + Name: "Update", |
| 198 | + ApiEndpoint: []*gaia.UserRoleEndpoint{ |
| 199 | + NewUserRoleEndpoint("PUT", "/api/v1/user/:username/permissions"), |
| 200 | + }, |
| 201 | + Description: "Update created users permissions.", |
| 202 | + }, |
| 203 | + }, |
| 204 | + }, |
| 205 | + } |
| 206 | +) |
0 commit comments