本文整理汇总了Golang中github.com/crunchydata/crunchy-postgresql-manager/types.SimpleStatus类的典型用法代码示例。如果您正苦于以下问题:Golang SimpleStatus类的具体用法?Golang SimpleStatus怎么用?Golang SimpleStatus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DeleteRole
// DeleteRole delete a CPM role
func DeleteRole(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-user")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
if r.PathParam("ID") == "" {
logit.Error.Println("DeleteRole: error ID required")
rest.Error(w, "ID required", http.StatusBadRequest)
return
}
err = secimpl.DeleteRole(dbConn, r.PathParam("ID"))
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteJson(&status)
}
示例2: RulesDelete
// RulesDelete deletes a given rule
func RulesDelete(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
ID := r.PathParam("ID")
if ID == "" {
rest.Error(w, "ID required", http.StatusBadRequest)
return
}
err = DeleteRule(dbConn, ID)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteHeader(http.StatusOK)
w.WriteJson(&status)
}
示例3: StartCluster
// StartCluster starts all nodes in a cluster
func StartCluster(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-cluster")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
ID := r.PathParam("ID")
if ID == "" {
logit.Error.Println("StartCluster: error cluster ID required")
rest.Error(w, "cluster ID required", http.StatusBadRequest)
return
}
cluster, err := admindb.GetCluster(dbConn, ID)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
}
//start docker containers
containers, err := admindb.GetAllContainersForCluster(dbConn, cluster.ID)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
}
i := 0
i = 0
var response swarmapi.DockerStartResponse
for i = range containers {
req := &swarmapi.DockerStartRequest{}
req.ContainerName = containers[i].Name
logit.Info.Println("will attempt to start container " + req.ContainerName)
response, err = swarmapi.DockerStart(req)
if err != nil {
logit.Error.Println("StartCluster: error when trying to start container" + err.Error())
}
logit.Info.Println("StartCluster: started " + response.Output)
i++
}
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteHeader(http.StatusOK)
w.WriteJson(&status)
}
示例4: Logout
// Logout perform a logout based on a given token
func Logout(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
token := r.PathParam("Token")
if token == "" {
logit.Error.Println("Logout: Token not supplied")
rest.Error(w, "Token not supplied", http.StatusBadRequest)
}
err = secimpl.Logout(dbConn, token)
if err != nil {
logit.Error.Println("Logout: error secimpl call" + err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteJson(&status)
}
示例5: Status
func Status(w rest.ResponseWriter, r *rest.Request) {
w.WriteHeader(http.StatusOK)
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteJson(&status)
}
示例6: ChangePassword
// ChangePassword change a user password
func ChangePassword(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
//logit.Info.Println("ChangePassword: in ChangePassword")
changePass := ChgPassword{}
err = r.DecodeJsonPayload(&changePass)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = secimpl.Authorize(dbConn, changePass.Token, "perm-read")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
var sameUser bool
sameUser, err = secimpl.CompareUserToToken(dbConn, changePass.Username, changePass.Token)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
//enforce perm-user if the username is not the same as the token's
//username (e.g. bob tries to change larry's password)
if !sameUser {
err = secimpl.Authorize(dbConn, changePass.Token, "perm-user")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
}
err = secimpl.ChangePassword(dbConn, changePass.Username, changePass.Password)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteJson(&status)
}
示例7: AdminStartNode
// AdminStartNode starts a container
func AdminStartNode(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
ID := r.PathParam("ID")
if ID == "" {
logit.Error.Println("AdminStartNode: error ID required")
rest.Error(w, "ID required", http.StatusBadRequest)
return
}
node, err := admindb.GetContainer(dbConn, ID)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
/**
server := types.Server{}
server, err = admindb.GetServer(dbConn, node.ServerID)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
*/
var response swarmapi.DockerStartResponse
request := &swarmapi.DockerStartRequest{}
request.ContainerName = node.Name
response, err = swarmapi.DockerStart(request)
if err != nil {
logit.Error.Println(err.Error())
logit.Error.Println(response.Output)
}
//logit.Info.Println(response.Output)
w.WriteHeader(http.StatusOK)
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteJson(&status)
}
示例8: AdminStopServerContainers
// AdminStopServerContainers stops all containers on a given server
func AdminStopServerContainers(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
//serverID
serverid := r.PathParam("ID")
if serverid == "" {
logit.Error.Println("AdminStopoServerContainers: error ID required")
rest.Error(w, "ID required", http.StatusBadRequest)
return
}
cleanIP := strings.Replace(serverid, "_", ".", -1)
containers, err := swarmapi.DockerPs(cleanIP)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
//for each, get server, stop container
for _, each := range containers.Output {
if strings.HasPrefix(each.Status, "Up") {
//stop container
request := &swarmapi.DockerStopRequest{}
request.ContainerName = each.Name
logit.Info.Println("stopping " + request.ContainerName)
_, err = swarmapi.DockerStop(request)
if err != nil {
logit.Error.Println("AdminStopServerContainers: error when trying to start container " + err.Error())
}
}
}
w.WriteHeader(http.StatusOK)
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteJson(&status)
}
示例9: AdminStoppg
// AdminStoppg stops a postgres database on a given container
func AdminStoppg(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-cluster")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
//logit.Info.Println("AdminStoppg:called")
ID := r.PathParam("ID")
if ID == "" {
logit.Error.Println("AdminStoppg:ID not found error")
rest.Error(w, "node ID required", http.StatusBadRequest)
return
}
var dbNode types.Container
dbNode, err = admindb.GetContainer(dbConn, ID)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
//logit.Info.Println("AdminStoppg: in stop with dbnode")
if dbNode.Role == "pgpool" {
var stoppoolResp cpmcontainerapi.StopPgpoolResponse
stoppoolResp, err = cpmcontainerapi.StopPgpoolClient(dbNode.Name)
logit.Info.Println("AdminStoppg:" + stoppoolResp.Output)
} else {
var stoppgResp cpmcontainerapi.StopPGResponse
stoppgResp, err = cpmcontainerapi.StopPGClient(dbNode.Name)
logit.Info.Println("AdminStoppg:" + stoppgResp.Output)
}
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
w.WriteHeader(http.StatusOK)
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteJson(&status)
}
示例10: ProxyUpdate
// ProxyUpdate updates a proxy node definition
func ProxyUpdate(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
req := ProxyRequest{}
err = r.DecodeJsonPayload(&req)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
//logit.Info.Println("ID=" + req.ID)
//logit.Info.Println("Port" + req.Port)
//logit.Info.Println("Host" + req.Host)
//logit.Info.Println("Database" + req.Database)
//logit.Info.Println("Usename" + req.Usename)
//logit.Info.Println("Passwd" + req.Passwd)
//encrypt the password...passwords at rest are encrypted
var encrypted string
encrypted, err = sec.EncryptPassword(req.Passwd)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
queryStr := fmt.Sprintf("update proxy set ( port, host, usename, passwd, databasename, updatedt) = ( '%s', '%s', '%s', '%s', '%s', now()) where id = %s returning id",
req.Port, req.Host, req.Usename, encrypted, req.Database, req.ID)
logit.Info.Println("UpdateProxy:" + queryStr)
var proxyid int
err = dbConn.QueryRow(queryStr).Scan(&proxyid)
switch {
case err != nil:
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
default:
logit.Info.Println("UpdateProxy: update " + strconv.Itoa(proxyid))
}
w.WriteHeader(http.StatusOK)
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteJson(&status)
}
示例11: RulesUpdate
// RulesUpdate updates a given rule
func RulesUpdate(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
//logit.Info.Println("RulesUpdate: in RulesUpdate")
rule := Rule{}
err = r.DecodeJsonPayload(&rule)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = secimpl.Authorize(dbConn, rule.Token, "perm-container")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
if rule.ID == "" {
logit.Error.Println("RulesUpdate: error in ID")
rest.Error(w, "rule ID required", http.StatusBadRequest)
return
}
if rule.Name == "" {
logit.Error.Println("RulesUpdate: error in Name")
rest.Error(w, "rule name required", http.StatusBadRequest)
return
}
err = UpdateRule(dbConn, rule)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteHeader(http.StatusOK)
w.WriteJson(&status)
}
示例12: DeleteSchedule
// DeleteSchedule deletes an existing task schedule
func DeleteSchedule(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-backup")
if err != nil {
logit.Error.Println("validate token error " + err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
ID := r.PathParam("ID")
if ID == "" {
rest.Error(w, "schedule ID required", 400)
return
}
err = task.DeleteSchedule(dbConn, ID)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
//notify task server to reload schedules
var output task.ReloadResponse
output, err = task.ReloadClient()
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
logit.Info.Println("reload output=" + output.Output)
w.WriteHeader(http.StatusOK)
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteJson(&status)
}
示例13: UpdateUser
// UpdateUser update a CPM user security settings
func UpdateUser(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
//logit.Info.Println("UpdateUser: in UpdateUser")
user := sec.User{}
err = r.DecodeJsonPayload(&user)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
//logit.Info.Println("UpdateUser: Name=" + user.Name)
//logit.Info.Println("UpdateUser: token=" + user.Token)
err = secimpl.Authorize(dbConn, user.Token, "perm-user")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
err = secimpl.UpdateUser(dbConn, user)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteJson(&status)
}
示例14: SaveSetting
// SaveSetting update an existing setting value
func SaveSetting(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
//logit.Info.Println("SaveSetting:")
setting := types.Setting{}
err = r.DecodeJsonPayload(&setting)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = secimpl.Authorize(dbConn, setting.Token, "perm-setting")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
dbSetting := types.Setting{}
dbSetting.Name = setting.Name
dbSetting.Value = setting.Value
err2 := admindb.UpdateSetting(dbConn, dbSetting)
if err2 != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
w.WriteHeader(http.StatusOK)
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteJson(&status)
}
示例15: AddRole
// AddRole create a new CPM role
func AddRole(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
//logit.Info.Println("AddRole: in AddRole")
role := sec.Role{}
err = r.DecodeJsonPayload(&role)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = secimpl.Authorize(dbConn, role.Token, "perm-user")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
err = secimpl.AddRole(dbConn, role)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteJson(&status)
}