Skip to content

Commit 7d520a5

Browse files
Fix 404 bug when trying to delete keys (#72)
* Update Dockerfile to use golang:bookworm and improve error handling in account existence check * Refactor HTTP status code checks to use http.StatusOK and http.StatusNotFound for clarity
1 parent ec40dc6 commit 7d520a5

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

Dockerfile.Debug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:buster
1+
FROM golang:bookworm
22
RUN mkdir /app
33
COPY ./pkg/ /app/pkg
44
COPY . /app

pkg/actions/remove-machine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func RemoveMachine(c *cli.Context) error {
3737
if err != nil {
3838
return err
3939
}
40-
_, exists := lo.Find(machines, func(x dto.MachineDto) bool {
40+
machine, exists := lo.Find(machines, func(x dto.MachineDto) bool {
4141
return x.Name == answer
4242
})
4343
if !exists {
@@ -52,6 +52,6 @@ func RemoveMachine(c *cli.Context) error {
5252
if answer != "y" {
5353
return nil
5454
}
55-
err = retrieval.DeleteMachine(profile, answer)
55+
err = retrieval.DeleteMachine(profile, machine.Name)
5656
return err
5757
}

pkg/actions/setup.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,12 @@ func checkIfAccountExists(username string, serverUrl *url.URL) (bool, error) {
134134
if err != nil {
135135
return false, err
136136
}
137-
if res.StatusCode == 404 {
137+
if res.StatusCode == http.StatusNotFound {
138138
return false, nil
139139
}
140+
if res.StatusCode != http.StatusOK {
141+
return false, errors.New("failed to check if account exists. status code: " + strconv.Itoa(res.StatusCode))
142+
}
140143
return true, nil
141144
}
142145

@@ -226,7 +229,7 @@ func newAccountSetup(serverUrl *url.URL) error {
226229
if err != nil {
227230
return err
228231
}
229-
if res.StatusCode != 200 {
232+
if res.StatusCode != http.StatusOK {
230233
return errors.New("failed to create user. status code: " + strconv.Itoa(res.StatusCode))
231234
}
232235
return nil

pkg/actions/upload.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func Upload(c *cli.Context) error {
4646
if err != nil {
4747
return err
4848
}
49-
if res.StatusCode != 200 {
49+
if res.StatusCode != http.StatusOK {
5050
return errors.New("failed to get data. status code: " + strconv.Itoa(res.StatusCode))
5151
}
5252
masterKey, err := utils.RetrieveMasterKey()
@@ -125,7 +125,7 @@ func Upload(c *cli.Context) error {
125125
if err != nil {
126126
return err
127127
}
128-
if res2.StatusCode != 200 {
128+
if res2.StatusCode != http.StatusOK {
129129
return errors.New("failed to upload data. status code: " + strconv.Itoa(res2.StatusCode))
130130
}
131131
fmt.Println("Successfully uploaded keys.")

pkg/retrieval/data.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func GetUserData(profile *models.Profile) (dto.DataDto, error) {
2929
if err != nil {
3030
return data, err
3131
}
32-
if res.StatusCode != 200 {
32+
if res.StatusCode != http.StatusOK {
3333
return data, errors.New("failed to get data. status code: " + strconv.Itoa(res.StatusCode))
3434
}
3535
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
@@ -65,7 +65,7 @@ func DeleteKey(profile *models.Profile, key dto.KeyDto) error {
6565
if err != nil {
6666
return err
6767
}
68-
if res.StatusCode != 200 {
68+
if res.StatusCode != http.StatusOK {
6969
return errors.New("failed to delete data. status code: " + strconv.Itoa(res.StatusCode))
7070
}
7171
return nil

0 commit comments

Comments
 (0)