Exemplo n.º 1
0
func main() {
	flags.Parse(os.Args[1:])

	var err error
	var conf *config.Config

	//load configuration from either confFile or Env's CONFIG variable
	conf, err = config.New(*confFile, os.Getenv("CONFIG"))
	if err != nil {
		logme.Fatal(err)
	}

	//create a new Releasidier app.
	app, err := selfie.New(conf)
	if err != nil {
		logme.Fatal(err)
	}

	//start the selfie's App.
	//this will block until app stops, either by panic or exit signal
	app.Start()

	logme.Info("App is shutting down.")
	app.Exit()
}
Exemplo n.º 2
0
//New makes a new and setup releasifer app's settings
func New(conf *config.Config) (*selfie, error) {
	logme.Info("selfie started at " + conf.Server.Bind)

	app := &selfie{conf: conf}

	//setup security
	security.Setup(conf)

	//Start a new DB session
	_, err := data.NewDBWithConfig(conf)
	if err != nil {
		logme.Fatal(err)
	}

	return app, nil
}
Exemplo n.º 3
0
func uploadBundles(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	userID, _ := util.GetUserIDFromContext(ctx)
	appID, _ := util.GetParamValueAsID(ctx, "appID")
	releaseID, _ := util.GetParamValueAsID(ctx, "releaseID")

	//check if user has permission admin or owner
	if !data.DB.App.HasPermission(appID, userID, data.ADMIN, data.OWNER) {
		utils.RespondEx(w, nil, 0, internalErrors.ErrorAuthorizeAccess)
		return
	}

	if err := r.ParseMultipartForm(config.Conf.FileUpload.MaxSize); err != nil {
		utils.RespondEx(w, nil, 0, internalErrors.ErrorSomethingWentWrong)
		logme.Warn(err.Error())
		return
	}

	var fileInfos []*common.FileInfo
	var path string

	fileInfos = make([]*common.FileInfo, 0)

	//saving all the files into temp folder
	for _, fileHeaders := range r.MultipartForm.File {
		for _, fileHeader := range fileHeaders {
			file, _ := fileHeader.Open()
			path = config.Conf.FileUpload.Temp + uuid()
			if err := copyDataToFile(file, path); err != nil {
				utils.RespondEx(w, nil, 0, internalErrors.ErrorSomethingWentWrong)
				logme.Warn(err.Error())
				return
			}

			file.Close()

			hash, err := crypto.HashFile(path)
			if err != nil {
				utils.RespondEx(w, nil, 0, internalErrors.ErrorSomethingWentWrong)
				logme.Warn(err.Error())
				return
			}

			fileInfos = append(fileInfos, &common.FileInfo{
				Filename:     fileHeader.Filename,
				Hash:         hash,
				TempLocation: path,
			})
		}
	}

	bundles, err := data.DB.Bundle.UploadBundles(releaseID, appID, userID, fileInfos)

	if err != nil {
		logme.Warn(err.Error())
		//remove all temp files
		for _, fileInfo := range fileInfos {
			os.Remove(fileInfo.TempLocation)
		}
	} else {
		for _, fileInfo := range fileInfos {
			err = os.Rename(fileInfo.TempLocation, config.Conf.FileUpload.Bundle+fileInfo.Hash)
			logme.Info(fileInfo.TempLocation)
			if err != nil {
				logme.Warn(err.Error())
			}
		}
	}

	utils.RespondEx(w, bundles, 0, err)
}