Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
EVEREST-115: Azure storage support (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Kralik authored Oct 13, 2023
1 parent 8ca0535 commit 6a40a11
Show file tree
Hide file tree
Showing 8 changed files with 490 additions and 302 deletions.
96 changes: 87 additions & 9 deletions api-tests/tests/backup-storages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
// limitations under the License.
import { expect, test } from '@fixtures'

let req

test('add/list/get/delete backup storage success', async ({ request }) => {
req = request
test('add/list/get/delete s3 backup storage success', async ({ request }) => {
const payload = {
type: 's3',
name: 'backup-storage-1',
Expand Down Expand Up @@ -92,9 +89,78 @@ test('add/list/get/delete backup storage success', async ({ request }) => {
expect(deleted.ok()).toBeTruthy()
})

test('create backup storage failures', async ({ request }) => {
req = request
test('add/list/get/delete azure backup storage success', async ({ request }) => {
const payload = {
type: 'azure',
name: 'backup-storage-azure',
description: 'Dev storage',
bucketName: 'percona-test-backup-storage',
accessKey: 'sdfs',
secretKey: 'sdfsdfsd',
}

const response = await request.post('/v1/backup-storages', {
data: payload,
})

// create
expect(response.ok()).toBeTruthy()
const created = await response.json()

const name = created.name

expect(created.name).toBe(payload.name)
expect(created.bucketName).toBe(payload.bucketName)
expect(created.type).toBe(payload.type)
expect(created.description).toBe(payload.description)

// list
const listResponse = await request.get('/v1/backup-storages')

expect(listResponse.ok()).toBeTruthy()
const list = await listResponse.json()

expect(list.length).toBeGreaterThan(0)

// get
const one = await request.get(`/v1/backup-storages/${name}`)

expect(one.ok()).toBeTruthy()
expect((await one.json()).name).toBe(payload.name)

// update
const updatePayload = {
description: 'some description',
bucketName: 'percona-test-backup-storage1',
accessKey: 'otherAccessKey',
secretKey: 'otherSecret',
}
const updated = await request.patch(`/v1/backup-storages/${name}`, {
data: updatePayload,
})

expect(updated.ok()).toBeTruthy()
const result = await updated.json()

expect(result.bucketName).toBe(updatePayload.bucketName)
expect(result.region).toBe(created.region)
expect(result.type).toBe(created.type)
expect(result.description).toBe(updatePayload.description)

// backup storage already exists
const createAgain = await request.post('/v1/backup-storages', {
data: payload,
})

expect(createAgain.status()).toBe(409)

// delete
const deleted = await request.delete(`/v1/backup-storages/${name}`)

expect(deleted.ok()).toBeTruthy()
})

test('create backup storage failures', async ({ request }) => {
const testCases = [
{
payload: {},
Expand Down Expand Up @@ -135,14 +201,24 @@ test('create backup storage failures', async ({ request }) => {
},
{
payload: {
type: 'azure',
type: 's3',
name: 'missing-region',
bucketName: 'invalid',
accessKey: 'ssdssd',
secretKey: 'ssdssdssdssd',
},
errorText: 'Region is required',
},
{
payload: {
type: 'gcs',
name: 'invalid',
region: 'us-east-2',
bucketName: 'invalid',
accessKey: 'ssdssd',
secretKey: 'ssdssdssdssd',
},
errorText: `Creating storage is not implemented for 'azure'`,
errorText: `"/type": value is not one of the allowed values`,
},
]

Expand All @@ -157,7 +233,6 @@ test('create backup storage failures', async ({ request }) => {
})

test('update backup storage failures', async ({ request }) => {
req = request
const createPayload = {
type: 's3',
name: 'backup-storage-2',
Expand Down Expand Up @@ -198,6 +273,9 @@ test('update backup storage failures', async ({ request }) => {
expect((await response.json()).message).toMatch(testCase.errorText)
expect(response.status()).toBe(400)
}

const deleted = await request.delete(`/v1/backup-storages/${name}`)
expect(deleted.ok()).toBeTruthy()
})

test('update: backup storage not found', async ({ request }) => {
Expand Down
9 changes: 7 additions & 2 deletions api/backup_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,12 @@ func (e *EverestServer) GetBackupStorage(ctx echo.Context, backupStorageID strin

// UpdateBackupStorage updates of the specified backup storage.
func (e *EverestServer) UpdateBackupStorage(ctx echo.Context, backupStorageName string) error {
params, err := validateUpdateBackupStorageRequest(ctx)
bs, err := e.storage.GetBackupStorage(ctx.Request().Context(), nil, backupStorageName)
if err != nil {
return ctx.JSON(http.StatusNotFound, Error{Message: pointer.ToString("Could not find backup storage")})
}

params, err := validateUpdateBackupStorageRequest(ctx, bs)
if err != nil {
return ctx.JSON(http.StatusBadRequest, Error{Message: pointer.ToString(err.Error())})
}
Expand Down Expand Up @@ -422,7 +427,7 @@ func (e *EverestServer) checkStorageAccessByUpdate(ctx context.Context, storageN
storage: *s,
}

err = validateStorageAccessByUpdate(oldData, params, e.l)
err = validateStorageAccessByUpdate(ctx, oldData, params, e.l)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 6a40a11

Please sign in to comment.