Best Syzkaller code snippet using config.LoadData
root.go
Source:root.go
...42 defaultLogMaxAge = 2843 defaultLogCompress = false44 defaultLogVerbose = true45 defaultLogUTCTime = false46 defaultLoadDataFrom = ""47 defaultLoadDataMode = 148 defaultLoadDataQuotaScan = 049 defaultLoadDataClean = false50)51var (52 configDir string53 configFile string54 logFilePath string55 logMaxSize int56 logMaxBackups int57 logMaxAge int58 logCompress bool59 logVerbose bool60 logUTCTime bool61 loadDataFrom string62 loadDataMode int63 loadDataQuotaScan int64 loadDataClean bool65 rootCmd = &cobra.Command{66 Use: "sftpgo",67 Short: "Fully featured and highly configurable SFTP server",68 }69)70func init() {71 rootCmd.CompletionOptions.DisableDefaultCmd = true72 rootCmd.Flags().BoolP("version", "v", false, "")73 rootCmd.Version = version.GetAsString()74 rootCmd.SetVersionTemplate(`{{printf "SFTPGo "}}{{printf "%s" .Version}}75`)76}77// Execute adds all child commands to the root command and sets flags appropriately.78// This is called by main.main(). It only needs to happen once to the rootCmd.79func Execute() {80 if err := rootCmd.Execute(); err != nil {81 fmt.Println(err)82 os.Exit(1)83 }84}85func addConfigFlags(cmd *cobra.Command) {86 viper.SetDefault(configDirKey, defaultConfigDir)87 viper.BindEnv(configDirKey, "SFTPGO_CONFIG_DIR") //nolint:errcheck // err is not nil only if the key to bind is missing88 cmd.Flags().StringVarP(&configDir, configDirFlag, "c", viper.GetString(configDirKey),89 `Location for the config dir. This directory90is used as the base for files with a relative91path, eg. the private keys for the SFTP92server or the SQLite database if you use93SQLite as data provider.94The configuration file, if not explicitly set,95is looked for in this dir. We support reading96from JSON, TOML, YAML, HCL, envfile and Java97properties config files. The default config98file name is "sftpgo" and therefore99"sftpgo.json", "sftpgo.yaml" and so on are100searched.101This flag can be set using SFTPGO_CONFIG_DIR102env var too.`)103 viper.BindPFlag(configDirKey, cmd.Flags().Lookup(configDirFlag)) //nolint:errcheck104 viper.SetDefault(configFileKey, defaultConfigFile)105 viper.BindEnv(configFileKey, "SFTPGO_CONFIG_FILE") //nolint:errcheck106 cmd.Flags().StringVar(&configFile, configFileFlag, viper.GetString(configFileKey),107 `Path to SFTPGo configuration file.108This flag explicitly defines the path, name109and extension of the config file. If must be110an absolute path or a path relative to the111configuration directory. The specified file112name must have a supported extension (JSON,113YAML, TOML, HCL or Java properties).114This flag can be set using SFTPGO_CONFIG_FILE115env var too.`)116 viper.BindPFlag(configFileKey, cmd.Flags().Lookup(configFileFlag)) //nolint:errcheck117}118func addBaseLoadDataFlags(cmd *cobra.Command) {119 viper.SetDefault(loadDataFromKey, defaultLoadDataFrom)120 viper.BindEnv(loadDataFromKey, "SFTPGO_LOADDATA_FROM") //nolint:errcheck121 cmd.Flags().StringVar(&loadDataFrom, loadDataFromFlag, viper.GetString(loadDataFromKey),122 `Load users and folders from this file.123The file must be specified as absolute path124and it must contain a backup obtained using125the "dumpdata" REST API or compatible content.126This flag can be set using SFTPGO_LOADDATA_FROM127env var too.128`)129 viper.BindPFlag(loadDataFromKey, cmd.Flags().Lookup(loadDataFromFlag)) //nolint:errcheck130 viper.SetDefault(loadDataModeKey, defaultLoadDataMode)131 viper.BindEnv(loadDataModeKey, "SFTPGO_LOADDATA_MODE") //nolint:errcheck132 cmd.Flags().IntVar(&loadDataMode, loadDataModeFlag, viper.GetInt(loadDataModeKey),133 `Restore mode for data to load:134 0 - new users are added, existing users are135 updated136 1 - New users are added, existing users are137 not modified138This flag can be set using SFTPGO_LOADDATA_MODE139env var too.140`)141 viper.BindPFlag(loadDataModeKey, cmd.Flags().Lookup(loadDataModeFlag)) //nolint:errcheck142 viper.SetDefault(loadDataCleanKey, defaultLoadDataClean)143 viper.BindEnv(loadDataCleanKey, "SFTPGO_LOADDATA_CLEAN") //nolint:errcheck144 cmd.Flags().BoolVar(&loadDataClean, loadDataCleanFlag, viper.GetBool(loadDataCleanKey),145 `Determine if the loaddata-from file should146be removed after a successful load. This flag147can be set using SFTPGO_LOADDATA_CLEAN env var148too. (default "false")149`)150 viper.BindPFlag(loadDataCleanKey, cmd.Flags().Lookup(loadDataCleanFlag)) //nolint:errcheck151}152func addServeFlags(cmd *cobra.Command) {153 addConfigFlags(cmd)154 viper.SetDefault(logFilePathKey, defaultLogFile)155 viper.BindEnv(logFilePathKey, "SFTPGO_LOG_FILE_PATH") //nolint:errcheck156 cmd.Flags().StringVarP(&logFilePath, logFilePathFlag, "l", viper.GetString(logFilePathKey),157 `Location for the log file. Leave empty to write158logs to the standard output. This flag can be159set using SFTPGO_LOG_FILE_PATH env var too.160`)161 viper.BindPFlag(logFilePathKey, cmd.Flags().Lookup(logFilePathFlag)) //nolint:errcheck162 viper.SetDefault(logMaxSizeKey, defaultLogMaxSize)163 viper.BindEnv(logMaxSizeKey, "SFTPGO_LOG_MAX_SIZE") //nolint:errcheck164 cmd.Flags().IntVarP(&logMaxSize, logMaxSizeFlag, "s", viper.GetInt(logMaxSizeKey),165 `Maximum size in megabytes of the log file166before it gets rotated. This flag can be set167using SFTPGO_LOG_MAX_SIZE env var too. It is168unused if log-file-path is empty.169`)170 viper.BindPFlag(logMaxSizeKey, cmd.Flags().Lookup(logMaxSizeFlag)) //nolint:errcheck171 viper.SetDefault(logMaxBackupKey, defaultLogMaxBackup)172 viper.BindEnv(logMaxBackupKey, "SFTPGO_LOG_MAX_BACKUPS") //nolint:errcheck173 cmd.Flags().IntVarP(&logMaxBackups, "log-max-backups", "b", viper.GetInt(logMaxBackupKey),174 `Maximum number of old log files to retain.175This flag can be set using SFTPGO_LOG_MAX_BACKUPS176env var too. It is unused if log-file-path is177empty.`)178 viper.BindPFlag(logMaxBackupKey, cmd.Flags().Lookup(logMaxBackupFlag)) //nolint:errcheck179 viper.SetDefault(logMaxAgeKey, defaultLogMaxAge)180 viper.BindEnv(logMaxAgeKey, "SFTPGO_LOG_MAX_AGE") //nolint:errcheck181 cmd.Flags().IntVarP(&logMaxAge, "log-max-age", "a", viper.GetInt(logMaxAgeKey),182 `Maximum number of days to retain old log files.183This flag can be set using SFTPGO_LOG_MAX_AGE env184var too. It is unused if log-file-path is empty.185`)186 viper.BindPFlag(logMaxAgeKey, cmd.Flags().Lookup(logMaxAgeFlag)) //nolint:errcheck187 viper.SetDefault(logCompressKey, defaultLogCompress)188 viper.BindEnv(logCompressKey, "SFTPGO_LOG_COMPRESS") //nolint:errcheck189 cmd.Flags().BoolVarP(&logCompress, logCompressFlag, "z", viper.GetBool(logCompressKey),190 `Determine if the rotated log files191should be compressed using gzip. This flag can192be set using SFTPGO_LOG_COMPRESS env var too.193It is unused if log-file-path is empty.194`)195 viper.BindPFlag(logCompressKey, cmd.Flags().Lookup(logCompressFlag)) //nolint:errcheck196 viper.SetDefault(logVerboseKey, defaultLogVerbose)197 viper.BindEnv(logVerboseKey, "SFTPGO_LOG_VERBOSE") //nolint:errcheck198 cmd.Flags().BoolVarP(&logVerbose, logVerboseFlag, "v", viper.GetBool(logVerboseKey),199 `Enable verbose logs. This flag can be set200using SFTPGO_LOG_VERBOSE env var too.201`)202 viper.BindPFlag(logVerboseKey, cmd.Flags().Lookup(logVerboseFlag)) //nolint:errcheck203 viper.SetDefault(logUTCTimeKey, defaultLogUTCTime)204 viper.BindEnv(logUTCTimeKey, "SFTPGO_LOG_UTC_TIME") //nolint:errcheck205 cmd.Flags().BoolVar(&logUTCTime, logUTCTimeFlag, viper.GetBool(logUTCTimeKey),206 `Use UTC time for logging. This flag can be set207using SFTPGO_LOG_UTC_TIME env var too.208`)209 viper.BindPFlag(logUTCTimeKey, cmd.Flags().Lookup(logUTCTimeFlag)) //nolint:errcheck210 addBaseLoadDataFlags(cmd)211 viper.SetDefault(loadDataQuotaScanKey, defaultLoadDataQuotaScan)212 viper.BindEnv(loadDataQuotaScanKey, "SFTPGO_LOADDATA_QUOTA_SCAN") //nolint:errcheck213 cmd.Flags().IntVar(&loadDataQuotaScan, loadDataQuotaScanFlag, viper.GetInt(loadDataQuotaScanKey),214 `Quota scan mode after data load:215 0 - no quota scan216 1 - scan quota217 2 - scan quota if the user has quota restrictions218This flag can be set using SFTPGO_LOADDATA_QUOTA_SCAN219env var too.220(default 0)`)221 viper.BindPFlag(loadDataQuotaScanKey, cmd.Flags().Lookup(loadDataQuotaScanFlag)) //nolint:errcheck222}...
1442ebceb36269abf540d3d402408a87f6dd21a0store.go
Source:1442ebceb36269abf540d3d402408a87f6dd21a0store.go
...13const (14 LoadNotFound = 40415 LoadAlreadyExist = 40316)17func Path(loadData domain.LoadData) string {18 return pathById(loadData.ID)19}20func pathById(loadId string) string {21 return config.DataPath + "/" + loadId22}23func Create(loadName, loadTag string) (loadData domain.LoadData, errApp *domain.AppError) {24 // check if already exist25 _, appErr := findByNameTag(loadName, loadTag)26 if appErr == nil || appErr.Code != LoadNotFound {27 return domain.LoadData{}, &domain.AppError{nil, "Load with this tag already exist.", LoadAlreadyExist}28 }29 var loadId string30 var loadDataPath string31 // create id and folder32 for {33 c := 634 b := make([]byte, c)35 _, err := rand.Read(b)36 if err != nil {37 return domain.LoadData{}, &domain.AppError{nil, "Error when create dockloadId", 500}38 }39 loadId = hex.EncodeToString(b)40 loadDataPath = pathById(loadId)41 if _, err := os.Stat(loadDataPath); os.IsNotExist(err) {42 // path/to/whatever does not exist43 break44 }45 }46 err := os.MkdirAll(loadDataPath, config.DataPathMode)47 if err != nil {48 return domain.LoadData{}, &domain.AppError{err, "Error creating dockload folder", 500}49 }50 loadData = domain.LoadData{51 ID: loadId,52 Name: loadName,53 Tag: loadTag,54 }55 appErr = Save(loadData)56 if appErr != nil {57 return domain.LoadData{}, appErr58 }59 return loadData, nil60}61func Save(loadData domain.LoadData) *domain.AppError {62 if loadData.ID == "" {63 return &domain.AppError{nil, "Invalid dockloadId", 400}64 }65 loadDataJson := config.DataPath + "/" + loadData.ID + ".json"66 outJson, err := os.Create(loadDataJson)67 if err != nil {68 return &domain.AppError{err, "Failed to create data file", 500}69 }70 defer outJson.Close()71 enc := json.NewEncoder(outJson)72 enc.Encode(loadData)73 return nil74}75func List() ([]domain.LoadData, *domain.AppError) {76 l := list.New()77 files, _ := ioutil.ReadDir(config.DataPath)78 for _, f := range files {79 if f.IsDir() {80 l.PushBack(f.Name())81 }82 }83 var loadRecords = make([]domain.LoadData, l.Len())84 idx := 085 for e := l.Front(); e != nil; e = e.Next() {86 loadId := e.Value.(string)87 inJson, err := os.Open(config.DataPath + "/" + loadId + ".json")88 if err != nil {89 return []domain.LoadData{}, &domain.AppError{err, "Error opening data store", 500}90 }91 defer inJson.Close()92 decode := json.NewDecoder(inJson)93 var loadData domain.LoadData94 err = decode.Decode(&loadData)95 if err != nil {96 return []domain.LoadData{}, &domain.AppError{err, "Error opening data store", 500}97 }98 loadRecords[idx] = loadData99 idx += 1100 }101 return loadRecords, nil102}103// find docloadId by dockloadId, name and version104// tag can be in the form:105// 123456789012106// test107// test:1108// test:*109func Find(query string) (domain.LoadData, *domain.AppError) {110 nameOrId := query111 tag := ""112 querySplit := strings.Split(query, ":")113 if len(querySplit) > 1 {114 nameOrId = querySplit[0]115 tag = querySplit[1]116 }117 return findByNameTag(nameOrId, tag)118}119func findByNameTag(nameOrId, tag string) (domain.LoadData, *domain.AppError) {120 loadRecords, appErr := List()121 if appErr != nil {122 return domain.LoadData{}, appErr123 }124 for _, loadRecord := range loadRecords {125 if loadRecord.ID == nameOrId {126 return loadRecord, nil127 } else if loadRecord.Name == nameOrId {128 // TODO add support to remove all load with same name, we should return a list of matching loaddata129 //if tag == "*" {130 // return loadRecord, nil131 if loadRecord.Tag == tag {132 return loadRecord, nil133 }134 }135 }136 return domain.LoadData{}, &domain.AppError{nil, "Load not found.", LoadNotFound}137}...
store.go
Source:store.go
...13const (14 LoadNotFound = 40415 LoadAlreadyExist = 40316)17func Path(loadData domain.LoadData) string {18 return pathById(loadData.ID)19}20func pathById(loadId string) string {21 return config.DataPath + "/" + loadId22}23func Create(loadName, loadTag string) (loadData domain.LoadData, errApp *domain.AppError) {24 // check if already exist25 _, appErr := findByNameTag(loadName, loadTag)26 if appErr == nil || appErr.Code != LoadNotFound {27 return domain.LoadData{}, &domain.AppError{nil, "Load with this tag already exist.", LoadAlreadyExist}28 }29 var loadId string30 var loadDataPath string31 // create id and folder32 for {33 c := 634 b := make([]byte, c)35 _, err := rand.Read(b)36 if err != nil {37 return domain.LoadData{}, &domain.AppError{nil, "Error when create dockloadId", 500}38 }39 loadId = hex.EncodeToString(b)40 loadDataPath = pathById(loadId)41 if _, err := os.Stat(loadDataPath); os.IsNotExist(err) {42 // path/to/whatever does not exist43 break44 }45 }46 err := os.MkdirAll(loadDataPath, config.DataPathMode)47 if err != nil {48 return domain.LoadData{}, &domain.AppError{err, "Error creating dockload folder", 500}49 }50 loadData = domain.LoadData{51 ID: loadId,52 Name: loadName,53 Tag: loadTag,54 }55 appErr = Save(loadData)56 if appErr != nil {57 return domain.LoadData{}, appErr58 }59 return loadData, nil60}61func Save(loadData domain.LoadData) *domain.AppError {62 if loadData.ID == "" {63 return &domain.AppError{nil, "Invalid dockloadId", 400}64 }65 loadDataJson := config.DataPath + "/" + loadData.ID + ".json"66 outJson, err := os.Create(loadDataJson)67 if err != nil {68 return &domain.AppError{err, "Failed to create data file", 500}69 }70 defer outJson.Close()71 enc := json.NewEncoder(outJson)72 enc.Encode(loadData)73 return nil74}75func List() ([]domain.LoadData, *domain.AppError) {76 l := list.New()77 files, _ := ioutil.ReadDir(config.DataPath)78 for _, f := range files {79 if f.IsDir() {80 l.PushBack(f.Name())81 }82 }83 var loadRecords = make([]domain.LoadData, l.Len())84 idx := 085 for e := l.Front(); e != nil; e = e.Next() {86 loadId := e.Value.(string)87 inJson, err := os.Open(config.DataPath + "/" + loadId + ".json")88 if err != nil {89 return []domain.LoadData{}, &domain.AppError{err, "Error opening data store", 500}90 }91 defer inJson.Close()92 decode := json.NewDecoder(inJson)93 var loadData domain.LoadData94 err = decode.Decode(&loadData)95 if err != nil {96 return []domain.LoadData{}, &domain.AppError{err, "Error opening data store", 500}97 }98 loadRecords[idx] = loadData99 idx += 1100 }101 return loadRecords, nil102}103// find docloadId by dockloadId, name and version104// tag can be in the form:105// 123456789012106// test107// test:1108// test:*109func Find(query string) (domain.LoadData, *domain.AppError) {110 nameOrId := query111 tag := ""112 querySplit := strings.Split(query, ":")113 if len(querySplit) > 1 {114 nameOrId = querySplit[0]115 tag = querySplit[1]116 }117 return findByNameTag(nameOrId, tag)118}119func findByNameTag(nameOrId, tag string) (domain.LoadData, *domain.AppError) {120 loadRecords, appErr := List()121 if appErr != nil {122 return domain.LoadData{}, appErr123 }124 for _, loadRecord := range loadRecords {125 if loadRecord.ID == nameOrId {126 return loadRecord, nil127 } else if loadRecord.Name == nameOrId {128 // TODO add support to remove all load with same name, we should return a list of matching loaddata129 //if tag == "*" {130 // return loadRecord, nil131 if loadRecord.Tag == tag {132 return loadRecord, nil133 }134 }135 }136 return domain.LoadData{}, &domain.AppError{nil, "Load not found.", LoadNotFound}137}...
LoadData
Using AI Code Generation
1import (2func main() {3 conf, err := config.NewConfig("ini", "conf/app.conf")4 if err != nil {5 fmt.Println("new config failed, err:", err)6 }7 fmt.Println(conf.String("appname"))8 fmt.Println(conf.String("httpport"))9 fmt.Println(conf.String("runmode"))10 fmt.Println(conf.String("mysql::user"))11 fmt.Println(conf.String("mysql::password"))12 fmt.Println(conf.String("mysql::host"))13 fmt.Println(conf.String("mysql::port"))14 fmt.Println(conf.String("mysql::database"))15}16import (17func main() {18 conf, err := config.NewConfig("ini", "conf/app.conf")19 if err != nil {20 fmt.Println("new config failed, err:", err)21 }22 fmt.Println(conf.String("appname"))23 fmt.Println(conf.String("httpport"))24 fmt.Println(conf.String("runmode"))25 fmt.Println(conf.String("mysql::user"))26 fmt.Println(conf.String("mysql::password"))27 fmt.Println(conf.String("mysql::host"))28 fmt.Println(conf.String("mysql::port"))29 fmt.Println(conf.String("mysql::database"))30 sections := conf.GetSection("mysql")31 fmt.Println(sections)32}33import (34func main() {35 conf, err := config.NewConfig("ini", "conf/app.conf")36 if err != nil {37 fmt.Println("new config failed, err:", err)38 }39 fmt.Println(conf.String("appname"))40 fmt.Println(conf.String("httpport"))41 fmt.Println(conf.String("runmode"))42 fmt.Println(conf.String("mysql::user"))43 fmt.Println(conf.String("mysql::password"))44 fmt.Println(conf.String("mysql::host"))45 fmt.Println(conf.String("mysql::port"))46 fmt.Println(conf.String("mysql::database"))47 sections := conf.GetSection("mysql")48 fmt.Println(sections)49 sections = conf.GetSection("appname")50 fmt.Println(sections)51}
LoadData
Using AI Code Generation
1import (2func main() {3 file, err := config.NewConfig("ini", "test.conf")4 if err != nil {5 fmt.Println(err)6 }7 file.LoadData("test2.conf")8 fmt.Println(file.String("appname"))9}
LoadData
Using AI Code Generation
1import (2func main() {3 conf, err := config.ReadDefault("1.ini")4 if err != nil {5 fmt.Println(err)6 }7 fmt.Println(conf)8}
LoadData
Using AI Code Generation
1import (2func main() {3 config.LoadData("config.json")4 fmt.Println(config.Get("name"))5}6{7}8import (9func main() {10 config.LoadData("config.json")11 config.SetEnv("name", "Ankit")12 fmt.Println(config.Get("name"))13}14{15}16import (17func main() {18 config.LoadData("config.json")19 config.SetEnv("name", "Ankit")20 fmt.Println(config.Get("name"))21}22{23}24import (25func main() {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!