* api: accept both ids or names in the same endpoint

Simplify api to accept both ids or names in the same endpoint
This commit is contained in:
Simone Gotti 2019-05-03 11:07:53 +02:00
parent 6943c10dc9
commit ea02eed2d9
21 changed files with 270 additions and 401 deletions

View File

@ -260,15 +260,9 @@ func (c *Client) DeleteProjectVariable(ctx context.Context, projectRef, variable
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/projects/%s/variables/%s", url.PathEscape(projectRef), variableName), nil, jsonContent, nil)
}
func (c *Client) GetUser(ctx context.Context, userID string) (*types.User, *http.Response, error) {
func (c *Client) GetUser(ctx context.Context, userRef string) (*types.User, *http.Response, error) {
user := new(types.User)
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/user/%s", userID), nil, jsonContent, nil, user)
return user, resp, err
}
func (c *Client) GetUserByName(ctx context.Context, userName string) (*types.User, *http.Response, error) {
user := new(types.User)
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/users/%s", userName), nil, jsonContent, nil, user)
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/users/%s", userRef), nil, jsonContent, nil, user)
return user, resp, err
}
@ -323,19 +317,19 @@ func (c *Client) CreateUser(ctx context.Context, req *CreateUserRequest) (*types
return user, resp, err
}
func (c *Client) UpdateUser(ctx context.Context, userID string, req *UpdateUserRequest) (*types.User, *http.Response, error) {
func (c *Client) UpdateUser(ctx context.Context, userRef string, req *UpdateUserRequest) (*types.User, *http.Response, error) {
reqj, err := json.Marshal(req)
if err != nil {
return nil, nil, err
}
user := new(types.User)
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/users/%s", userID), nil, jsonContent, bytes.NewReader(reqj), user)
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/users/%s", userRef), nil, jsonContent, bytes.NewReader(reqj), user)
return user, resp, err
}
func (c *Client) DeleteUser(ctx context.Context, userName string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/users/%s", userName), nil, jsonContent, nil)
func (c *Client) DeleteUser(ctx context.Context, userRef string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/users/%s", userRef), nil, jsonContent, nil)
}
func (c *Client) GetUsers(ctx context.Context, start string, limit int, asc bool) ([]*types.User, *http.Response, error) {
@ -355,56 +349,50 @@ func (c *Client) GetUsers(ctx context.Context, start string, limit int, asc bool
return users, resp, err
}
func (c *Client) CreateUserLA(ctx context.Context, userName string, req *CreateUserLARequest) (*types.LinkedAccount, *http.Response, error) {
func (c *Client) CreateUserLA(ctx context.Context, userRef string, req *CreateUserLARequest) (*types.LinkedAccount, *http.Response, error) {
reqj, err := json.Marshal(req)
if err != nil {
return nil, nil, err
}
la := new(types.LinkedAccount)
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/users/%s/linkedaccounts", userName), nil, jsonContent, bytes.NewReader(reqj), la)
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/users/%s/linkedaccounts", userRef), nil, jsonContent, bytes.NewReader(reqj), la)
return la, resp, err
}
func (c *Client) DeleteUserLA(ctx context.Context, userName, laID string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/users/%s/linkedaccounts/%s", userName, laID), nil, jsonContent, nil)
func (c *Client) DeleteUserLA(ctx context.Context, userRef, laID string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/users/%s/linkedaccounts/%s", userRef, laID), nil, jsonContent, nil)
}
func (c *Client) UpdateUserLA(ctx context.Context, userName, laID string, req *UpdateUserLARequest) (*types.LinkedAccount, *http.Response, error) {
func (c *Client) UpdateUserLA(ctx context.Context, userRef, laID string, req *UpdateUserLARequest) (*types.LinkedAccount, *http.Response, error) {
reqj, err := json.Marshal(req)
if err != nil {
return nil, nil, err
}
la := new(types.LinkedAccount)
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/users/%s/linkedaccounts/%s", userName, laID), nil, jsonContent, bytes.NewReader(reqj), la)
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/users/%s/linkedaccounts/%s", userRef, laID), nil, jsonContent, bytes.NewReader(reqj), la)
return la, resp, err
}
func (c *Client) CreateUserToken(ctx context.Context, userName string, req *CreateUserTokenRequest) (*CreateUserTokenResponse, *http.Response, error) {
func (c *Client) CreateUserToken(ctx context.Context, userRef string, req *CreateUserTokenRequest) (*CreateUserTokenResponse, *http.Response, error) {
reqj, err := json.Marshal(req)
if err != nil {
return nil, nil, err
}
tresp := new(CreateUserTokenResponse)
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/users/%s/tokens", userName), nil, jsonContent, bytes.NewReader(reqj), tresp)
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/users/%s/tokens", userRef), nil, jsonContent, bytes.NewReader(reqj), tresp)
return tresp, resp, err
}
func (c *Client) DeleteUserToken(ctx context.Context, userName, tokenName string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/users/%s/tokens/%s", userName, tokenName), nil, jsonContent, nil)
func (c *Client) DeleteUserToken(ctx context.Context, userRef, tokenName string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/users/%s/tokens/%s", userRef, tokenName), nil, jsonContent, nil)
}
func (c *Client) GetRemoteSource(ctx context.Context, rsID string) (*types.RemoteSource, *http.Response, error) {
func (c *Client) GetRemoteSource(ctx context.Context, rsRef string) (*types.RemoteSource, *http.Response, error) {
rs := new(types.RemoteSource)
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/remotesource/%s", rsID), nil, jsonContent, nil, rs)
return rs, resp, err
}
func (c *Client) GetRemoteSourceByName(ctx context.Context, rsName string) (*types.RemoteSource, *http.Response, error) {
rs := new(types.RemoteSource)
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/remotesources/%s", rsName), nil, jsonContent, nil, rs)
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/remotesources/%s", rsRef), nil, jsonContent, nil, rs)
return rs, resp, err
}
@ -436,8 +424,8 @@ func (c *Client) CreateRemoteSource(ctx context.Context, rs *types.RemoteSource)
return rs, resp, err
}
func (c *Client) DeleteRemoteSource(ctx context.Context, name string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/remotesources/%s", name), nil, jsonContent, nil)
func (c *Client) DeleteRemoteSource(ctx context.Context, rsRef string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/remotesources/%s", rsRef), nil, jsonContent, nil)
}
func (c *Client) CreateOrg(ctx context.Context, org *types.Organization) (*types.Organization, *http.Response, error) {
@ -451,8 +439,8 @@ func (c *Client) CreateOrg(ctx context.Context, org *types.Organization) (*types
return org, resp, err
}
func (c *Client) DeleteOrg(ctx context.Context, orgname string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/orgs/%s", orgname), nil, jsonContent, nil)
func (c *Client) DeleteOrg(ctx context.Context, orgRef string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/orgs/%s", orgRef), nil, jsonContent, nil)
}
func (c *Client) GetOrgs(ctx context.Context, start string, limit int, asc bool) ([]*types.Organization, *http.Response, error) {
@ -472,14 +460,8 @@ func (c *Client) GetOrgs(ctx context.Context, start string, limit int, asc bool)
return orgs, resp, err
}
func (c *Client) GetOrg(ctx context.Context, orgID string) (*types.Organization, *http.Response, error) {
func (c *Client) GetOrg(ctx context.Context, orgRef string) (*types.Organization, *http.Response, error) {
org := new(types.Organization)
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/org/%s", orgID), nil, jsonContent, nil, org)
return org, resp, err
}
func (c *Client) GetOrgByName(ctx context.Context, orgname string) (*types.Organization, *http.Response, error) {
org := new(types.Organization)
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/orgs/%s", orgname), nil, jsonContent, nil, org)
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/orgs/%s", orgRef), nil, jsonContent, nil, org)
return org, resp, err
}

View File

@ -41,12 +41,12 @@ func NewOrgHandler(logger *zap.Logger, readDB *readdb.ReadDB) *OrgHandler {
func (h *OrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
orgID := vars["orgid"]
orgRef := vars["orgref"]
var org *types.Organization
err := h.readDB.Do(func(tx *db.Tx) error {
var err error
org, err = h.readDB.GetOrg(tx, orgID)
org, err = h.readDB.GetOrg(tx, orgRef)
return err
})
if err != nil {
@ -56,42 +56,7 @@ func (h *OrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
if org == nil {
httpError(w, util.NewErrNotFound(errors.Errorf("org %q doesn't exist", orgID)))
return
}
if err := httpResponse(w, http.StatusOK, org); err != nil {
h.log.Errorf("err: %+v", err)
}
}
type OrgByNameHandler struct {
log *zap.SugaredLogger
readDB *readdb.ReadDB
}
func NewOrgByNameHandler(logger *zap.Logger, readDB *readdb.ReadDB) *OrgByNameHandler {
return &OrgByNameHandler{log: logger.Sugar(), readDB: readDB}
}
func (h *OrgByNameHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
orgName := vars["orgname"]
var org *types.Organization
err := h.readDB.Do(func(tx *db.Tx) error {
var err error
org, err = h.readDB.GetOrgByName(tx, orgName)
return err
})
if err != nil {
h.log.Errorf("err: %+v", err)
httpError(w, err)
return
}
if org == nil {
httpError(w, util.NewErrNotFound(errors.Errorf("org %q doesn't exist", orgName)))
httpError(w, util.NewErrNotFound(errors.Errorf("org %q doesn't exist", orgRef)))
return
}
@ -144,9 +109,9 @@ func (h *DeleteOrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
orgName := vars["orgname"]
orgRef := vars["orgref"]
err := h.ch.DeleteOrg(ctx, orgName)
err := h.ch.DeleteOrg(ctx, orgRef)
if httpError(w, err) {
h.log.Errorf("err: %+v", err)
}

View File

@ -23,7 +23,6 @@ import (
"github.com/pkg/errors"
"github.com/sorintlab/agola/internal/db"
"github.com/sorintlab/agola/internal/services/configstore/command"
"github.com/sorintlab/agola/internal/services/configstore/common"
"github.com/sorintlab/agola/internal/services/configstore/readdb"
"github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util"
@ -121,21 +120,10 @@ func (h *ProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
projectRefType, err := common.ParseRef(projectRef)
if err != nil {
httpError(w, util.NewErrBadRequest(err))
return
}
var project *types.Project
err = h.readDB.Do(func(tx *db.Tx) error {
var err error
switch projectRefType {
case common.RefTypeID:
project, err = h.readDB.GetProject(tx, projectRef)
case common.RefTypePath:
project, err = h.readDB.GetProjectByPath(tx, projectRef)
}
return err
})
if err != nil {

View File

@ -41,12 +41,12 @@ func NewRemoteSourceHandler(logger *zap.Logger, readDB *readdb.ReadDB) *RemoteSo
func (h *RemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
remoteSourceID := vars["id"]
rsRef := vars["remotesourceref"]
var remoteSource *types.RemoteSource
err := h.readDB.Do(func(tx *db.Tx) error {
var err error
remoteSource, err = h.readDB.GetRemoteSource(tx, remoteSourceID)
remoteSource, err = h.readDB.GetRemoteSource(tx, rsRef)
return err
})
if err != nil {
@ -56,42 +56,7 @@ func (h *RemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
}
if remoteSource == nil {
httpError(w, util.NewErrNotFound(errors.Errorf("remote source %q doesn't exist", remoteSourceID)))
return
}
if err := httpResponse(w, http.StatusOK, remoteSource); err != nil {
h.log.Errorf("err: %+v", err)
}
}
type RemoteSourceByNameHandler struct {
log *zap.SugaredLogger
readDB *readdb.ReadDB
}
func NewRemoteSourceByNameHandler(logger *zap.Logger, readDB *readdb.ReadDB) *RemoteSourceByNameHandler {
return &RemoteSourceByNameHandler{log: logger.Sugar(), readDB: readDB}
}
func (h *RemoteSourceByNameHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
remoteSourceName := vars["name"]
var remoteSource *types.RemoteSource
err := h.readDB.Do(func(tx *db.Tx) error {
var err error
remoteSource, err = h.readDB.GetRemoteSourceByName(tx, remoteSourceName)
return err
})
if err != nil {
h.log.Errorf("err: %+v", err)
httpError(w, err)
return
}
if remoteSource == nil {
httpError(w, util.NewErrNotFound(errors.Errorf("remote source %q doesn't exist", remoteSourceName)))
httpError(w, util.NewErrNotFound(errors.Errorf("remote source %q doesn't exist", rsRef)))
return
}
@ -144,9 +109,9 @@ func (h *DeleteRemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
ctx := r.Context()
vars := mux.Vars(r)
remoteSourceName := vars["name"]
rsRef := vars["remotesourceref"]
err := h.ch.DeleteRemoteSource(ctx, remoteSourceName)
err := h.ch.DeleteRemoteSource(ctx, rsRef)
if httpError(w, err) {
h.log.Errorf("err: %+v", err)
}

View File

@ -42,12 +42,12 @@ func NewUserHandler(logger *zap.Logger, readDB *readdb.ReadDB) *UserHandler {
func (h *UserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
userID := vars["userid"]
userRef := vars["userref"]
var user *types.User
err := h.readDB.Do(func(tx *db.Tx) error {
var err error
user, err = h.readDB.GetUser(tx, userID)
user, err = h.readDB.GetUser(tx, userRef)
return err
})
if err != nil {
@ -57,42 +57,7 @@ func (h *UserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
if user == nil {
httpError(w, util.NewErrNotFound(errors.Errorf("user %q doesn't exist", userID)))
return
}
if err := httpResponse(w, http.StatusOK, user); err != nil {
h.log.Errorf("err: %+v", err)
}
}
type UserByNameHandler struct {
log *zap.SugaredLogger
readDB *readdb.ReadDB
}
func NewUserByNameHandler(logger *zap.Logger, readDB *readdb.ReadDB) *UserByNameHandler {
return &UserByNameHandler{log: logger.Sugar(), readDB: readDB}
}
func (h *UserByNameHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
userName := vars["username"]
var user *types.User
err := h.readDB.Do(func(tx *db.Tx) error {
var err error
user, err = h.readDB.GetUserByName(tx, userName)
return err
})
if err != nil {
h.log.Errorf("err: %+v", err)
httpError(w, err)
return
}
if user == nil {
httpError(w, util.NewErrNotFound(errors.Errorf("user %q doesn't exist", userName)))
httpError(w, util.NewErrNotFound(errors.Errorf("user %q doesn't exist", userRef)))
return
}
@ -154,8 +119,6 @@ func (h *CreateUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
type UpdateUserRequest struct {
UserName string `json:"user_name"`
UpdateUserLARequest *UpdateUserLARequest `json:"create_user_la_request"`
}
type UpdateUserHandler struct {
@ -171,7 +134,7 @@ func (h *UpdateUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
userID := vars["userid"]
userRef := vars["userref"]
var req *UpdateUserRequest
d := json.NewDecoder(r.Body)
@ -181,7 +144,7 @@ func (h *UpdateUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
creq := &command.UpdateUserRequest{
UserID: userID,
UserRef: userRef,
UserName: req.UserName,
}
@ -209,9 +172,9 @@ func (h *DeleteUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
userName := vars["username"]
userRef := vars["userref"]
err := h.ch.DeleteUser(ctx, userName)
err := h.ch.DeleteUser(ctx, userRef)
if httpError(w, err) {
h.log.Errorf("err: %+v", err)
}
@ -366,7 +329,7 @@ func NewCreateUserLAHandler(logger *zap.Logger, ch *command.CommandHandler) *Cre
func (h *CreateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
userName := vars["username"]
userRef := vars["userref"]
var req CreateUserLARequest
d := json.NewDecoder(r.Body)
@ -376,7 +339,7 @@ func (h *CreateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
}
creq := &command.CreateUserLARequest{
UserName: userName,
UserRef: userRef,
RemoteSourceName: req.RemoteSourceName,
RemoteUserID: req.RemoteUserID,
RemoteUserName: req.RemoteUserName,
@ -408,10 +371,10 @@ func NewDeleteUserLAHandler(logger *zap.Logger, ch *command.CommandHandler) *Del
func (h *DeleteUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
userName := vars["username"]
userRef := vars["userref"]
laID := vars["laid"]
err := h.ch.DeleteUserLA(ctx, userName, laID)
err := h.ch.DeleteUserLA(ctx, userRef, laID)
if httpError(w, err) {
h.log.Errorf("err: %+v", err)
}
@ -441,7 +404,7 @@ func NewUpdateUserLAHandler(logger *zap.Logger, ch *command.CommandHandler) *Upd
func (h *UpdateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
userName := vars["username"]
userRef := vars["userref"]
linkedAccountID := vars["laid"]
var req UpdateUserLARequest
@ -452,7 +415,7 @@ func (h *UpdateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
}
creq := &command.UpdateUserLARequest{
UserName: userName,
UserRef: userRef,
LinkedAccountID: linkedAccountID,
RemoteUserID: req.RemoteUserID,
RemoteUserName: req.RemoteUserName,
@ -492,7 +455,7 @@ func NewCreateUserTokenHandler(logger *zap.Logger, ch *command.CommandHandler) *
func (h *CreateUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
userName := vars["username"]
userRef := vars["userref"]
var req CreateUserTokenRequest
d := json.NewDecoder(r.Body)
@ -501,7 +464,7 @@ func (h *CreateUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
return
}
token, err := h.ch.CreateUserToken(ctx, userName, req.TokenName)
token, err := h.ch.CreateUserToken(ctx, userRef, req.TokenName)
if httpError(w, err) {
h.log.Errorf("err: %+v", err)
return
@ -527,10 +490,10 @@ func NewDeleteUserTokenHandler(logger *zap.Logger, ch *command.CommandHandler) *
func (h *DeleteUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
userName := vars["username"]
userRef := vars["userref"]
tokenName := vars["tokenname"]
err := h.ch.DeleteUserToken(ctx, userName, tokenName)
err := h.ch.DeleteUserToken(ctx, userRef, tokenName)
if httpError(w, err) {
h.log.Errorf("err: %+v", err)
}

View File

@ -379,7 +379,7 @@ func (s *CommandHandler) CreateUser(ctx context.Context, req *CreateUserRequest)
return user, err
}
func (s *CommandHandler) DeleteUser(ctx context.Context, userName string) error {
func (s *CommandHandler) DeleteUser(ctx context.Context, userRef string) error {
var user *types.User
var cgt *datamanager.ChangeGroupsUpdateToken
@ -388,12 +388,12 @@ func (s *CommandHandler) DeleteUser(ctx context.Context, userName string) error
var err error
// check user existance
user, err = s.readDB.GetUserByName(tx, userName)
user, err = s.readDB.GetUser(tx, userRef)
if err != nil {
return err
}
if user == nil {
return util.NewErrBadRequest(errors.Errorf("user %q doesn't exist", userName))
return util.NewErrBadRequest(errors.Errorf("user %q doesn't exist", userRef))
}
// changegroup is the userid
@ -422,7 +422,7 @@ func (s *CommandHandler) DeleteUser(ctx context.Context, userName string) error
}
type UpdateUserRequest struct {
UserID string
UserRef string
UserName string
}
@ -436,12 +436,12 @@ func (s *CommandHandler) UpdateUser(ctx context.Context, req *UpdateUserRequest)
// must do all the check in a single transaction to avoid concurrent changes
err := s.readDB.Do(func(tx *db.Tx) error {
var err error
user, err = s.readDB.GetUserByName(tx, req.UserName)
user, err = s.readDB.GetUser(tx, req.UserRef)
if err != nil {
return err
}
if user == nil {
return util.NewErrBadRequest(errors.Errorf("user %q doesn't exist", req.UserName))
return util.NewErrBadRequest(errors.Errorf("user %q doesn't exist", req.UserRef))
}
cgt, err = s.readDB.GetChangeGroupsUpdateTokens(tx, cgNames)
@ -492,7 +492,8 @@ func (s *CommandHandler) UpdateUser(ctx context.Context, req *UpdateUserRequest)
}
type CreateUserLARequest struct {
UserName string
UserRef string
RemoteSourceName string
RemoteUserID string
RemoteUserName string
@ -503,8 +504,8 @@ type CreateUserLARequest struct {
}
func (s *CommandHandler) CreateUserLA(ctx context.Context, req *CreateUserLARequest) (*types.LinkedAccount, error) {
if req.UserName == "" {
return nil, util.NewErrBadRequest(errors.Errorf("user name required"))
if req.UserRef == "" {
return nil, util.NewErrBadRequest(errors.Errorf("user ref required"))
}
if req.RemoteSourceName == "" {
return nil, util.NewErrBadRequest(errors.Errorf("remote source name required"))
@ -518,12 +519,12 @@ func (s *CommandHandler) CreateUserLA(ctx context.Context, req *CreateUserLARequ
// must do all the check in a single transaction to avoid concurrent changes
err := s.readDB.Do(func(tx *db.Tx) error {
var err error
user, err = s.readDB.GetUserByName(tx, req.UserName)
user, err = s.readDB.GetUser(tx, req.UserRef)
if err != nil {
return err
}
if user == nil {
return util.NewErrBadRequest(errors.Errorf("user %q doesn't exist", req.UserName))
return util.NewErrBadRequest(errors.Errorf("user %q doesn't exist", req.UserRef))
}
// changegroup is the userid
@ -588,9 +589,9 @@ func (s *CommandHandler) CreateUserLA(ctx context.Context, req *CreateUserLARequ
return la, err
}
func (s *CommandHandler) DeleteUserLA(ctx context.Context, userName, laID string) error {
if userName == "" {
return util.NewErrBadRequest(errors.Errorf("user name required"))
func (s *CommandHandler) DeleteUserLA(ctx context.Context, userRef, laID string) error {
if userRef == "" {
return util.NewErrBadRequest(errors.Errorf("user ref required"))
}
if laID == "" {
return util.NewErrBadRequest(errors.Errorf("user linked account id required"))
@ -603,12 +604,12 @@ func (s *CommandHandler) DeleteUserLA(ctx context.Context, userName, laID string
// must do all the check in a single transaction to avoid concurrent changes
err := s.readDB.Do(func(tx *db.Tx) error {
var err error
user, err = s.readDB.GetUserByName(tx, userName)
user, err = s.readDB.GetUser(tx, userRef)
if err != nil {
return err
}
if user == nil {
return util.NewErrBadRequest(errors.Errorf("user %q doesn't exist", userName))
return util.NewErrBadRequest(errors.Errorf("user %q doesn't exist", userRef))
}
// changegroup is the userid
@ -626,7 +627,7 @@ func (s *CommandHandler) DeleteUserLA(ctx context.Context, userName, laID string
_, ok := user.LinkedAccounts[laID]
if !ok {
return util.NewErrBadRequest(errors.Errorf("linked account id %q for user %q doesn't exist", laID, userName))
return util.NewErrBadRequest(errors.Errorf("linked account id %q for user %q doesn't exist", laID, userRef))
}
delete(user.LinkedAccounts, laID)
@ -649,7 +650,8 @@ func (s *CommandHandler) DeleteUserLA(ctx context.Context, userName, laID string
}
type UpdateUserLARequest struct {
UserName string
UserRef string
LinkedAccountID string
RemoteUserID string
RemoteUserName string
@ -660,8 +662,8 @@ type UpdateUserLARequest struct {
}
func (s *CommandHandler) UpdateUserLA(ctx context.Context, req *UpdateUserLARequest) (*types.LinkedAccount, error) {
if req.UserName == "" {
return nil, util.NewErrBadRequest(errors.Errorf("user name required"))
if req.UserRef == "" {
return nil, util.NewErrBadRequest(errors.Errorf("user ref required"))
}
var user *types.User
@ -672,12 +674,12 @@ func (s *CommandHandler) UpdateUserLA(ctx context.Context, req *UpdateUserLARequ
// must do all the check in a single transaction to avoid concurrent changes
err := s.readDB.Do(func(tx *db.Tx) error {
var err error
user, err = s.readDB.GetUserByName(tx, req.UserName)
user, err = s.readDB.GetUser(tx, req.UserRef)
if err != nil {
return err
}
if user == nil {
return util.NewErrBadRequest(errors.Errorf("user %q doesn't exist", req.UserName))
return util.NewErrBadRequest(errors.Errorf("user %q doesn't exist", req.UserRef))
}
// changegroup is the userid
@ -731,9 +733,9 @@ func (s *CommandHandler) UpdateUserLA(ctx context.Context, req *UpdateUserLARequ
return la, err
}
func (s *CommandHandler) CreateUserToken(ctx context.Context, userName, tokenName string) (string, error) {
if userName == "" {
return "", util.NewErrBadRequest(errors.Errorf("user name required"))
func (s *CommandHandler) CreateUserToken(ctx context.Context, userRef, tokenName string) (string, error) {
if userRef == "" {
return "", util.NewErrBadRequest(errors.Errorf("user ref required"))
}
if tokenName == "" {
return "", util.NewErrBadRequest(errors.Errorf("token name required"))
@ -746,12 +748,12 @@ func (s *CommandHandler) CreateUserToken(ctx context.Context, userName, tokenNam
// must do all the check in a single transaction to avoid concurrent changes
err := s.readDB.Do(func(tx *db.Tx) error {
var err error
user, err = s.readDB.GetUserByName(tx, userName)
user, err = s.readDB.GetUser(tx, userRef)
if err != nil {
return err
}
if user == nil {
return util.NewErrBadRequest(errors.Errorf("user %q doesn't exist", userName))
return util.NewErrBadRequest(errors.Errorf("user %q doesn't exist", userRef))
}
// changegroup is the userid
@ -768,7 +770,7 @@ func (s *CommandHandler) CreateUserToken(ctx context.Context, userName, tokenNam
}
if user.Tokens != nil {
if _, ok := user.Tokens[tokenName]; ok {
return "", util.NewErrBadRequest(errors.Errorf("token %q for user %q already exists", tokenName, userName))
return "", util.NewErrBadRequest(errors.Errorf("token %q for user %q already exists", tokenName, userRef))
}
}
@ -796,9 +798,9 @@ func (s *CommandHandler) CreateUserToken(ctx context.Context, userName, tokenNam
return token, err
}
func (s *CommandHandler) DeleteUserToken(ctx context.Context, userName, tokenName string) error {
if userName == "" {
return util.NewErrBadRequest(errors.Errorf("user name required"))
func (s *CommandHandler) DeleteUserToken(ctx context.Context, userRef, tokenName string) error {
if userRef == "" {
return util.NewErrBadRequest(errors.Errorf("user ref required"))
}
if tokenName == "" {
return util.NewErrBadRequest(errors.Errorf("token name required"))
@ -811,12 +813,12 @@ func (s *CommandHandler) DeleteUserToken(ctx context.Context, userName, tokenNam
// must do all the check in a single transaction to avoid concurrent changes
err := s.readDB.Do(func(tx *db.Tx) error {
var err error
user, err = s.readDB.GetUserByName(tx, userName)
user, err = s.readDB.GetUser(tx, userRef)
if err != nil {
return err
}
if user == nil {
return util.NewErrBadRequest(errors.Errorf("user %q doesn't exist", userName))
return util.NewErrBadRequest(errors.Errorf("user %q doesn't exist", userRef))
}
// changegroup is the userid
@ -834,7 +836,7 @@ func (s *CommandHandler) DeleteUserToken(ctx context.Context, userName, tokenNam
_, ok := user.Tokens[tokenName]
if !ok {
return util.NewErrBadRequest(errors.Errorf("token %q for user %q doesn't exist", tokenName, userName))
return util.NewErrBadRequest(errors.Errorf("token %q for user %q doesn't exist", tokenName, userRef))
}
delete(user.Tokens, tokenName)
@ -1016,37 +1018,38 @@ func (s *CommandHandler) CreateOrg(ctx context.Context, org *types.Organization)
return org, err
}
func (s *CommandHandler) DeleteOrg(ctx context.Context, orgName string) error {
func (s *CommandHandler) DeleteOrg(ctx context.Context, orgRef string) error {
var org *types.Organization
var projects []*types.Project
var cgt *datamanager.ChangeGroupsUpdateToken
// changegroup is the org id
cgNames := []string{util.EncodeSha256Hex("orgid-" + org.ID)}
// must do all the check in a single transaction to avoid concurrent changes
err := s.readDB.Do(func(tx *db.Tx) error {
var err error
// check org existance
org, err = s.readDB.GetOrgByName(tx, orgRef)
if err != nil {
return err
}
if org == nil {
return util.NewErrBadRequest(errors.Errorf("org %q doesn't exist", orgRef))
}
// changegroup is the org id
cgNames := []string{util.EncodeSha256Hex("orgid-" + org.ID)}
cgt, err = s.readDB.GetChangeGroupsUpdateTokens(tx, cgNames)
if err != nil {
return err
}
// check org existance
org, err = s.readDB.GetOrgByName(tx, orgName)
if err != nil {
return err
}
if org == nil {
return util.NewErrBadRequest(errors.Errorf("org %q doesn't exist", orgName))
}
// TODO(sgotti) delete all project groups, projects etc...
return nil
})
if err != nil {
return err
}
// TODO(sgotti) delete all project groups, projects etc...
actions := []*datamanager.Action{
{
ActionType: datamanager.ActionTypeDelete,

View File

@ -17,6 +17,8 @@ package common
import (
"net/url"
"strings"
uuid "github.com/satori/go.uuid"
)
const (
@ -28,17 +30,27 @@ type RefType int
const (
RefTypeID RefType = iota
RefTypePath
RefTypeName
)
// ParseRef parses the api call to determine if the provided ref is
// an ID or a path
func ParseRef(projectRef string) (RefType, error) {
projectRef, err := url.PathUnescape(projectRef)
func ParsePathRef(ref string) (RefType, error) {
ref, err := url.PathUnescape(ref)
if err != nil {
return -1, err
}
if strings.Contains(projectRef, "/") {
if strings.Contains(ref, "/") {
return RefTypePath, nil
}
return RefTypeID, nil
}
// ParseRef parses the api call to determine if the provided ref is
// an ID or a name
func ParseNameRef(ref string) (RefType, error) {
if _, err := uuid.FromString(ref); err == nil {
return RefTypeID, nil
}
return RefTypeName, nil
}

View File

@ -143,7 +143,6 @@ func (s *ConfigStore) Run(ctx context.Context) error {
userHandler := api.NewUserHandler(logger, s.readDB)
usersHandler := api.NewUsersHandler(logger, s.readDB)
userByNameHandler := api.NewUserByNameHandler(logger, s.readDB)
createUserHandler := api.NewCreateUserHandler(logger, s.ch)
updateUserHandler := api.NewUpdateUserHandler(logger, s.ch)
deleteUserHandler := api.NewDeleteUserHandler(logger, s.ch)
@ -157,13 +156,11 @@ func (s *ConfigStore) Run(ctx context.Context) error {
orgHandler := api.NewOrgHandler(logger, s.readDB)
orgsHandler := api.NewOrgsHandler(logger, s.readDB)
orgByNameHandler := api.NewOrgByNameHandler(logger, s.readDB)
createOrgHandler := api.NewCreateOrgHandler(logger, s.ch)
deleteOrgHandler := api.NewDeleteOrgHandler(logger, s.ch)
remoteSourceHandler := api.NewRemoteSourceHandler(logger, s.readDB)
remoteSourcesHandler := api.NewRemoteSourcesHandler(logger, s.readDB)
remoteSourceByNameHandler := api.NewRemoteSourceByNameHandler(logger, s.readDB)
createRemoteSourceHandler := api.NewCreateRemoteSourceHandler(logger, s.ch)
deleteRemoteSourceHandler := api.NewDeleteRemoteSourceHandler(logger, s.ch)
@ -193,30 +190,27 @@ func (s *ConfigStore) Run(ctx context.Context) error {
apirouter.Handle("/projectgroups/{projectgroupref}/variables/{variablename}", deleteVariableHandler).Methods("DELETE")
apirouter.Handle("/projects/{projectref}/variables/{variablename}", deleteVariableHandler).Methods("DELETE")
apirouter.Handle("/user/{userid}", userHandler).Methods("GET")
apirouter.Handle("/users/{userref}", userHandler).Methods("GET")
apirouter.Handle("/users", usersHandler).Methods("GET")
apirouter.Handle("/users", createUserHandler).Methods("POST")
apirouter.Handle("/users/{username}", userByNameHandler).Methods("GET")
apirouter.Handle("/users/{userid}", updateUserHandler).Methods("PUT")
apirouter.Handle("/users/{username}", deleteUserHandler).Methods("DELETE")
apirouter.Handle("/users/{userref}", updateUserHandler).Methods("PUT")
apirouter.Handle("/users/{userref}", deleteUserHandler).Methods("DELETE")
apirouter.Handle("/users/{username}/linkedaccounts", createUserLAHandler).Methods("POST")
apirouter.Handle("/users/{username}/linkedaccounts/{laid}", deleteUserLAHandler).Methods("DELETE")
apirouter.Handle("/users/{username}/linkedaccounts/{laid}", updateUserLAHandler).Methods("PUT")
apirouter.Handle("/users/{username}/tokens", createUserTokenHandler).Methods("POST")
apirouter.Handle("/users/{username}/tokens/{tokenname}", deleteUserTokenHandler).Methods("DELETE")
apirouter.Handle("/users/{userref}/linkedaccounts", createUserLAHandler).Methods("POST")
apirouter.Handle("/users/{userref}/linkedaccounts/{laid}", deleteUserLAHandler).Methods("DELETE")
apirouter.Handle("/users/{userref}/linkedaccounts/{laid}", updateUserLAHandler).Methods("PUT")
apirouter.Handle("/users/{userref}/tokens", createUserTokenHandler).Methods("POST")
apirouter.Handle("/users/{userref}/tokens/{tokenname}", deleteUserTokenHandler).Methods("DELETE")
apirouter.Handle("/org/{orgid}", orgHandler).Methods("GET")
apirouter.Handle("/orgs/{orgref}", orgHandler).Methods("GET")
apirouter.Handle("/orgs", orgsHandler).Methods("GET")
apirouter.Handle("/orgs", createOrgHandler).Methods("POST")
apirouter.Handle("/orgs/{orgname}", orgByNameHandler).Methods("GET")
apirouter.Handle("/orgs/{orgname}", deleteOrgHandler).Methods("DELETE")
apirouter.Handle("/orgs/{orgref}", deleteOrgHandler).Methods("DELETE")
apirouter.Handle("/remotesource/{id}", remoteSourceHandler).Methods("GET")
apirouter.Handle("/remotesources/{remotesourceref}", remoteSourceHandler).Methods("GET")
apirouter.Handle("/remotesources", remoteSourcesHandler).Methods("GET")
apirouter.Handle("/remotesources", createRemoteSourceHandler).Methods("POST")
apirouter.Handle("/remotesources/{name}", remoteSourceByNameHandler).Methods("GET")
apirouter.Handle("/remotesources/{name}", deleteRemoteSourceHandler).Methods("DELETE")
apirouter.Handle("/remotesources/{remotesourceref}", deleteRemoteSourceHandler).Methods("DELETE")
mainrouter := mux.NewRouter()
mainrouter.PathPrefix("/").Handler(corsHandler(router))

View File

@ -19,6 +19,7 @@ import (
"encoding/json"
"github.com/sorintlab/agola/internal/db"
"github.com/sorintlab/agola/internal/services/configstore/common"
"github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util"
@ -59,7 +60,23 @@ func (r *ReadDB) deleteOrg(tx *db.Tx, orgID string) error {
return nil
}
func (r *ReadDB) GetOrg(tx *db.Tx, orgID string) (*types.Organization, error) {
func (r *ReadDB) GetOrg(tx *db.Tx, orgRef string) (*types.Organization, error) {
refType, err := common.ParseNameRef(orgRef)
if err != nil {
return nil, err
}
var org *types.Organization
switch refType {
case common.RefTypeID:
org, err = r.GetOrgByID(tx, orgRef)
case common.RefTypeName:
org, err = r.GetOrgByName(tx, orgRef)
}
return org, err
}
func (r *ReadDB) GetOrgByID(tx *db.Tx, orgID string) (*types.Organization, error) {
q, args, err := orgSelect.Where(sq.Eq{"id": orgID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil {

View File

@ -79,7 +79,7 @@ func (r *ReadDB) GetProjectPath(tx *db.Tx, project *types.Project) (string, erro
}
func (r *ReadDB) GetProject(tx *db.Tx, projectRef string) (*types.Project, error) {
projectRefType, err := common.ParseRef(projectRef)
projectRefType, err := common.ParsePathRef(projectRef)
if err != nil {
return nil, err
}

View File

@ -135,7 +135,7 @@ func (r *ReadDB) GetProjectGroupPath(tx *db.Tx, group *types.ProjectGroup) (stri
}
func (r *ReadDB) GetProjectGroup(tx *db.Tx, projectGroupRef string) (*types.ProjectGroup, error) {
groupRef, err := common.ParseRef(projectGroupRef)
groupRef, err := common.ParsePathRef(projectGroupRef)
if err != nil {
return nil, err
}

View File

@ -19,6 +19,7 @@ import (
"encoding/json"
"github.com/sorintlab/agola/internal/db"
"github.com/sorintlab/agola/internal/services/configstore/common"
"github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util"
@ -56,7 +57,23 @@ func (r *ReadDB) deleteRemoteSource(tx *db.Tx, id string) error {
return nil
}
func (r *ReadDB) GetRemoteSource(tx *db.Tx, remoteSourceID string) (*types.RemoteSource, error) {
func (r *ReadDB) GetRemoteSource(tx *db.Tx, rsRef string) (*types.RemoteSource, error) {
refType, err := common.ParseNameRef(rsRef)
if err != nil {
return nil, err
}
var rs *types.RemoteSource
switch refType {
case common.RefTypeID:
rs, err = r.GetRemoteSourceByID(tx, rsRef)
case common.RefTypeName:
rs, err = r.GetRemoteSourceByName(tx, rsRef)
}
return rs, err
}
func (r *ReadDB) GetRemoteSourceByID(tx *db.Tx, remoteSourceID string) (*types.RemoteSource, error) {
q, args, err := remotesourceSelect.Where(sq.Eq{"id": remoteSourceID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil {

View File

@ -19,6 +19,7 @@ import (
"encoding/json"
"github.com/sorintlab/agola/internal/db"
"github.com/sorintlab/agola/internal/services/configstore/common"
"github.com/sorintlab/agola/internal/services/types"
"github.com/sorintlab/agola/internal/util"
@ -146,7 +147,23 @@ func (r *ReadDB) deleteUserToken(tx *db.Tx, tokenValue string) error {
return nil
}
func (r *ReadDB) GetUser(tx *db.Tx, userID string) (*types.User, error) {
func (r *ReadDB) GetUser(tx *db.Tx, userRef string) (*types.User, error) {
refType, err := common.ParseNameRef(userRef)
if err != nil {
return nil, err
}
var user *types.User
switch refType {
case common.RefTypeID:
user, err = r.GetUserByID(tx, userRef)
case common.RefTypeName:
user, err = r.GetUserByName(tx, userRef)
}
return user, err
}
func (r *ReadDB) GetUserByID(tx *db.Tx, userID string) (*types.User, error) {
q, args, err := userSelect.Where(sq.Eq{"id": userID}).ToSql()
r.log.Debugf("q: %s, args: %s", q, util.Dump(args))
if err != nil {

View File

@ -229,9 +229,9 @@ func (c *Client) GetCurrentUser(ctx context.Context) (*UserResponse, *http.Respo
return user, resp, err
}
func (c *Client) GetUser(ctx context.Context, userID string) (*UserResponse, *http.Response, error) {
func (c *Client) GetUser(ctx context.Context, userRef string) (*UserResponse, *http.Response, error) {
user := new(UserResponse)
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/user/%s", userID), nil, jsonContent, nil, user)
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/users/%s", userRef), nil, jsonContent, nil, user)
return user, resp, err
}
@ -263,23 +263,23 @@ func (c *Client) CreateUser(ctx context.Context, req *CreateUserRequest) (*UserR
return user, resp, err
}
func (c *Client) DeleteUser(ctx context.Context, userName string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/users/%s", userName), nil, jsonContent, nil)
func (c *Client) DeleteUser(ctx context.Context, userRef string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/users/%s", userRef), nil, jsonContent, nil)
}
func (c *Client) CreateUserLA(ctx context.Context, userName string, req *CreateUserLARequest) (*CreateUserLAResponse, *http.Response, error) {
func (c *Client) CreateUserLA(ctx context.Context, userRef string, req *CreateUserLARequest) (*CreateUserLAResponse, *http.Response, error) {
reqj, err := json.Marshal(req)
if err != nil {
return nil, nil, err
}
la := new(CreateUserLAResponse)
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/users/%s/linkedaccounts", userName), nil, jsonContent, bytes.NewReader(reqj), la)
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/users/%s/linkedaccounts", userRef), nil, jsonContent, bytes.NewReader(reqj), la)
return la, resp, err
}
func (c *Client) DeleteUserLA(ctx context.Context, userName, laID string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/users/%s/linkedaccounts/%s", userName, laID), nil, jsonContent, nil)
func (c *Client) DeleteUserLA(ctx context.Context, userRef, laID string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/users/%s/linkedaccounts/%s", userRef, laID), nil, jsonContent, nil)
}
func (c *Client) RegisterUser(ctx context.Context, req *RegisterUserRequest) (*RegisterUserResponse, *http.Response, error) {
@ -293,19 +293,19 @@ func (c *Client) RegisterUser(ctx context.Context, req *RegisterUserRequest) (*R
return res, resp, err
}
func (c *Client) CreateUserToken(ctx context.Context, userName string, req *CreateUserTokenRequest) (*CreateUserTokenResponse, *http.Response, error) {
func (c *Client) CreateUserToken(ctx context.Context, userRef string, req *CreateUserTokenRequest) (*CreateUserTokenResponse, *http.Response, error) {
reqj, err := json.Marshal(req)
if err != nil {
return nil, nil, err
}
tresp := new(CreateUserTokenResponse)
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/users/%s/tokens", userName), nil, jsonContent, bytes.NewReader(reqj), tresp)
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/users/%s/tokens", userRef), nil, jsonContent, bytes.NewReader(reqj), tresp)
return tresp, resp, err
}
func (c *Client) DeleteUserToken(ctx context.Context, userName, tokenName string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/users/%s/tokens/%s", userName, tokenName), nil, jsonContent, nil)
func (c *Client) DeleteUserToken(ctx context.Context, userRef, tokenName string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/users/%s/tokens/%s", userRef, tokenName), nil, jsonContent, nil)
}
func (c *Client) GetRun(ctx context.Context, runID string) (*RunResponse, *http.Response, error) {
@ -340,9 +340,9 @@ func (c *Client) GetRuns(ctx context.Context, phaseFilter, groups, runGroups []s
return getRunsResponse, resp, err
}
func (c *Client) GetRemoteSource(ctx context.Context, rsID string) (*RemoteSourceResponse, *http.Response, error) {
func (c *Client) GetRemoteSource(ctx context.Context, rsRef string) (*RemoteSourceResponse, *http.Response, error) {
rs := new(RemoteSourceResponse)
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/remotesource/%s", rsID), nil, jsonContent, nil, rs)
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/remotesources/%s", rsRef), nil, jsonContent, nil, rs)
return rs, resp, err
}
@ -374,8 +374,8 @@ func (c *Client) CreateRemoteSource(ctx context.Context, req *CreateRemoteSource
return rs, resp, err
}
func (c *Client) DeleteRemoteSource(ctx context.Context, name string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/remotesources/%s", name), nil, jsonContent, nil)
func (c *Client) DeleteRemoteSource(ctx context.Context, rsRef string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/remotesources/%s", rsRef), nil, jsonContent, nil)
}
func (c *Client) CreateOrg(ctx context.Context, req *CreateOrgRequest) (*OrgResponse, *http.Response, error) {
@ -389,6 +389,6 @@ func (c *Client) CreateOrg(ctx context.Context, req *CreateOrgRequest) (*OrgResp
return org, resp, err
}
func (c *Client) DeleteOrg(ctx context.Context, orgName string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/orgs/%s", orgName), nil, jsonContent, nil)
func (c *Client) DeleteOrg(ctx context.Context, orgRef string) (*http.Response, error) {
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/orgs/%s", orgRef), nil, jsonContent, nil)
}

View File

@ -80,9 +80,9 @@ func NewDeleteOrgHandler(logger *zap.Logger, configstoreClient *csapi.Client) *D
func (h *DeleteOrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
orgName := vars["orgname"]
orgRef := vars["orgref"]
resp, err := h.configstoreClient.DeleteOrg(ctx, orgName)
resp, err := h.configstoreClient.DeleteOrg(ctx, orgRef)
if httpErrorFromRemote(w, resp, err) {
h.log.Errorf("err: %+v", err)
return
@ -105,35 +105,9 @@ func NewOrgHandler(logger *zap.Logger, configstoreClient *csapi.Client) *OrgHand
func (h *OrgHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
orgID := vars["orgid"]
orgRef := vars["orgref"]
org, resp, err := h.configstoreClient.GetOrg(ctx, orgID)
if httpErrorFromRemote(w, resp, err) {
h.log.Errorf("err: %+v", err)
return
}
res := createOrgResponse(org)
if err := httpResponse(w, http.StatusOK, res); err != nil {
h.log.Errorf("err: %+v", err)
}
}
type OrgByNameHandler struct {
log *zap.SugaredLogger
configstoreClient *csapi.Client
}
func NewOrgByNameHandler(logger *zap.Logger, configstoreClient *csapi.Client) *OrgByNameHandler {
return &OrgByNameHandler{log: logger.Sugar(), configstoreClient: configstoreClient}
}
func (h *OrgByNameHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
orgName := vars["orgname"]
org, resp, err := h.configstoreClient.GetOrgByName(ctx, orgName)
org, resp, err := h.configstoreClient.GetOrg(ctx, orgRef)
if httpErrorFromRemote(w, resp, err) {
h.log.Errorf("err: %+v", err)
return

View File

@ -55,7 +55,7 @@ func NewUserRemoteReposHandler(logger *zap.Logger, ch *command.CommandHandler, c
func (h *UserRemoteReposHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
remoteSourceID := vars["remotesourceid"]
remoteSourceRef := vars["remotesourceref"]
userIDVal := ctx.Value("userid")
if userIDVal == nil {
@ -71,7 +71,7 @@ func (h *UserRemoteReposHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
return
}
rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, remoteSourceID)
rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, remoteSourceRef)
if httpErrorFromRemote(w, resp, err) {
h.log.Errorf("err: %+v", err)
return

View File

@ -104,9 +104,9 @@ func NewRemoteSourceHandler(logger *zap.Logger, configstoreClient *csapi.Client)
func (h *RemoteSourceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
rsID := vars["id"]
rsRef := vars["remotesourceref"]
rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, rsID)
rs, resp, err := h.configstoreClient.GetRemoteSource(ctx, rsRef)
if httpErrorFromRemote(w, resp, err) {
h.log.Errorf("err: %+v", err)
return

View File

@ -83,9 +83,9 @@ func NewDeleteUserHandler(logger *zap.Logger, configstoreClient *csapi.Client) *
func (h *DeleteUserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
userName := vars["username"]
userRef := vars["userref"]
resp, err := h.configstoreClient.DeleteUser(ctx, userName)
resp, err := h.configstoreClient.DeleteUser(ctx, userRef)
if httpErrorFromRemote(w, resp, err) {
h.log.Errorf("err: %+v", err)
return
@ -139,35 +139,9 @@ func NewUserHandler(logger *zap.Logger, configstoreClient *csapi.Client) *UserHa
func (h *UserHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
userID := vars["userid"]
userRef := vars["userref"]
user, resp, err := h.configstoreClient.GetUser(ctx, userID)
if httpErrorFromRemote(w, resp, err) {
h.log.Errorf("err: %+v", err)
return
}
res := createUserResponse(user)
if err := httpResponse(w, http.StatusOK, res); err != nil {
h.log.Errorf("err: %+v", err)
}
}
type UserByNameHandler struct {
log *zap.SugaredLogger
configstoreClient *csapi.Client
}
func NewUserByNameHandler(logger *zap.Logger, configstoreClient *csapi.Client) *UserByNameHandler {
return &UserByNameHandler{log: logger.Sugar(), configstoreClient: configstoreClient}
}
func (h *UserByNameHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
userName := vars["username"]
user, resp, err := h.configstoreClient.GetUserByName(ctx, userName)
user, resp, err := h.configstoreClient.GetUser(ctx, userRef)
if httpErrorFromRemote(w, resp, err) {
h.log.Errorf("err: %+v", err)
return
@ -288,7 +262,7 @@ func NewCreateUserLAHandler(logger *zap.Logger, ch *command.CommandHandler) *Cre
func (h *CreateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
userName := vars["username"]
userRef := vars["userref"]
var req *CreateUserLARequest
d := json.NewDecoder(r.Body)
@ -297,7 +271,7 @@ func (h *CreateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
return
}
res, err := h.createUserLA(ctx, userName, req)
res, err := h.createUserLA(ctx, userRef, req)
if httpError(w, err) {
h.log.Errorf("err: %+v", err)
return
@ -308,9 +282,9 @@ func (h *CreateUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
}
}
func (h *CreateUserLAHandler) createUserLA(ctx context.Context, userName string, req *CreateUserLARequest) (*CreateUserLAResponse, error) {
func (h *CreateUserLAHandler) createUserLA(ctx context.Context, userRef string, req *CreateUserLARequest) (*CreateUserLAResponse, error) {
creq := &command.CreateUserLARequest{
UserName: userName,
UserRef: userRef,
RemoteSourceName: req.RemoteSourceName,
}
@ -329,7 +303,7 @@ func (h *CreateUserLAHandler) createUserLA(ctx context.Context, userName string,
resp := &CreateUserLAResponse{
LinkedAccount: authresp.LinkedAccount,
}
h.log.Infof("linked account %q for user %q created", resp.LinkedAccount.ID, userName)
h.log.Infof("linked account %q for user %q created", resp.LinkedAccount.ID, userRef)
return resp, nil
}
@ -345,10 +319,10 @@ func NewDeleteUserLAHandler(logger *zap.Logger, configstoreClient *csapi.Client)
func (h *DeleteUserLAHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
userName := vars["username"]
userRef := vars["userref"]
laID := vars["laid"]
resp, err := h.configstoreClient.DeleteUserLA(ctx, userName, laID)
resp, err := h.configstoreClient.DeleteUserLA(ctx, userRef, laID)
if httpErrorFromRemote(w, resp, err) {
h.log.Errorf("err: %+v", err)
return
@ -379,7 +353,7 @@ func NewCreateUserTokenHandler(logger *zap.Logger, ch *command.CommandHandler) *
func (h *CreateUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
userName := vars["username"]
userRef := vars["userref"]
var req CreateUserTokenRequest
d := json.NewDecoder(r.Body)
@ -389,10 +363,10 @@ func (h *CreateUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
}
creq := &command.CreateUserTokenRequest{
UserName: userName,
UserRef: userRef,
TokenName: req.TokenName,
}
h.log.Infof("creating user %q token", userName)
h.log.Infof("creating user %q token", userRef)
token, err := h.ch.CreateUserToken(ctx, creq)
if httpError(w, err) {
h.log.Errorf("err: %+v", err)
@ -420,11 +394,11 @@ func NewDeleteUserTokenHandler(logger *zap.Logger, configstoreClient *csapi.Clie
func (h *DeleteUserTokenHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
userName := vars["username"]
userRef := vars["userref"]
tokenName := vars["tokenname"]
h.log.Infof("deleting user %q token %q", userName, tokenName)
resp, err := h.configstoreClient.DeleteUserToken(ctx, userName, tokenName)
h.log.Infof("deleting user %q token %q", userRef, tokenName)
resp, err := h.configstoreClient.DeleteUserToken(ctx, userRef, tokenName)
if httpErrorFromRemote(w, resp, err) {
h.log.Errorf("err: %+v", err)
return

View File

@ -53,7 +53,7 @@ func (c *CommandHandler) CreateProject(ctx context.Context, req *CreateProjectRe
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", req.CurrentUserID))
}
rs, resp, err := c.configstoreClient.GetRemoteSourceByName(ctx, req.RemoteSourceName)
rs, resp, err := c.configstoreClient.GetRemoteSource(ctx, req.RemoteSourceName)
if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", req.RemoteSourceName))
}

View File

@ -67,7 +67,7 @@ func (c *CommandHandler) CreateUser(ctx context.Context, req *CreateUserRequest)
}
type CreateUserTokenRequest struct {
UserName string
UserRef string
TokenName string
}
@ -84,8 +84,8 @@ func (c *CommandHandler) CreateUserToken(ctx context.Context, req *CreateUserTok
isAdmin = isAdminVal.(bool)
}
userName := req.UserName
user, resp, err := c.configstoreClient.GetUserByName(ctx, userName)
userRef := req.UserRef
user, resp, err := c.configstoreClient.GetUser(ctx, userRef)
if err != nil {
return "", ErrFromRemote(resp, errors.Wrapf(err, "failed to get user"))
}
@ -95,24 +95,25 @@ func (c *CommandHandler) CreateUserToken(ctx context.Context, req *CreateUserTok
return "", util.NewErrBadRequest(errors.Errorf("logged in user cannot create token for another user"))
}
if _, ok := user.Tokens[req.TokenName]; ok {
return "", util.NewErrBadRequest(errors.Errorf("user %q already have a token with name %q", userName, req.TokenName))
return "", util.NewErrBadRequest(errors.Errorf("user %q already have a token with name %q", userRef, req.TokenName))
}
c.log.Infof("creating user token")
creq := &csapi.CreateUserTokenRequest{
TokenName: req.TokenName,
}
res, resp, err := c.configstoreClient.CreateUserToken(ctx, userName, creq)
res, resp, err := c.configstoreClient.CreateUserToken(ctx, userRef, creq)
if err != nil {
return "", ErrFromRemote(resp, errors.Wrapf(err, "failed to create user token"))
}
c.log.Infof("token %q for user %q created", req.TokenName, userName)
c.log.Infof("token %q for user %q created", req.TokenName, userRef)
return res.Token, nil
}
type CreateUserLARequest struct {
UserName string
UserRef string
RemoteSourceName string
UserAccessToken string
Oauth2AccessToken string
@ -121,12 +122,12 @@ type CreateUserLARequest struct {
}
func (c *CommandHandler) CreateUserLA(ctx context.Context, req *CreateUserLARequest) (*types.LinkedAccount, error) {
userName := req.UserName
user, resp, err := c.configstoreClient.GetUserByName(ctx, userName)
userRef := req.UserRef
user, resp, err := c.configstoreClient.GetUser(ctx, userRef)
if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", userName))
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", userRef))
}
rs, resp, err := c.configstoreClient.GetRemoteSourceByName(ctx, req.RemoteSourceName)
rs, resp, err := c.configstoreClient.GetRemoteSource(ctx, req.RemoteSourceName)
if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", req.RemoteSourceName))
}
@ -140,7 +141,7 @@ func (c *CommandHandler) CreateUserLA(ctx context.Context, req *CreateUserLARequ
}
c.log.Infof("la: %s", util.Dump(la))
if la != nil {
return nil, util.NewErrBadRequest(errors.Errorf("user %q already have a linked account for remote source %q", userName, rs.Name))
return nil, util.NewErrBadRequest(errors.Errorf("user %q already have a linked account for remote source %q", userRef, rs.Name))
}
accessToken, err := common.GetAccessToken(rs, req.UserAccessToken, req.Oauth2AccessToken)
@ -171,19 +172,19 @@ func (c *CommandHandler) CreateUserLA(ctx context.Context, req *CreateUserLARequ
}
c.log.Infof("creating linked account")
la, resp, err = c.configstoreClient.CreateUserLA(ctx, userName, creq)
la, resp, err = c.configstoreClient.CreateUserLA(ctx, userRef, creq)
if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to create linked account"))
}
c.log.Infof("linked account %q for user %q created", la.ID, userName)
c.log.Infof("linked account %q for user %q created", la.ID, userRef)
return la, nil
}
func (c *CommandHandler) UpdateUserLA(ctx context.Context, userName string, la *types.LinkedAccount) error {
user, resp, err := c.configstoreClient.GetUserByName(ctx, userName)
func (c *CommandHandler) UpdateUserLA(ctx context.Context, userRef string, la *types.LinkedAccount) error {
user, resp, err := c.configstoreClient.GetUser(ctx, userRef)
if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", userName))
return ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", userRef))
}
laFound := false
for _, ula := range user.LinkedAccounts {
@ -194,7 +195,7 @@ func (c *CommandHandler) UpdateUserLA(ctx context.Context, userName string, la *
}
c.log.Infof("la: %s", util.Dump(la))
if !laFound {
return util.NewErrBadRequest(errors.Errorf("user %q doesn't have a linked account with id %q", userName, la.ID))
return util.NewErrBadRequest(errors.Errorf("user %q doesn't have a linked account with id %q", userRef, la.ID))
}
creq := &csapi.UpdateUserLARequest{
@ -206,12 +207,12 @@ func (c *CommandHandler) UpdateUserLA(ctx context.Context, userName string, la *
Oauth2AccessTokenExpiresAt: la.Oauth2AccessTokenExpiresAt,
}
c.log.Infof("updating user %q linked account", userName)
la, resp, err = c.configstoreClient.UpdateUserLA(ctx, userName, la.ID, creq)
c.log.Infof("updating user %q linked account", userRef)
la, resp, err = c.configstoreClient.UpdateUserLA(ctx, userRef, la.ID, creq)
if err != nil {
return ErrFromRemote(resp, errors.Wrapf(err, "failed to update user"))
}
c.log.Infof("linked account %q for user %q updated", la.ID, userName)
c.log.Infof("linked account %q for user %q updated", la.ID, userRef)
return nil
}
@ -272,7 +273,7 @@ func (c *CommandHandler) RegisterUser(ctx context.Context, req *RegisterUserRequ
return nil, util.NewErrBadRequest(errors.Errorf("invalid user name %q", req.UserName))
}
rs, resp, err := c.configstoreClient.GetRemoteSourceByName(ctx, req.RemoteSourceName)
rs, resp, err := c.configstoreClient.GetRemoteSource(ctx, req.RemoteSourceName)
if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", req.RemoteSourceName))
}
@ -332,7 +333,7 @@ type LoginUserResponse struct {
}
func (c *CommandHandler) LoginUser(ctx context.Context, req *LoginUserRequest) (*LoginUserResponse, error) {
rs, resp, err := c.configstoreClient.GetRemoteSourceByName(ctx, req.RemoteSourceName)
rs, resp, err := c.configstoreClient.GetRemoteSource(ctx, req.RemoteSourceName)
if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", req.RemoteSourceName))
}
@ -423,7 +424,7 @@ type AuthorizeResponse struct {
}
func (c *CommandHandler) Authorize(ctx context.Context, req *AuthorizeRequest) (*AuthorizeResponse, error) {
rs, resp, err := c.configstoreClient.GetRemoteSourceByName(ctx, req.RemoteSourceName)
rs, resp, err := c.configstoreClient.GetRemoteSource(ctx, req.RemoteSourceName)
if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", req.RemoteSourceName))
}
@ -458,7 +459,7 @@ type RemoteSourceAuthResponse struct {
}
func (c *CommandHandler) HandleRemoteSourceAuth(ctx context.Context, remoteSourceName, loginName, loginPassword string, requestType RemoteSourceRequestType, req interface{}) (*RemoteSourceAuthResponse, error) {
rs, resp, err := c.configstoreClient.GetRemoteSourceByName(ctx, remoteSourceName)
rs, resp, err := c.configstoreClient.GetRemoteSource(ctx, remoteSourceName)
if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", remoteSourceName))
}
@ -467,9 +468,9 @@ func (c *CommandHandler) HandleRemoteSourceAuth(ctx context.Context, remoteSourc
switch requestType {
case RemoteSourceRequestTypeCreateUserLA:
req := req.(*CreateUserLARequest)
user, resp, err := c.configstoreClient.GetUserByName(ctx, req.UserName)
user, resp, err := c.configstoreClient.GetUser(ctx, req.UserRef)
if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", req.UserName))
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get user %q", req.UserRef))
}
var la *types.LinkedAccount
for _, v := range user.LinkedAccounts {
@ -480,7 +481,7 @@ func (c *CommandHandler) HandleRemoteSourceAuth(ctx context.Context, remoteSourc
}
c.log.Infof("la: %s", util.Dump(la))
if la != nil {
return nil, util.NewErrBadRequest(errors.Errorf("user %q already have a linked account for remote source %q", req.UserName, rs.Name))
return nil, util.NewErrBadRequest(errors.Errorf("user %q already have a linked account for remote source %q", req.UserRef, rs.Name))
}
case RemoteSourceRequestTypeLoginUser:
@ -568,7 +569,7 @@ func (c *CommandHandler) HandleRemoteSourceAuthRequest(ctx context.Context, requ
}
creq := &CreateUserLARequest{
UserName: req.UserName,
UserRef: req.UserRef,
RemoteSourceName: req.RemoteSourceName,
UserAccessToken: userAccessToken,
Oauth2AccessToken: oauth2AccessToken,
@ -686,7 +687,7 @@ func (c *CommandHandler) HandleOauth2Callback(ctx context.Context, code, state s
requestType := RemoteSourceRequestType(claims["request_type"].(string))
requestString := claims["request"].(string)
rs, resp, err := c.configstoreClient.GetRemoteSourceByName(ctx, remoteSourceName)
rs, resp, err := c.configstoreClient.GetRemoteSource(ctx, remoteSourceName)
if err != nil {
return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", remoteSourceName))
}

View File

@ -168,7 +168,6 @@ func (g *Gateway) Run(ctx context.Context) error {
currentUserHandler := api.NewCurrentUserHandler(logger, g.configstoreClient)
userHandler := api.NewUserHandler(logger, g.configstoreClient)
userByNameHandler := api.NewUserByNameHandler(logger, g.configstoreClient)
usersHandler := api.NewUsersHandler(logger, g.configstoreClient)
createUserHandler := api.NewCreateUserHandler(logger, g.ch)
deleteUserHandler := api.NewDeleteUserHandler(logger, g.configstoreClient)
@ -183,7 +182,6 @@ func (g *Gateway) Run(ctx context.Context) error {
remoteSourcesHandler := api.NewRemoteSourcesHandler(logger, g.configstoreClient)
orgHandler := api.NewOrgHandler(logger, g.configstoreClient)
orgByNameHandler := api.NewOrgByNameHandler(logger, g.configstoreClient)
orgsHandler := api.NewOrgsHandler(logger, g.configstoreClient)
createOrgHandler := api.NewCreateOrgHandler(logger, g.ch)
deleteOrgHandler := api.NewDeleteOrgHandler(logger, g.configstoreClient)
@ -242,26 +240,24 @@ func (g *Gateway) Run(ctx context.Context) error {
apirouter.Handle("/projects/{projectref}/variables/{variablename}", authForcedHandler(deleteVariableHandler)).Methods("DELETE")
apirouter.Handle("/user", authForcedHandler(currentUserHandler)).Methods("GET")
apirouter.Handle("/user/{userid}", authForcedHandler(userHandler)).Methods("GET")
apirouter.Handle("/users/{userref}", authForcedHandler(userHandler)).Methods("GET")
apirouter.Handle("/users", authForcedHandler(usersHandler)).Methods("GET")
apirouter.Handle("/users", authForcedHandler(createUserHandler)).Methods("POST")
apirouter.Handle("/users/{username}", authForcedHandler(userByNameHandler)).Methods("GET")
apirouter.Handle("/users/{username}", authForcedHandler(deleteUserHandler)).Methods("DELETE")
apirouter.Handle("/users/{userref}", authForcedHandler(deleteUserHandler)).Methods("DELETE")
apirouter.Handle("/users/{username}/linkedaccounts", authForcedHandler(createUserLAHandler)).Methods("POST")
apirouter.Handle("/users/{username}/linkedaccounts/{laid}", authForcedHandler(deleteUserLAHandler)).Methods("DELETE")
apirouter.Handle("/users/{username}/tokens", authForcedHandler(createUserTokenHandler)).Methods("POST")
apirouter.Handle("/users/{username}/tokens/{tokenname}", authForcedHandler(deleteUserTokenHandler)).Methods("DELETE")
apirouter.Handle("/users/{userref}/linkedaccounts", authForcedHandler(createUserLAHandler)).Methods("POST")
apirouter.Handle("/users/{userref}/linkedaccounts/{laid}", authForcedHandler(deleteUserLAHandler)).Methods("DELETE")
apirouter.Handle("/users/{userref}/tokens", authForcedHandler(createUserTokenHandler)).Methods("POST")
apirouter.Handle("/users/{userref}/tokens/{tokenname}", authForcedHandler(deleteUserTokenHandler)).Methods("DELETE")
apirouter.Handle("/remotesource/{id}", authForcedHandler(remoteSourceHandler)).Methods("GET")
apirouter.Handle("/remotesources/{remotesourceref}", authForcedHandler(remoteSourceHandler)).Methods("GET")
apirouter.Handle("/remotesources", authForcedHandler(createRemoteSourceHandler)).Methods("POST")
apirouter.Handle("/remotesources", authOptionalHandler(remoteSourcesHandler)).Methods("GET")
apirouter.Handle("/org/{orgid}", authForcedHandler(orgHandler)).Methods("GET")
apirouter.Handle("/orgs/{orgref}", authForcedHandler(orgHandler)).Methods("GET")
apirouter.Handle("/orgs", authForcedHandler(orgsHandler)).Methods("GET")
apirouter.Handle("/orgs", authForcedHandler(createOrgHandler)).Methods("POST")
apirouter.Handle("/orgs/{orgname}", authForcedHandler(orgByNameHandler)).Methods("GET")
apirouter.Handle("/orgs/{orgname}", authForcedHandler(deleteOrgHandler)).Methods("DELETE")
apirouter.Handle("/orgs/{orgref}", authForcedHandler(deleteOrgHandler)).Methods("DELETE")
apirouter.Handle("/runs/{runid}", authForcedHandler(runHandler)).Methods("GET")
apirouter.Handle("/runs/{runid}/actions", authForcedHandler(runActionsHandler)).Methods("PUT")
@ -269,9 +265,10 @@ func (g *Gateway) Run(ctx context.Context) error {
apirouter.Handle("/runs/{runid}/tasks/{taskid}/actions", runTaskActionsHandler).Methods("PUT")
apirouter.Handle("/runs", authForcedHandler(runsHandler)).Methods("GET")
// TODO(sgotti) add auth to these requests
router.Handle("/repos/{rest:.*}", reposHandler).Methods("GET", "POST")
apirouter.Handle("/user/remoterepos/{remotesourceid}", authForcedHandler(userRemoteReposHandler)).Methods("GET")
apirouter.Handle("/user/remoterepos/{remotesourceref}", authForcedHandler(userRemoteReposHandler)).Methods("GET")
router.Handle("/login", loginUserHandler).Methods("POST")
router.Handle("/authorize", authorizeHandler).Methods("POST")