1 /***********************************************************************************************************************************
2 Repository Create Command
3 ***********************************************************************************************************************************/
4 #include "build.auto.h"
5 
6 #include "common/debug.h"
7 #include "common/log.h"
8 #include "common/memContext.h"
9 #include "common/type/json.h"
10 #include "config/config.h"
11 #include "storage/helper.h"
12 #include "storage/azure/storage.intern.h"
13 #include "storage/gcs/storage.intern.h"
14 #include "storage/s3/storage.intern.h"
15 
16 /**********************************************************************************************************************************/
17 void
cmdRepoCreate(void)18 cmdRepoCreate(void)
19 {
20     FUNCTION_LOG_VOID(logLevelDebug);
21 
22     MEM_CONTEXT_TEMP_BEGIN()
23     {
24         switch (storageType(storageRepo()))
25         {
26             case STORAGE_AZURE_TYPE:
27             storageAzureRequestP(
28                 (StorageAzure *)storageDriver(storageRepoWrite()), HTTP_VERB_PUT_STR,
29                 .query = httpQueryAdd(httpQueryNewP(), AZURE_QUERY_RESTYPE_STR, AZURE_QUERY_VALUE_CONTAINER_STR));
30                 break;
31 
32             case STORAGE_GCS_TYPE:
33         {
34                 const KeyValue *const kvContent = kvPut(kvNew(), GCS_JSON_NAME_VAR, VARSTR(cfgOptionStr(cfgOptRepoGcsBucket)));
35 
36             storageGcsRequestP(
37                 (StorageGcs *)storageDriver(storageRepoWrite()), HTTP_VERB_POST_STR, .noBucket = true,
38                 .content = BUFSTR(jsonFromKv(kvContent)));
39 
40                 break;
41             }
42 
43             case STORAGE_S3_TYPE:
44                 storageS3RequestP((StorageS3 *)storageDriver(storageRepoWrite()), HTTP_VERB_PUT_STR, FSLASH_STR);
45                 break;
46 
47             // Other storage types do not require the repo to be created
48             default:
49                 break;
50         }
51     }
52     MEM_CONTEXT_TEMP_END();
53 
54     FUNCTION_LOG_RETURN_VOID();
55 }
56