本文整理汇总了Golang中github.com/catalyzeio/catalyze/helpers.SignIn函数的典型用法代码示例。如果您正苦于以下问题:Golang SignIn函数的具体用法?Golang SignIn怎么用?Golang SignIn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SignIn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ListVars
// ListVars lists all environment variables.
func ListVars(settings *models.Settings) {
helpers.SignIn(settings)
envVars := helpers.ListEnvVars(settings)
for key, value := range envVars {
fmt.Printf("%s=%s\n", key, value)
}
}
示例2: Status
// Status prints out an environment healthcheck. The status of the environment
// and every service in the environment is printed out.
func Status(settings *models.Settings) {
helpers.SignIn(settings)
env := helpers.RetrieveEnvironment("pod", settings)
fmt.Printf("%s (environment ID = %s):\n", env.Data.Name, env.ID)
for _, service := range *env.Data.Services {
if service.Type != "utility" {
if service.Type == "code" {
switch service.Size.(type) {
case string:
printLegacySizing(&service)
default:
printNewSizing(&service)
}
} else {
switch service.Size.(type) {
case string:
sizeString := service.Size.(string)
defer fmt.Printf("\t%s (size = %s, image = %s, status = %s) ID: %s\n", service.Label, sizeString, service.Name, service.DeployStatus, service.ID)
default:
serviceSize := service.Size.(map[string]interface{})
defer fmt.Printf("\t%s (ram = %.0f, storage = %.0f, behavior = %s, type = %s, cpu = %.0f, image = %s, status = %s) ID: %s\n", service.Label, serviceSize["ram"], serviceSize["storage"], serviceSize["behavior"], serviceSize["type"], serviceSize["cpu"], service.Name, service.DeployStatus, service.ID)
}
}
}
}
}
示例3: SupportIds
// SupportIds prints out various IDs related to the associated environment to be
// used when contacting Catalyze support at [email protected]
func SupportIds(settings *models.Settings) {
helpers.SignIn(settings)
fmt.Printf(`EnvironmentID: %s
UsersID: %s
ServiceID: %s
`, settings.EnvironmentID, settings.UsersID, settings.ServiceID)
}
示例4: Export
// Export dumps all data from a database service and downloads the encrypted
// data to the local machine. The export is accomplished by first creating a
// backup. Once finished, the CLI asks where the file can be downloaded from.
// The file is downloaded, decrypted, and saved locally.
func Export(databaseLabel string, filePath string, force bool, settings *models.Settings) {
helpers.PHIPrompt()
helpers.SignIn(settings)
if !force {
if _, err := os.Stat(filePath); err == nil {
fmt.Printf("File already exists at path '%s'. Specify `--force` to overwrite\n", filePath)
os.Exit(1)
}
} else {
os.Remove(filePath)
}
service := helpers.RetrieveServiceByLabel(databaseLabel, settings)
if service == nil {
fmt.Printf("Could not find a service with the label \"%s\"\n", databaseLabel)
os.Exit(1)
}
task := helpers.CreateBackup(service.ID, settings)
fmt.Printf("Export started (task ID = %s)\n", task.ID)
fmt.Print("Polling until export finishes.")
ch := make(chan string, 1)
go helpers.PollTaskStatus(task.ID, ch, settings)
status := <-ch
task.Status = status
if task.Status != "finished" {
fmt.Printf("\nExport finished with illegal status \"%s\", aborting.\n", task.Status)
helpers.DumpLogs(service, task, "backup", settings)
os.Exit(1)
}
fmt.Printf("\nEnded in status '%s'\n", task.Status)
job := helpers.RetrieveJobFromTaskID(task.ID, settings)
fmt.Printf("Downloading export %s\n", job.ID)
tempURL := helpers.RetrieveTempURL(job.ID, service.ID, settings)
dir, dirErr := ioutil.TempDir("", "")
if dirErr != nil {
fmt.Println(dirErr.Error())
os.Exit(1)
}
defer os.Remove(dir)
tmpFile, tmpFileErr := ioutil.TempFile(dir, "")
if tmpFileErr != nil {
fmt.Println(tmpFileErr.Error())
os.Exit(1)
}
resp, respErr := http.Get(tempURL.URL)
if respErr != nil {
fmt.Println(respErr.Error())
os.Exit(1)
}
defer resp.Body.Close()
io.Copy(tmpFile, resp.Body)
fmt.Println("Decrypting...")
tmpFile.Close()
helpers.DecryptFile(tmpFile.Name(), job.Backup.Key, job.Backup.IV, filePath)
fmt.Printf("%s exported successfully to %s\n", databaseLabel, filePath)
helpers.DumpLogs(service, task, "backup", settings)
}
示例5: ListUsers
// ListUsers lists all users who have access to the associated environment.
func ListUsers(settings *models.Settings) {
helpers.SignIn(settings)
envUsers := helpers.ListEnvironmentUsers(settings)
for _, userID := range envUsers.Users {
if userID == settings.UsersID {
fmt.Printf("%s (you)\n", userID)
} else {
defer fmt.Printf("%s\n", userID)
}
}
}
示例6: Console
// Console opens a secure console to a code or database service. For code
// services, a command is required. This command is executed as root in the
// context of the application root directory. For database services, no command
// is needed - instead, the appropriate command for the database type is run.
// For example, for a postgres database, psql is run.
func Console(serviceLabel string, command string, settings *models.Settings) {
helpers.SignIn(settings)
service := helpers.RetrieveServiceByLabel(serviceLabel, settings)
if service == nil {
fmt.Printf("Could not find a service with the label \"%s\"\n", serviceLabel)
os.Exit(1)
}
fmt.Printf("Opening console to %s (%s)\n", serviceLabel, service.ID)
task := helpers.RequestConsole(command, service.ID, settings)
fmt.Print("Waiting for the console to be ready. This might take a minute.")
ch := make(chan string, 1)
go helpers.PollConsoleJob(task.ID, service.ID, ch, settings)
jobID := <-ch
defer helpers.DestroyConsole(jobID, service.ID, settings)
creds := helpers.RetrieveConsoleTokens(jobID, service.ID, settings)
creds.URL = strings.Replace(creds.URL, "http", "ws", 1)
fmt.Println("Connecting...")
// BEGIN websocket impl
config, _ := websocket.NewConfig(creds.URL, "ws://localhost:9443/")
config.TlsConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
}
config.Header["X-Console-Token"] = []string{creds.Token}
ws, err := websocket.DialConfig(config)
if err != nil {
panic(err)
}
defer ws.Close()
fmt.Println("Connection opened")
stdin, stdout, _ := term.StdStreams()
fdIn, isTermIn := term.GetFdInfo(stdin)
if !isTermIn {
panic(errors.New("StdIn is not a terminal"))
}
oldState, err := term.SetRawTerminal(fdIn)
if err != nil {
panic(err)
}
done := make(chan bool)
msgCh := make(chan []byte, 2)
go webSocketDaemon(ws, &stdout, done, msgCh)
signal.Notify(make(chan os.Signal, 1), os.Interrupt)
defer term.RestoreTerminal(fdIn, oldState)
go termDaemon(&stdin, ws)
<-done
}
示例7: ListInvites
// ListInvites lists all pending invites for a given environment. After an
// invite is accepted, you can manage the users access with the `users`
// commands.
func ListInvites(settings *models.Settings) {
helpers.SignIn(settings)
invites := helpers.ListEnvironmentInvites(settings)
if len(*invites) == 0 {
fmt.Printf("There are no pending invites for %s\n", settings.EnvironmentName)
return
}
fmt.Printf("Pending invites for %s:\n", settings.EnvironmentName)
for _, invite := range *invites {
fmt.Printf("\t%s %s\n", invite.Email, invite.Code)
}
}
示例8: DownloadBackup
// DownloadBackup an existing backup to the local machine. The backup is encrypted
// throughout the entire journey and then decrypted once it is stored locally.
func DownloadBackup(serviceLabel string, backupID string, filePath string, force bool, settings *models.Settings) {
helpers.PHIPrompt()
helpers.SignIn(settings)
if !force {
if _, err := os.Stat(filePath); err == nil {
fmt.Printf("File already exists at path '%s'. Specify `--force` to overwrite\n", filePath)
os.Exit(1)
}
} else {
os.Remove(filePath)
}
service := helpers.RetrieveServiceByLabel(serviceLabel, settings)
if service == nil {
fmt.Printf("Could not find a service with the label \"%s\"\n", serviceLabel)
os.Exit(1)
}
job := helpers.RetrieveJob(backupID, service.ID, settings)
if job.Type != "backup" || job.Status != "finished" {
fmt.Println("Only 'finished' 'backup' jobs may be downloaded")
}
fmt.Printf("Downloading backup %s\n", backupID)
tempURL := helpers.RetrieveTempURL(backupID, service.ID, settings)
dir, dirErr := ioutil.TempDir("", "")
if dirErr != nil {
fmt.Println(dirErr.Error())
os.Exit(1)
}
defer os.Remove(dir)
tmpFile, tmpFileErr := ioutil.TempFile(dir, "")
if tmpFileErr != nil {
fmt.Println(tmpFileErr.Error())
os.Exit(1)
}
resp, respErr := http.Get(tempURL.URL)
if respErr != nil {
fmt.Println(respErr.Error())
os.Exit(1)
}
defer resp.Body.Close()
io.Copy(tmpFile, resp.Body)
tmpFile.Close()
fmt.Println("Decrypting...")
helpers.DecryptFile(tmpFile.Name(), job.Backup.Key, job.Backup.IV, filePath)
fmt.Printf("%s backup downloaded successfully to %s\n", serviceLabel, filePath)
}
示例9: Import
// Import imports data into a database service. The import is accomplished
// by encrypting the file locally, requesting a location that it can be uploaded
// to, then uploads the file. Once uploaded an automated service processes the
// file and acts according to the given parameters.
//
// The type of file that should be imported depends on the database. For
// PostgreSQL and MySQL, this should be a single `.sql` file. For Mongo, this
// should be a single tar'ed, gzipped archive (`.tar.gz`) of the database dump
// that you want to import.
func Import(databaseLabel string, filePath string, mongoCollection string, mongoDatabase string, wipeFirst bool, settings *models.Settings) {
helpers.SignIn(settings)
if _, err := os.Stat(filePath); os.IsNotExist(err) {
fmt.Printf("A file does not exist at path '%s'\n", filePath)
os.Exit(1)
}
service := helpers.RetrieveServiceByLabel(databaseLabel, settings)
if service == nil {
fmt.Printf("Could not find a service with the label \"%s\"\n", databaseLabel)
os.Exit(1)
}
env := helpers.RetrieveEnvironment("spec", settings)
pod := helpers.RetrievePodMetadata(env.PodID, settings)
fmt.Printf("Importing '%s' into %s (ID = %s)\n", filePath, databaseLabel, service.ID)
key := make([]byte, 32)
iv := make([]byte, aes.BlockSize)
rand.Read(key)
rand.Read(iv)
fmt.Println("Encrypting...")
encrFilePath := helpers.EncryptFile(filePath, key, iv, pod.ImportRequiresLength)
defer os.Remove(encrFilePath)
options := map[string]string{}
if mongoCollection != "" {
options["mongoCollection"] = mongoCollection
}
if mongoDatabase != "" {
options["mongoDatabase"] = mongoDatabase
}
fmt.Println("Uploading...")
tempURL := helpers.RetrieveTempUploadURL(service.ID, settings)
task := helpers.InitiateImport(tempURL.URL, encrFilePath, string(helpers.Base64Encode(helpers.Hex(key))), string(helpers.Base64Encode(helpers.Hex(iv))), options, wipeFirst, service.ID, settings)
fmt.Printf("Processing import... (task ID = %s)\n", task.ID)
ch := make(chan string, 1)
go helpers.PollTaskStatus(task.ID, ch, settings)
status := <-ch
task.Status = status
fmt.Printf("\nImport complete (end status = '%s')\n", task.Status)
helpers.DumpLogs(service, task, "restore", settings)
if task.Status != "finished" {
os.Exit(1)
}
}
示例10: ListBackups
// ListBackups lists the created backups for the service sorted from oldest to newest
func ListBackups(serviceLabel string, page int, pageSize int, settings *models.Settings) {
helpers.SignIn(settings)
service := helpers.RetrieveServiceByLabel(serviceLabel, settings)
if service == nil {
fmt.Printf("Could not find a service with the label \"%s\"\n", serviceLabel)
os.Exit(1)
}
jobs := helpers.ListBackups(service.ID, page, pageSize, settings)
sort.Sort(SortedJobs(*jobs))
for _, job := range *jobs {
fmt.Printf("%s %s (status = %s)\n", job.ID, job.CreatedAt, job.Status)
}
if len(*jobs) == pageSize && page == 1 {
fmt.Println("(for older backups, try with --page 2 or adjust --page-size)")
}
if len(*jobs) == 0 && page == 1 {
fmt.Println("No backups created yet for this service.")
}
}
示例11: CreateBackup
// CreateBackup a new backup
func CreateBackup(serviceLabel string, skipPoll bool, settings *models.Settings) {
helpers.SignIn(settings)
service := helpers.RetrieveServiceByLabel(serviceLabel, settings)
if service == nil {
fmt.Printf("Could not find a service with the label \"%s\"\n", serviceLabel)
os.Exit(1)
}
task := helpers.CreateBackup(service.ID, settings)
fmt.Printf("Backup started (task ID = %s)\n", task.ID)
if !skipPoll {
fmt.Print("Polling until backup finishes.")
ch := make(chan string, 1)
go helpers.PollTaskStatus(task.ID, ch, settings)
status := <-ch
task.Status = status
fmt.Printf("\nEnded in status '%s'\n", task.Status)
helpers.DumpLogs(service, task, "backup", settings)
if task.Status != "finished" {
os.Exit(1)
}
}
}
示例12: SetVar
// SetVar adds a new environment variables or updates the value of an existing
// environment variables. Any changes to environment variables will not take
// effect until the service is redeployed by pushing new code or via
// `catalyze redeploy`.
func SetVar(variables []string, settings *models.Settings) {
helpers.SignIn(settings)
envVars := helpers.ListEnvVars(settings)
envVarsMap := make(map[string]string, len(variables))
for _, envVar := range variables {
pieces := strings.Split(envVar, "=")
if len(pieces) != 2 {
fmt.Printf("Invalid variable format. Expected <key>=<value> but got %s\n", envVar)
os.Exit(1)
}
envVarsMap[pieces[0]] = pieces[1]
}
for key := range envVarsMap {
if _, ok := envVars[key]; ok {
helpers.UnsetEnvVar(key, settings)
}
}
helpers.SetEnvVars(envVarsMap, settings)
fmt.Println("Set.")
}
示例13: Redeploy
// Redeploy offers a way of deploying a service without having to do a git push
// first. The same version of the currently running service is deployed with
// no changes.
func Redeploy(settings *models.Settings) {
helpers.SignIn(settings)
fmt.Printf("Redeploying %s\n", settings.ServiceID)
helpers.RedeployService(settings)
fmt.Println("Redeploy successful! Check the status and logs for updates")
}
示例14: Metrics
// Metrics prints out metrics for a given service or if the service is not
// specified, metrics for the entire environment are printed.
func Metrics(serviceLabel string, jsonFlag bool, csvFlag bool, sparkFlag bool, streamFlag bool, mins int, settings *models.Settings) {
if streamFlag && (jsonFlag || csvFlag || mins != 1) {
fmt.Println("--stream cannot be used with a custom format and multiple records")
os.Exit(1)
}
var singleRetriever func(mins int, settings *models.Settings) *models.Metrics
if serviceLabel != "" {
service := helpers.RetrieveServiceByLabel(serviceLabel, settings)
if service == nil {
fmt.Printf("Could not find a service with the label \"%s\"\n", serviceLabel)
os.Exit(1)
}
settings.ServiceID = service.ID
singleRetriever = helpers.RetrieveServiceMetrics
}
var transformer Transformer
redraw := make(chan bool)
if jsonFlag {
transformer = Transformer{
SingleRetriever: singleRetriever,
DataTransformer: &JSONTransformer{},
}
} else if csvFlag {
buffer := &bytes.Buffer{}
transformer = Transformer{
SingleRetriever: singleRetriever,
DataTransformer: &CSVTransformer{
HeadersWritten: false,
GroupMode: serviceLabel == "",
Buffer: buffer,
Writer: csv.NewWriter(buffer),
},
}
} else if sparkFlag {
// the spark lines interface stays up until closed by the user, so
// we might as well keep updating it as long as it is there
streamFlag = true
mins = 60
err := ui.Init()
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
defer ui.Close()
ui.UseTheme("helloworld")
p := ui.NewPar("PRESS q TO QUIT")
p.HasBorder = false
p.TextFgColor = ui.Theme().SparklineTitle
ui.Body.AddRows(
ui.NewRow(ui.NewCol(12, 0, p)),
)
transformer = Transformer{
SingleRetriever: singleRetriever,
DataTransformer: &SparkTransformer{
Redraw: redraw,
SparkLines: make(map[string]*ui.Sparklines),
},
}
} else {
transformer = Transformer{
SingleRetriever: singleRetriever,
DataTransformer: &TextTransformer{},
}
}
transformer.GroupRetriever = helpers.RetrieveEnvironmentMetrics
transformer.Stream = streamFlag
transformer.GroupMode = serviceLabel == ""
transformer.Mins = mins
transformer.settings = settings
helpers.SignIn(settings)
if sparkFlag {
go transformer.process()
ui.Body.Align()
ui.Render(ui.Body)
quit := make(chan bool)
go maintainSparkLines(redraw, quit)
<-quit
} else {
transformer.process()
}
}
示例15: RmInvite
// RmInvite deletes an invite sent to a user. This invite must not already be
// accepted.
func RmInvite(inviteID string, settings *models.Settings) {
helpers.SignIn(settings)
helpers.DeleteInvite(inviteID, settings)
fmt.Printf("Invite %s removed\n", inviteID)
}