func (k *SKeys) List() (*[]models.UserKey, error) { headers := httpclient.GetHeaders(k.Settings.SessionToken, k.Settings.Version, k.Settings.Pod, k.Settings.UsersID) resp, status, err := httpclient.Get(nil, fmt.Sprintf("%s%s/keys", k.Settings.AuthHost, k.Settings.AuthHostVersion), headers) if err != nil { return nil, err } keys := []models.UserKey{} err = httpclient.ConvertResp(resp, status, &keys) return &keys, err }
func (j *SJobs) Retrieve(jobID, svcID string, includeSpec bool) (*models.Job, error) { headers := httpclient.GetHeaders(j.Settings.SessionToken, j.Settings.Version, j.Settings.Pod, j.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/jobs/%s?spec=true", j.Settings.PaasHost, j.Settings.PaasHostVersion, j.Settings.EnvironmentID, svcID, jobID), headers) if err != nil { return nil, err } var job models.Job err = httpclient.ConvertResp(resp, statusCode, &job) if err != nil { return nil, err } return &job, nil }
func (w *SWorker) Retrieve(svcID string) (*models.Workers, error) { headers := httpclient.GetHeaders(w.Settings.SessionToken, w.Settings.Version, w.Settings.Pod, w.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/workers", w.Settings.PaasHost, w.Settings.PaasHostVersion, w.Settings.EnvironmentID, svcID), headers) if err != nil { return nil, err } var workers models.Workers err = httpclient.ConvertResp(resp, statusCode, &workers) if err != nil { return nil, err } return &workers, nil }
func (j *SJobs) RetrieveByStatus(svcID, status string) (*[]models.Job, error) { headers := httpclient.GetHeaders(j.Settings.SessionToken, j.Settings.Version, j.Settings.Pod, j.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/jobs?status=%s", j.Settings.PaasHost, j.Settings.PaasHostVersion, j.Settings.EnvironmentID, svcID, status), headers) if err != nil { return nil, err } var jobs []models.Job err = httpclient.ConvertResp(resp, statusCode, &jobs) if err != nil { return nil, err } return &jobs, nil }
func (j *SJobs) List(svcID string, page, pageSize int) (*[]models.Job, error) { headers := httpclient.GetHeaders(j.Settings.SessionToken, j.Settings.Version, j.Settings.Pod, j.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/jobs?pageNumber=%d&pageSize=%d", j.Settings.PaasHost, j.Settings.PaasHostVersion, j.Settings.EnvironmentID, svcID, page, pageSize), headers) if err != nil { return nil, err } var jobs []models.Job err = httpclient.ConvertResp(resp, statusCode, &jobs) if err != nil { return nil, err } return &jobs, nil }
// RetrieveServiceMetrics retrieves metrics data for the given service. func (m *SMetrics) RetrieveServiceMetrics(mins int, svcID string) (*models.Metrics, error) { headers := httpclient.GetHeaders(m.Settings.SessionToken, m.Settings.Version, m.Settings.Pod, m.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/metrics?time=%dm", m.Settings.PaasHost, m.Settings.PaasHostVersion, m.Settings.EnvironmentID, svcID, mins), headers) if err != nil { return nil, err } var metrics models.Metrics err = httpclient.ConvertResp(resp, statusCode, &metrics) if err != nil { return nil, err } return &metrics, nil }
func (r *SReleases) Retrieve(releaseName, svcID string) (*models.Release, error) { headers := httpclient.GetHeaders(r.Settings.SessionToken, r.Settings.Version, r.Settings.Pod, r.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/releases/%s", r.Settings.PaasHost, r.Settings.PaasHostVersion, r.Settings.EnvironmentID, svcID, releaseName), headers) if err != nil { return nil, err } var rls models.Release err = httpclient.ConvertResp(resp, statusCode, &rls) if err != nil { return nil, err } return &rls, nil }
func (c *SCerts) List(svcID string) (*[]models.Cert, error) { headers := httpclient.GetHeaders(c.Settings.SessionToken, c.Settings.Version, c.Settings.Pod, c.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/certs", c.Settings.PaasHost, c.Settings.PaasHostVersion, c.Settings.EnvironmentID, svcID), headers) if err != nil { return nil, err } var certs []models.Cert err = httpclient.ConvertResp(resp, statusCode, &certs) if err != nil { return nil, err } return &certs, nil }
// ListRoles lists all available roles func (i *SInvites) ListRoles() (*[]models.Role, error) { headers := httpclient.GetHeaders(i.Settings.SessionToken, i.Settings.Version, i.Settings.Pod, i.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/orgs/roles", i.Settings.AuthHost, i.Settings.AuthHostVersion), headers) if err != nil { return nil, err } var roles []models.Role err = httpclient.ConvertResp(resp, statusCode, &roles) if err != nil { return nil, err } return &roles, nil }
func (s *SSites) List(svcID string) (*[]models.Site, error) { headers := httpclient.GetHeaders(s.Settings.SessionToken, s.Settings.Version, s.Settings.Pod, s.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/sites", s.Settings.PaasHost, s.Settings.PaasHostVersion, s.Settings.EnvironmentID, svcID), headers) if err != nil { return nil, err } var sites []models.Site err = httpclient.ConvertResp(resp, statusCode, &sites) if err != nil { return nil, err } return &sites, nil }
func (u *SUsers) List() (*[]models.OrgUser, error) { headers := httpclient.GetHeaders(u.Settings.SessionToken, u.Settings.Version, u.Settings.Pod, u.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/orgs/%s/users", u.Settings.AuthHost, u.Settings.AuthHostVersion, u.Settings.OrgID), headers) if err != nil { return nil, err } var users []models.OrgUser err = httpclient.ConvertResp(resp, statusCode, &users) if err != nil { return nil, err } return &users, nil }
func (d *SDeployKeys) List(svcID string) (*[]models.DeployKey, error) { headers := httpclient.GetHeaders(d.Settings.SessionToken, d.Settings.Version, d.Settings.Pod, d.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/ssh_keys", d.Settings.PaasHost, d.Settings.PaasHostVersion, d.Settings.EnvironmentID, svcID), headers) if err != nil { return nil, err } var deployKeys []models.DeployKey err = httpclient.ConvertResp(resp, statusCode, &deployKeys) if err != nil { return nil, err } return &deployKeys, nil }
func (d *SDb) TempLogsURL(jobID string, serviceID string) (*models.TempURL, error) { headers := httpclient.GetHeaders(d.Settings.SessionToken, d.Settings.Version, d.Settings.Pod, d.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/backup-restore-logs-url/%s", d.Settings.PaasHost, d.Settings.PaasHostVersion, d.Settings.EnvironmentID, serviceID, jobID), headers) if err != nil { return nil, err } var tempURL models.TempURL err = httpclient.ConvertResp(resp, statusCode, &tempURL) if err != nil { return nil, err } return &tempURL, nil }
// List lists the created backups for the service sorted from oldest to newest func (d *SDb) List(page, pageSize int, service *models.Service) (*[]models.Job, error) { headers := httpclient.GetHeaders(d.Settings.SessionToken, d.Settings.Version, d.Settings.Pod, d.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/jobs?type=backup&pageNumber=%d&pageSize=%d", d.Settings.PaasHost, d.Settings.PaasHostVersion, d.Settings.EnvironmentID, service.ID, page, pageSize), headers) if err != nil { return nil, err } var jobs []models.Job err = httpclient.ConvertResp(resp, statusCode, &jobs) if err != nil { return nil, err } return &jobs, nil }
func (p *SPods) List() (*[]models.Pod, error) { headers := httpclient.GetHeaders(p.Settings.SessionToken, p.Settings.Version, p.Settings.Pod, p.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/pods", p.Settings.PaasHost, p.Settings.PaasHostVersion), headers) if err != nil { return nil, err } var podWrapper models.PodWrapper err = httpclient.ConvertResp(resp, statusCode, &podWrapper) if err != nil { return nil, err } return podWrapper.Pods, nil }
// List lists all environment variables. func (v *SVars) List(svcID string) (map[string]string, error) { headers := httpclient.GetHeaders(v.Settings.SessionToken, v.Settings.Version, v.Settings.Pod, v.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/env", v.Settings.PaasHost, v.Settings.PaasHostVersion, v.Settings.EnvironmentID, svcID), headers) if err != nil { return nil, err } var envVars map[string]string err = httpclient.ConvertResp(resp, statusCode, &envVars) if err != nil { return nil, err } return envVars, nil }
func (e *SEnvironments) Retrieve(envID string) (*models.Environment, error) { headers := httpclient.GetHeaders(e.Settings.SessionToken, e.Settings.Version, e.Settings.Pod, e.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s", e.Settings.PaasHost, e.Settings.PaasHostVersion, envID), headers) if err != nil { return nil, err } var env models.Environment err = httpclient.ConvertResp(resp, statusCode, &env) if err != nil { return nil, err } env.Pod = e.Settings.Pod return &env, nil }
// Verify verifies if a given session token is still valid or not. If it is // valid, the returned error will be nil. func (a *SAuth) Verify() (*models.User, error) { headers := httpclient.GetHeaders(a.Settings.SessionToken, a.Settings.Version, a.Settings.Pod, a.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/auth/verify", a.Settings.AuthHost, a.Settings.AuthHostVersion), headers) if err != nil { return nil, err } var user models.User err = httpclient.ConvertResp(resp, statusCode, &user) if err != nil { return nil, err } a.Settings.UsersID = user.UsersID return &user, nil }
func (l *SLogs) Output(queryString, sessionToken, domain string, follow bool, hours, minutes, seconds, from int, startTimestamp, endTimestamp time.Time, env *models.Environment) (int, time.Time, error) { appLogsIdentifier := "source" appLogsValue := "app" if strings.HasPrefix(domain, "pod01") || strings.HasPrefix(domain, "csb01") { appLogsIdentifier = "syslog_program" appLogsValue = "supervisord" } urlString := fmt.Sprintf("https://%s/__es", domain) headers := map[string][]string{"Cookie": {"sessionToken=" + url.QueryEscape(sessionToken)}} logrus.Println(" @timestamp - message") for { queryBytes := generateQuery(queryString, appLogsIdentifier, appLogsValue, startTimestamp, from) resp, statusCode, err := httpclient.Get(queryBytes, fmt.Sprintf("%s/_search", urlString), headers) if err != nil { return from, startTimestamp, err } var logs models.Logs err = httpclient.ConvertResp(resp, statusCode, &logs) if err != nil { return from, startTimestamp, err } end := time.Time{} for _, lh := range *logs.Hits.Hits { logrus.Printf("%s - %s", lh.Fields["@timestamp"][0], lh.Fields["message"][0]) end, _ = time.Parse(time.RFC3339Nano, lh.Fields["@timestamp"][0]) } amount := len(*logs.Hits.Hits) from += len(*logs.Hits.Hits) // TODO this will infinite loop if it always retrieves `size` hits // and it fails to parse the end timestamp. very small window of opportunity. if amount < size || end.After(endTimestamp) { break } time.Sleep(config.JobPollTime * time.Second) } return from, startTimestamp, nil }
func (f *SFiles) Retrieve(fileName string, svcID string) (*models.ServiceFile, error) { files, err := f.List(svcID) if err != nil { return nil, err } for _, ff := range *files { if ff.Name == fileName { headers := httpclient.GetHeaders(f.Settings.SessionToken, f.Settings.Version, f.Settings.Pod, f.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/files/%d", f.Settings.PaasHost, f.Settings.PaasHostVersion, f.Settings.EnvironmentID, svcID, ff.ID), headers) if err != nil { return nil, err } var file models.ServiceFile err = httpclient.ConvertResp(resp, statusCode, &file) if err != nil { return nil, err } return &file, nil } } return nil, nil }
func (j *SJobs) PollForStatus(statuses []string, jobID, svcID string) (string, error) { var job models.Job failedAttempts := 0 poll: for { failed := false headers := httpclient.GetHeaders(j.Settings.SessionToken, j.Settings.Version, j.Settings.Pod, j.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments/%s/services/%s/jobs/%s", j.Settings.PaasHost, j.Settings.PaasHostVersion, j.Settings.EnvironmentID, svcID, jobID), headers) if err != nil { failed = true } err = httpclient.ConvertResp(resp, statusCode, &job) if err != nil { failed = true } if failed { failedAttempts++ } s := job.Status switch { case contains(s, statuses): break poll case contains(s, []string{"scheduled", "queued", "started", "running", "stopped", "waiting"}): if failedAttempts >= 3 { return "", fmt.Errorf("Error - ended in status '%s'.", job.Status) } // all because logrus treats print, println, and printf the same logrus.StandardLogger().Out.Write([]byte(".")) time.Sleep(config.JobPollTime * time.Second) default: return "", fmt.Errorf("Error - ended in status '%s'.", job.Status) } } if !contains(job.Status, statuses) { return "", fmt.Errorf("Error - ended in status '%s'.", job.Status) } return job.Status, nil }
func (e *SEnvironments) List() (*[]models.Environment, map[string]error) { allEnvs := []models.Environment{} errs := map[string]error{} for _, pod := range *e.Settings.Pods { headers := httpclient.GetHeaders(e.Settings.SessionToken, e.Settings.Version, pod.Name, e.Settings.UsersID) resp, statusCode, err := httpclient.Get(nil, fmt.Sprintf("%s%s/environments", e.Settings.PaasHost, e.Settings.PaasHostVersion), headers) if err != nil { errs[pod.Name] = err continue } var envs []models.Environment err = httpclient.ConvertResp(resp, statusCode, &envs) if err != nil { errs[pod.Name] = err continue } for i := 0; i < len(envs); i++ { envs[i].Pod = pod.Name } allEnvs = append(allEnvs, envs...) } return &allEnvs, errs }