added the route that creates a secret from the s3 credentials
This commit is contained in:
parent
25d1c7ca39
commit
ebb330e3fa
@ -16,7 +16,7 @@ type MinioController struct {
|
||||
|
||||
// @Title CreateServiceAccounnt
|
||||
// @Description Add a new ServiceAccount to a Minio server using its ID and an execution ID and store the secret holding the login in the appropriate namespace
|
||||
// @Success 200
|
||||
// @Success 201
|
||||
// @Param executions path string true "The executionsID of the execution"
|
||||
// @Param minioId path string true "The ID of the Minio you want to reach"
|
||||
// @Param retrieve body map[string]string false "Should be empty or contain "'retrieve': true"
|
||||
@ -154,3 +154,64 @@ func findLiveStorage(storageId string, peerId string) *live.LiveStorage {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// @Title CreateCredentialsSecret
|
||||
// @Description Create a Kubernetes secret holding the access and secret keys to a given S3 server and bucket
|
||||
// @Success 201
|
||||
// @Param executions path string true "The executionsID of the execution"
|
||||
// @Param minioId path string true "The ID of the Minio youto which the credentials give access to"
|
||||
// @Param creds body map[string]string true "The credentials to store in the secret"
|
||||
// @router /secret/:minioId/:executions [post]
|
||||
func (m *MinioController) CreateCredentialHoldingSecret(){
|
||||
executionsId := m.Ctx.Input.Param(":executions")
|
||||
minioId := m.Ctx.Input.Param(":minioId")
|
||||
|
||||
|
||||
var creds map[string]string
|
||||
json.Unmarshal(m.Ctx.Input.CopyBody(10000), &creds)
|
||||
|
||||
access, aOk := creds["access"]
|
||||
secret, sOk := creds["secret"]
|
||||
|
||||
if !aOk || !sOk || len(access) == 0 || len(secret) == 0 {
|
||||
m.Ctx.Output.SetStatus(403)
|
||||
m.Data["json"] = map[string]interface{}{"error": "Missing credentials"}
|
||||
m.ServeJSON()
|
||||
}
|
||||
|
||||
// test if the namespace exists
|
||||
k, err := infrastructure.NewService()
|
||||
if err != nil {
|
||||
m.Ctx.Output.SetStatus(500)
|
||||
m.Data["json"] = map[string]string{"error": err.Error()}
|
||||
m.ServeJSON()
|
||||
return
|
||||
}
|
||||
|
||||
ns, err := k.GetNamespace(m.Ctx.Request.Context(), executionsId)
|
||||
if ns == nil {
|
||||
m.Ctx.Output.SetStatus(403)
|
||||
m.Data["json"] = map[string]string{"error":"Could not find the namespace corresponding to executionsID " + executionsId}
|
||||
m.ServeJSON()
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
m.Ctx.Output.SetStatus(500)
|
||||
m.Data["json"] = map[string]string{"error": "Error when trying to check if namespace " + executionsId + " exists : " + err.Error()}
|
||||
m.ServeJSON()
|
||||
return
|
||||
}
|
||||
|
||||
// store the credentials in the namespace
|
||||
err = k.CreateSecret(m.Ctx.Request.Context(), minioId, executionsId, creds["access"], creds["secret"])
|
||||
if err != nil {
|
||||
m.Ctx.Output.SetStatus(500)
|
||||
m.Data["json"] = map[string]string{"error": "Error when storing Minio serviceAccount credentials in namespace " + executionsId + " exists : " + err.Error()}
|
||||
m.ServeJSON()
|
||||
return
|
||||
}
|
||||
|
||||
m.Ctx.Output.SetStatus(201)
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user