File

src/app/shared/api/rgw-bucket.service.ts

Index

Properties
Methods

Constructor

constructor(http: HttpClient)
Parameters :
Name Type Optional
http HttpClient No

Methods

create
create(bucket: string, uid: string)
Parameters :
Name Type Optional
bucket string No
uid string No
Returns : any
delete
delete(bucket: string, purgeObjects)
Parameters :
Name Type Optional Default value
bucket string No
purgeObjects No true
Returns : any
enumerate
enumerate()

Get the list of bucket names.

Returns : any
exists
exists(bucket: string)

Check if the specified bucket exists.

Parameters :
Name Type Optional
bucket string No
Returns : any
get
get(bucket: string)
Parameters :
Name Type Optional
bucket string No
Returns : any
list
list()

Get the list of buckets.

Returns : any
update
update(bucket: string, bucketId: string, uid: string)
Parameters :
Name Type Optional
bucket string No
bucketId string No
uid string No
Returns : any

Properties

Private url
Type : string
Default value : 'api/rgw/bucket'
import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';

import * as _ from 'lodash';
import { forkJoin as observableForkJoin, of as observableOf } from 'rxjs';
import { mergeMap } from 'rxjs/operators';

import { cdEncode } from '../decorators/cd-encode';
import { ApiModule } from './api.module';

@cdEncode
@Injectable({
  providedIn: ApiModule
})
export class RgwBucketService {
  private url = 'api/rgw/bucket';

  constructor(private http: HttpClient) {}

  /**
   * Get the list of buckets.
   * @return {Observable<Object[]>}
   */
  list() {
    return this.enumerate().pipe(
      mergeMap((buckets: string[]) => {
        if (buckets.length > 0) {
          return observableForkJoin(
            buckets.map((bucket: string) => {
              return this.get(bucket);
            })
          );
        }
        return observableOf([]);
      })
    );
  }

  /**
   * Get the list of bucket names.
   * @return {Observable<string[]>}
   */
  enumerate() {
    return this.http.get(this.url);
  }

  get(bucket: string) {
    return this.http.get(`${this.url}/${bucket}`);
  }

  create(bucket: string, uid: string) {
    let params = new HttpParams();
    params = params.append('bucket', bucket);
    params = params.append('uid', uid);
    return this.http.post(this.url, null, { params: params });
  }

  update(bucket: string, bucketId: string, uid: string) {
    let params = new HttpParams();
    params = params.append('bucket_id', bucketId);
    params = params.append('uid', uid);
    return this.http.put(`${this.url}/${bucket}`, null, { params: params });
  }

  delete(bucket: string, purgeObjects = true) {
    let params = new HttpParams();
    params = params.append('purge_objects', purgeObjects ? 'true' : 'false');
    return this.http.delete(`${this.url}/${bucket}`, { params: params });
  }

  /**
   * Check if the specified bucket exists.
   * @param {string} uid The bucket name to check.
   * @return {Observable<boolean>}
   */
  exists(bucket: string) {
    return this.enumerate().pipe(
      mergeMap((resp: string[]) => {
        const index = _.indexOf(resp, bucket);
        return observableOf(-1 !== index);
      })
    );
  }
}

result-matching ""

    No results matching ""