Skip to content

Commit

Permalink
Merge branch 'laverya/redact-spec-api' of github.com:replicatedhq/kot…
Browse files Browse the repository at this point in the history
…s into jelena-redactors
  • Loading branch information
jgruica committed May 22, 2020
2 parents 8deff9f + 5210ed8 commit f0fe30e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 39 deletions.
14 changes: 7 additions & 7 deletions kotsadm/pkg/handlers/redact.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func UpdateRedact(w http.ResponseWriter, r *http.Request) {

// we don't currently have roles, all valid tokens are valid sessions
if sess == nil || sess.ID == "" {
updateRedactResponse.Error = "failed to parse authorization header"
updateRedactResponse.Error = "no session in auth header"
JSON(w, 401, updateRedactResponse)
return
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func GetRedact(w http.ResponseWriter, r *http.Request) {

// we don't currently have roles, all valid tokens are valid sessions
if sess == nil || sess.ID == "" {
getRedactResponse.Error = "failed to parse authorization header"
getRedactResponse.Error = "no session in auth header"
JSON(w, 401, getRedactResponse)
return
}
Expand Down Expand Up @@ -211,7 +211,7 @@ func GetRedactMetadata(w http.ResponseWriter, r *http.Request) {

// we don't currently have roles, all valid tokens are valid sessions
if sess == nil || sess.ID == "" {
getMetadataResponse.Error = "failed to parse authorization header"
getMetadataResponse.Error = "no session in auth header"
JSON(w, 401, getMetadataResponse)
return
}
Expand Down Expand Up @@ -255,7 +255,7 @@ func GetRedactYaml(w http.ResponseWriter, r *http.Request) {

// we don't currently have roles, all valid tokens are valid sessions
if sess == nil || sess.ID == "" {
getRedactorResponse.Error = "failed to parse authorization header"
getRedactorResponse.Error = "no session in auth header"
JSON(w, 401, getRedactorResponse)
return
}
Expand Down Expand Up @@ -307,7 +307,7 @@ func ListRedactors(w http.ResponseWriter, r *http.Request) {

// we don't currently have roles, all valid tokens are valid sessions
if sess == nil || sess.ID == "" {
listRedactorsResponse.Error = "failed to parse authorization header"
listRedactorsResponse.Error = "no session in auth header"
JSON(w, 401, listRedactorsResponse)
return
}
Expand Down Expand Up @@ -344,7 +344,7 @@ func SetRedactMetadata(w http.ResponseWriter, r *http.Request) {

// we don't currently have roles, all valid tokens are valid sessions
if sess == nil || sess.ID == "" {
metadataResponse.Error = "failed to parse authorization header"
metadataResponse.Error = "no session in auth header"
JSON(w, 401, metadataResponse)
return
}
Expand Down Expand Up @@ -391,7 +391,7 @@ func SetRedactYaml(w http.ResponseWriter, r *http.Request) {

// we don't currently have roles, all valid tokens are valid sessions
if sess == nil || sess.ID == "" {
setYamlResponse.Error = "failed to parse authorization header"
setYamlResponse.Error = "no session in auth header"
JSON(w, 401, setYamlResponse)
return
}
Expand Down
4 changes: 2 additions & 2 deletions kotsadm/pkg/handlers/troubleshoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func GetSupportBundleFiles(w http.ResponseWriter, r *http.Request) {

// we don't currently have roles, all valid tokens are valid sessions
if sess == nil || sess.ID == "" {
getSupportBundleFilesResponse.Error = "failed to parse authorization header"
getSupportBundleFilesResponse.Error = "no session in auth header"
JSON(w, 401, getSupportBundleFilesResponse)
return
}
Expand Down Expand Up @@ -393,7 +393,7 @@ func GetSupportBundleRedactions(w http.ResponseWriter, r *http.Request) {

// we don't currently have roles, all valid tokens are valid sessions
if sess == nil || sess.ID == "" {
getSupportBundleRedactionsResponse.Error = "failed to parse authorization header"
getSupportBundleRedactionsResponse.Error = "no session in auth header"
JSON(w, 401, getSupportBundleRedactionsResponse)
return
}
Expand Down
53 changes: 23 additions & 30 deletions kotsadm/pkg/redact/redact.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,35 +142,9 @@ func SetRedactSpec(spec string) (string, error) {
return "failed to create kubernetes clientset", errors.Wrap(err, "failed to create kubernetes clientset")
}

configMap, err := clientset.CoreV1().ConfigMaps(os.Getenv("POD_NAMESPACE")).Get("kotsadm-redact", metav1.GetOptions{})
configMap, errMsg, err := getConfigmap()
if err != nil {
if !kuberneteserrors.IsNotFound(err) {
// not a not found error, so a real error
return "failed to get kotsadm-redact configMap", errors.Wrap(err, "failed to get kotsadm-redact configMap")
} else {
// not found, so create it fresh
newMap := v1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "kotsadm-redact",
Namespace: os.Getenv("POD_NAMESPACE"),
Labels: map[string]string{
"kots.io/kotsadm": "true",
},
},
Data: map[string]string{
"kotsadm-redact": spec,
},
}
_, err = clientset.CoreV1().ConfigMaps(os.Getenv("POD_NAMESPACE")).Create(&newMap)
if err != nil {
return "failed to create kotsadm-redact configMap", errors.Wrap(err, "failed to create kotsadm-redact configMap")
}
return "", nil
}
return errMsg, err
}

newMap, err := splitRedactors(spec, configMap.Data)
Expand Down Expand Up @@ -329,8 +303,27 @@ func getConfigmap() (*v1.ConfigMap, string, error) {
// not a not found error, so a real error
return nil, "failed to get kotsadm-redact configMap", errors.Wrap(err, "failed to get kotsadm-redact configMap")
} else {
// not found, so return empty string
return nil, "", nil
// not found, so create one and return it
newMap := v1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "kotsadm-redact",
Namespace: os.Getenv("POD_NAMESPACE"),
Labels: map[string]string{
"kots.io/kotsadm": "true",
},
},
Data: map[string]string{},
}
createdMap, err := clientset.CoreV1().ConfigMaps(os.Getenv("POD_NAMESPACE")).Create(&newMap)
if err != nil {
return nil, "failed to create kotsadm-redact configMap", errors.Wrap(err, "failed to create kotsadm-redact configMap")
}

return createdMap, "", nil
}
}
return configMap, "", nil
Expand Down

0 comments on commit f0fe30e

Please sign in to comment.