예제 #1
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)
	}
}
예제 #2
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)
	}
}
예제 #3
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)
	}
}
예제 #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)
	}
}
예제 #5
0
func main() {
	client := artifactory.NewClientFromEnv()
	p, err := client.GetSystemSecurityConfiguration()
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		fmt.Printf("%s\n", p)
		os.Exit(0)
	}
}
예제 #6
0
func main() {
	client := artifactory.NewClientFromEnv()
	p, err := client.GetUserApiKey()
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		fmt.Printf("%s\n", p)
		os.Exit(0)
	}
}
예제 #7
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)
	}
}
예제 #8
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)
	}
}
예제 #9
0
func main() {
	client := artifactory.NewClientFromEnv()
	data, err := client.GetLicenseInformation()
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		table := tablewriter.NewWriter(os.Stdout)
		table.SetHeader([]string{"Type", "Expires", "Owner"})
		table.SetAutoWrapText(false)
		table.Append([]string{data.LicenseType, data.ValidThrough, data.LicensedTo})
		table.Render()
		os.Exit(0)
	}
}
예제 #10
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)
	}
}
예제 #11
0
func main() {
	client := artifactory.NewClientFromEnv()
	data, err := client.GetGroups()
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		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()
		os.Exit(0)
	}
}
예제 #12
0
/*
type selectiveCol struct {
	Header string
	Data   string
}

type selectiveResults struct {
	Name                     selectiveCol
	Email                    selectiveCol
	Password                 selectiveCol
	Updatable                selectiveCol
	LastLoggedIn             selectiveCol
	InternalPasswordDisabled selectiveCol
	Realm                    selectiveCol
	Groups                   selectiveCol
}

func formatUser(u *artifactory.UserDetails, a *[]string) {
	headers := []string
	data := []string
	for _, col in range *attrs {

	}
	defaultHeaders := []string{
		"Name",
		"Email",
		"Password",
		"Admin?",
		"Updatable?",
		"Last Logged In",
		"Internal Password Disabled?",
		"Realm",
		"Groups",
	}
	defaultData := []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"),
	}

}
*/
func main() {
	kingpin.Parse()
	fmt.Printf("%s\n", *attrs)
	client := artifactory.NewClientFromEnv()
	u, err := client.GetUserDetails(*user)
	if err != nil {
		fmt.Printf("%s\n", err)
		os.Exit(1)
	} else {
		if *format == "table" {
			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()
		} else {
			fmt.Printf("Unknown format: %s", *format)
		}
		os.Exit(0)
	}
}
예제 #13
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)
	}
}
예제 #14
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)
	}
}