Beispiel #1
0
func main() {
	kingpin.Parse()
	if !contains(availableThemes, *theme) {
		kingpin.Fatalf("theme: %s not found", *theme)
	}

	p, err := presentation.NewFromFileWithConfig(*source, *config)
	ifErrFatal(err)

	p.Theme = *theme

	if *startDaemon {
		r := mux.NewRouter()

		r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
			ifErrFatal(p.Write(w))
			if err := p.Reload(); err != nil {
				w.WriteHeader(http.StatusInternalServerError)
			}
		})

		r.PathPrefix("/").Handler(http.FileServer(http.Dir(".")))

		port := ":" + strconv.Itoa(*port)
		log.Println("Serving slides at", port)
		log.Fatal(http.ListenAndServe(port, r))

		return
	}

	// Write it just if we don't serve it
	ifErrFatal(p.Write(*outputFile))
}
func main() {
	kingpin.Parse()

	if *startDaemon {
		debug, _ = strconv.ParseBool(os.Getenv("DEBUG"))
		rules, _ = loadRulesFromFile("rules.yaml")
		log.Println("Daemon is listening in port", strconv.Itoa(*port))
		http.HandleFunc("/validate", validateHandler)
		http.HandleFunc("/setup", uploadHandler)
		http.HandleFunc("/rules", uploadRulesHandler)
		http.HandleFunc("/", defaultHandler)
		http.ListenAndServe(":8080", nil)

	} else {
		rules, _ = loadRulesFromFile(*rulesFile)
		dfile, _ := DockerfileFromPath(*dockerfile)

		v := Validation{rules, dfile}
		valid, msg := v.validate()
		if valid {
			fmt.Println("Dockerfile valid")
			os.Exit(0)
		} else {
			fmt.Println("Docker file not vallid:", msg)
			os.Exit(1)
		}

	}
}
Beispiel #3
0
func main() {
	kingpin.Parse()
	client := artifactory.NewClientFromEnv()

	password := randPass()

	var details artifactory.UserDetails = artifactory.UserDetails{
		Email:    *email,
		Password: password,
	}
	if group != nil {
		details.Groups = *group
	}

	if updatable != nil {
		details.ProfileUpdatable = *updatable
	}
	err := client.CreateUser(*username, details)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		if *showpass {
			fmt.Printf("User created. Random password is: %s\n", password)
		}
		os.Exit(0)
	}
}
Beispiel #4
0
func main() {
	kingpin.Parse()
	client := artifactory.NewClientFromEnv()
	u, err := client.GetPermissionTargetDetails(*target)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetHeader([]string{"Name", "Includes", "Excludes", "Repositories", "Users", "Groups"})
		row := []string{
			u.Name,
			u.IncludesPattern,
			u.ExcludesPattern,
			strings.Join(u.Repositories, "\n"),
		}
		var users []string
		var groups []string
		for k, v := range u.Principals.Users {
			line := fmt.Sprintf("%s (%s)", k, strings.Join(v, ","))
			users = append(users, line)
		}
		for k, v := range u.Principals.Groups {
			line := fmt.Sprintf("%s (%s)", k, strings.Join(v, ","))
			groups = append(groups, line)
		}
		row = append(row, strings.Join(users, "\n"))
		row = append(row, strings.Join(groups, "\n"))
		table.Append(row)
		table.Render()
		fmt.Println("Legend: m=admin; d=delete; w=deploy; n=annotate; r=read")
		os.Exit(0)
	}
}
Beispiel #5
0
func main() {
	kingpin.UsageTemplate(kingpin.CompactUsageTemplate).Version("1.0").Author("John E. Vincent")
	kingpin.CommandLine.Help = "List all users in Artifactory"
	kingpin.Parse()

	client := artifactory.NewClientFromEnv()
	data, err := client.GetUsers()
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		if *format == "table" {
			table := tablewriter.NewWriter(os.Stdout)
			table.SetHeader([]string{"Name", "Uri"})
			table.SetAutoWrapText(false)
			for _, u := range data {
				table.Append([]string{u.Name, u.Uri})
			}
			table.Render()
		} else if *format == "list" {
			for _, u := range data {
				fmt.Printf("%s\n", u.Name)
			}
		} else if *format == "csv" {
			for _, u := range data {
				fmt.Printf("%s%s%s\n", u.Name, *sep, u.Uri)
			}
		}
		os.Exit(0)
	}
}
Beispiel #6
0
func main() {
	kingpin.Parse()
	client := artifactory.NewClientFromEnv()
	data, err := client.GetRepos(*kind)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetHeader([]string{
			"Key",
			"Type",
			"Description",
			"Url",
		})
		for _, r := range data {
			table.Append([]string{
				r.Key,
				r.Rtype,
				r.Description,
				r.Url,
			})
		}
		table.Render()
		os.Exit(0)
	}
}
Beispiel #7
0
func main() {
	kingpin.Parse()
	client := rundeck.NewClientFromEnv()
	data, err := client.GetJob(*jobid)
	if err != nil {
		fmt.Printf("%s\n", err)
	} else {
		scope := data.Job
		table := tablewriter.NewWriter(os.Stdout)
		table.SetHeader([]string{"ID", "Name", "Description", "Group", "Steps", "Node Filters"})
		var steps []string
		var nodefilters []string
		for _, d := range scope.Sequence.Steps {
			var stepDescription string
			if d.Description == "" {
				if d.JobRef != nil {
					stepDescription = d.JobRef.Name
				} else if d.Exec != nil {
					stepDescription = *d.Exec
				}
			} else {
				stepDescription = d.Description
			}
			steps = append(steps, stepDescription)
		}
		for _, n := range scope.NodeFilters.Filter {
			nodefilters = append(nodefilters, n)
		}
		table.Append([]string{scope.ID, scope.Name, scope.Description, scope.Group, strings.Join(steps, "\n"), strings.Join(nodefilters, "\n")})
		table.Render()
	}
}
Beispiel #8
0
func main() {
	kingpin.Parse()
	client := artifactory.NewClientFromEnv()
	u, err := client.GetUserDetails(*user)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetHeader([]string{"Name", "Email", "Password", "Admin?", "Updatable?", "Last Logged In", "Internal Password Disabled?", "Realm", "Groups"})
		table.SetAutoWrapText(false)
		table.Append([]string{
			u.Name,
			u.Email,
			"<hidden>",
			strconv.FormatBool(u.Admin),
			strconv.FormatBool(u.ProfileUpdatable),
			u.LastLoggedIn,
			strconv.FormatBool(u.InternalPasswordDisabled),
			u.Realm,
			strings.Join(u.Groups, "\n"),
		})
		table.Render()
		os.Exit(0)
	}
}
Beispiel #9
0
func main() {
	kingpin.Parse()
	client := rundeck.NewClientFromEnv()
	top, err := client.GetHistory(*projectid)
	if err != nil {
		fmt.Printf("%s\n", err)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		for _, data := range top.Events {
			var job string
			if data.Job != nil {
				job = data.Job.ID
			} else {
				job = "<adhoc>"
			}
			table.SetHeader([]string{"Status", "Summary", "Start Time", "End Time", "S/F/T", "Job", "Execution", "User", "Project"})
			table.Append([]string{
				data.Status,
				data.Summary,
				data.StartTime,
				data.EndTime,
				fmt.Sprintf("%d/%d/%d", data.NodeSummary.Succeeded, data.NodeSummary.Failed, data.NodeSummary.Total),
				job,
				fmt.Sprintf("%d", data.Execution.ID),
				data.User,
				data.Project,
			})
		}
		table.Render()
	}
}
Beispiel #10
0
func init() {
	flag.Parse()
	config.SetConfigFile(*configFileName)

	err := config.ReadInConfig()
	if err != nil {
		panic("Config file not found")
	}
	logConfig := config.GetStringMap("log")
	initLog(logConfig)
}
Beispiel #11
0
func main() {
	kingpin.Version("0.1.1")
	kingpin.Parse()
	forwardEnabled := false
	if *forwardhost != "" && *forwardport != "" {
		forwardEnabled = true
	}
	log.Println("Clenaup interval ", *cleanupInterval)

	serve(&MailServer{hostname: *hostname, port: *port, httpport: *webport, forwardEnabled: forwardEnabled, forwardHost: *forwardhost, forwardPort: *forwardport, expireinterval: *cleanupInterval})
}
Beispiel #12
0
func main() {
	kingpin.Parse()
	client := rundeck.NewClientFromEnv()
	err := client.DeleteExecution(*id)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		os.Exit(0)
	}
}
Beispiel #13
0
func main() {

	fmt.Println(buildInfo())

	kingpin.Parse()

	if *configPath == "" {
		*configPath = "/etc/tinfoilhat/tinfoilhat.toml"
	}

	config, err := config.ReadConfig(*configPath)
	if err != nil {
		log.Fatalln("Cannot open config:", err)
	}

	db, err := steward.OpenDatabase(config.Database.Connection)
	if err != nil {
		log.Fatalln("Open database fail:", err)
	}

	defer db.Close()

	db.SetMaxOpenConns(config.Database.MaxConnections)

	switch kingpin.Parse() {
	case "advisory list":
		advisoryList(db)

	case "advisory review":
		advisoryReview(db)

	case "advisory hide":
		advisoryHide(db)

	case "advisory unhide":
		advisoryUnhide(db)

	case "scoreboard":
		scoreboardShow(db)
	}
}
Beispiel #14
0
func main() {
	kingpin.Parse()
	client := rundeck.NewClientFromEnv()
	res, err := client.ExportJob(*jobid, *format)
	if err != nil {
		fmt.Printf(err.Error())
		os.Exit(1)
	} else {
		fmt.Printf(res)
		os.Exit(0)
	}
}
Beispiel #15
0
func main() {
	kingpin.Parse()
	client := artifactory.NewClientFromEnv()
	data, err := client.GetRepo(*repo)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetAutoWrapText(false)
		baseHeaders := []string{
			"Key",
			"Type",
			"PackageType",
			"Description",
			"Notes",
			"Blacked Out?",
			"Releases?",
			"Snapshots?",
			"Excludes",
			"Includes",
		}

		// base row data common to all repos
		baseRow := makeBaseRow(data)
		// We have to do this to get to the concrete repo type
		switch data.MimeType() {
		case artifactory.REMOTE_REPO_MIMETYPE:
			d := data.(artifactory.RemoteRepoConfig)
			baseHeaders = append(baseHeaders, "Url")
			table.SetHeader(baseHeaders)
			baseRow = append(baseRow, d.Url)
			table.Append(baseRow)
		case artifactory.LOCAL_REPO_MIMETYPE:
			d := data.(artifactory.LocalRepoConfig)
			baseHeaders = append(baseHeaders, "Layout")
			baseRow = append(baseRow, d.LayoutRef)
			table.SetHeader(baseHeaders)
			table.Append(baseRow)
		case artifactory.VIRTUAL_REPO_MIMETYPE:
			d := data.(artifactory.VirtualRepoConfig)
			baseHeaders = append(baseHeaders, "Repositories")
			baseRow = append(baseRow, strings.Join(d.Repositories, "\n"))
			table.SetHeader(baseHeaders)
			table.Append(baseRow)
		default:
			table.SetHeader(baseHeaders)
			table.Append(baseRow)
		}
		table.Render()
		os.Exit(0)
	}
}
Beispiel #16
0
func main() {
	kingpin.Parse()
	client := artifactory.NewClientFromEnv()
	err := client.DeleteUser(*username)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		fmt.Printf("User %s deleted\n", *username)
		os.Exit(0)
	}
}
Beispiel #17
0
func main() {
	kingpin.Parse()
	client := rundeck.NewClientFromEnv()
	res, err := client.ListRunningExecutions(*project)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		fmt.Printf("%+v\n", res)
		//fmt.Printf("Job %s is %s", res.Executions[0].ID, res.Executions[0].Status)
		os.Exit(0)
	}
}
Beispiel #18
0
func main() {
	kingpin.Parse()
	client := rundeck.NewClientFromEnv()
	data, err := client.ListJobs(*projectid)
	if err != nil {
		fmt.Printf("%s\n", err)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetHeader([]string{"ID", "Name", "Description", "Group", "Project"})
		for _, d := range data.Jobs {
			table.Append([]string{d.ID, d.Name, d.Description, d.Group, d.Project})
		}
		table.Render()
	}
}
Beispiel #19
0
func main() {
	kingpin.Parse()
	client := artifactory.NewClientFromEnv()

	i, err := client.DeployArtifact(*repo, *file, *path, *property)
	if err != nil {
		if *silent != true {
			fmt.Printf("%s\n", err)
		}
		os.Exit(1)
	} else {
		if *silent != true {
			fmt.Printf("%s\n", i.URI)
		}
		os.Exit(0)
	}
}
Beispiel #20
0
func main() {
	kingpin.Parse()
	client := rundeck.NewClientFromEnv()
	options := make(map[string]string)
	options["max"] = *max
	data, err := client.ListProjectExecutions(*projectid, options)
	if err != nil {
		fmt.Printf("%s\n", err)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetHeader([]string{
			"ID",
			"Job Name",
			"Job Description",
			"Status",
			"Node Success/Failure Count",
			"User",
			"Start",
			"End",
			"Project",
		})
		for _, d := range data.Executions {
			var description string
			var name string
			if d.Job != nil {
				name = d.Job.Name
				description = d.Job.Description
			} else {
				name = "<adhoc>"
				description = d.Description
			}
			table.Append([]string{
				d.ID,
				name,
				description,
				d.Status,
				strconv.Itoa(len(d.SuccessfulNodes.Nodes)) + "/" + strconv.Itoa(len(d.FailedNodes.Nodes)),
				d.User,
				d.DateStarted,
				d.DateEnded,
				d.Project,
			})
		}
		table.Render()
	}
}
Beispiel #21
0
func main() {
	kingpin.Parse()
	client := rundeck.NewClientFromEnv()
	jobopts := rundeck.RunOptions{
		RunAs:     *runAs,
		LogLevel:  *logLevel,
		Filter:    *nodeFilter,
		Arguments: strings.Join(*argString, " "),
	}
	res, err := client.RunJob(*jobId, jobopts)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		fmt.Printf("Job %s is %s\n", res.Executions[0].ID, res.Executions[0].Status)
		os.Exit(0)
	}
}
Beispiel #22
0
func main() {
	kingpin.Parse()
	client := rundeck.NewClientFromEnv()
	res, err := client.DeleteAllExecutionsForProject(*project, 200)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		fmt.Printf("Successful: %d\n", res.Successful.Count)
		if res.Failed.Count != 0 {
			fmt.Printf("Failed: %d\n", res.Failed.Count)
			for _, f := range res.Failed.Failures {
				fmt.Printf("%d - %s\n", f.ID, f.Message)
			}
		}
		os.Exit(0)
	}
}
Beispiel #23
0
func main() {
	kingpin.Parse()
	client := rundeck.NewClientFromEnv()
	importParams := rundeck.ImportParams{
		Filename: *filename,
		Format:   *format,
		Dupe:     *dupe,
		Uuid:     *uuid,
		Project:  *project,
	}
	jobid, err := client.ImportJob(importParams)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		fmt.Printf("Job %s imported\n", jobid)
		os.Exit(0)
	}
}
Beispiel #24
0
func main() {
	kingpin.Parse()
	client := rundeck.NewClientFromEnv()
	data, err := client.GetExecution(*id)
	if err != nil {
		fmt.Printf("%s\n", err)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		headers := []string{
			"ID",
			"User",
			"Status",
			"Start Date",
			"End Date",
		}
		table.SetHeader(headers)
		table.Append([]string{data.ID, data.User, data.Status, data.DateStarted, data.DateEnded})
		table.Render()
	}
}
Beispiel #25
0
func main() {
	kingpin.Parse()
	client := artifactory.NewClientFromEnv()
	u, err := client.GetGroupDetails(*group)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetHeader([]string{"Name", "Description", "AutoJoin?", "Realm", "Realm Attributes"})
		table.SetAutoWrapText(false)
		table.Append([]string{
			u.Name,
			u.Description,
			strconv.FormatBool(u.AutoJoin),
			u.Realm,
			u.RealmAttributes,
		})
		table.Render()
		os.Exit(0)
	}
}
Beispiel #26
0
func main() {
	kingpin.Parse()
	client := rundeck.NewClientFromEnv()
	data, err := client.GetJob(*jobid)
	if err != nil {
		fmt.Printf("%s\n", err)
	} else {
		scope := data.Job
		table := tablewriter.NewWriter(os.Stdout)
		table.SetHeader([]string{"ID", "Name", "Description", "Options"})
		table.SetAutoWrapText(false)
		var options []string
		for _, d := range *scope.Context.Options {
			var option string
			option = fmt.Sprintf("%s", d.Name)
			if d.Required {
				option = fmt.Sprintf("%s (required)", option)
			}
			options = append(options, option)
		}
		table.Append([]string{scope.ID, scope.Name, scope.Description, strings.Join(options, "\n")})
		table.Render()
	}
}
Beispiel #27
0
func main() {

	fmt.Println(buildInfo())

	kingpin.Parse()

	if *configPath == "" {
		log.Println("Use default config path")
		*configPath = "/etc/tinfoilhat/tinfoilhat.toml"
	}

	config, err := config.ReadConfig(*configPath)
	if err != nil {
		log.Fatalln("Cannot open config:", err)
	}

	logFile, err := os.OpenFile(config.LogFile,
		os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		log.Fatalln("Cannot open file:", err)
	}
	defer logFile.Close()
	log.SetOutput(logFile)

	log.Println(buildInfo())

	var rlim syscall.Rlimit
	err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim)
	if err != nil {
		log.Fatalln("Getrlimit fail:", err)
	}

	log.Println("RLIMIT_NOFILE CUR:", rlim.Cur, "MAX:", rlim.Max)

	db, err := steward.OpenDatabase(config.Database.Connection)
	if err != nil {
		log.Fatalln("Open database fail:", err)
	}

	defer db.Close()

	db.SetMaxOpenConns(config.Database.MaxConnections)

	if *dbReinit {
		reinitDatabase(db, config)
	}

	checker.SetTimeout(config.CheckerTimeout.Duration)

	if config.AdvisoryReceiver.Disabled {
		scoreboard.DisableAdvisory()
	}

	priv, err := vexillary.GenerateKey()
	if err != nil {
		log.Fatalln("Generate key fail:", err)
	}

	attackFlow := make(chan scoreboard.Attack, config.API.AttackBuffer)

	go receiver.FlagReceiver(db, priv, config.FlagReceiver.Addr,
		config.FlagReceiver.ReceiveTimeout.Duration,
		config.FlagReceiver.SocketTimeout.Duration,
		attackFlow)

	go receiver.AdvisoryReceiver(db, config.AdvisoryReceiver.Addr,
		config.AdvisoryReceiver.ReceiveTimeout.Duration,
		config.AdvisoryReceiver.SocketTimeout.Duration)

	go scoreboard.Scoreboard(db, attackFlow,
		config.Scoreboard.WwwPath,
		config.Scoreboard.Addr,
		config.Scoreboard.UpdateTimeout.Duration,
		config.Pulse.Start.Time,
		config.Pulse.Half.Duration,
		config.Pulse.Lunch.Duration,
		config.Pulse.DarkestTime.Duration)

	err = pulse.Pulse(db, priv,
		config.Pulse.Start.Time,
		config.Pulse.Half.Duration,
		config.Pulse.Lunch.Duration,
		config.Pulse.RoundLen.Duration,
		config.Pulse.CheckTimeout.Duration)
	if err != nil {
		log.Fatalln("Game error:", err)
	}

	log.Println("It's now safe to turn off you computer")
	for {
		time.Sleep(time.Hour)
	}
}
Beispiel #28
0
func main() {
	kingpin.Parse()
	client := artifactory.NewClientFromEnv()
	var coords artifactory.Gavc
	if groupid != nil {
		coords.GroupID = *groupid
	}
	if artifactid != nil {
		coords.ArtifactID = *artifactid
	}
	if version != nil {
		coords.Version = *version
	}
	if classifier != nil {
		coords.Classifier = *classifier
	}
	if repo != nil {
		coords.Repos = *repo
	}
	data, err := client.GAVCSearch(&coords)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetAutoWrapText(false)
		table.SetBorder(false)
		table.SetAlignment(tablewriter.ALIGN_LEFT)

		for _, r := range data {
			var innerBuf bytes.Buffer
			innerTable := tablewriter.NewWriter(&innerBuf)
			innerTable.SetHeader([]string{
				"File",
				"Repo",
				"RemoteUrl",
				"Created",
				"Last Modified",
				"Created By",
				"Modified By",
				"SHA1",
				"MD5",
				"Size",
				"MimeType",
			})
			elems := strings.Split(r.Path, "/")
			fileName := elems[len(elems)-1]
			innerTable.Append([]string{
				fileName,
				r.Repo,
				r.RemoteUrl,
				r.Created,
				r.LastModified,
				r.CreatedBy,
				r.ModifiedBy,
				r.Checksums.SHA1,
				r.Checksums.MD5,
				r.Size,
				r.MimeType,
			})
			innerTable.Render()
			table.Append([]string{
				innerBuf.String(),
			})
			table.Append([]string{
				fmt.Sprintf("Download: %s\n", r.Uri),
			})

		}
		table.Render()
		os.Exit(0)
	}
}