File: aws_config.c

package info (click to toggle)
netcdf-parallel 1%3A4.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 116,192 kB
  • sloc: ansic: 279,265; sh: 14,143; cpp: 5,971; yacc: 2,612; makefile: 2,075; lex: 1,218; javascript: 280; xml: 173; awk: 2
file content (89 lines) | stat: -rw-r--r-- 2,577 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*********************************************************************
 *   Copyright 2018, UCAR/Unidata
 *   See netcdf/COPYRIGHT file for copying and redistribution conditions.
 *********************************************************************/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "netcdf.h"
#include "ncrc.h"
#include "ncpathmgr.h"
#include "ncs3sdk.h"
#include "ncuri.h"
#include "nc4internal.h"

NCS3INFO s3info;
void* s3client = NULL;

/* Forward */
static void cleanup(void);

#define STR(p) p?p:"NULL"
#define CHECK(code) do {stat = check(code,__func__,__LINE__); if(stat) {goto done;}} while(0)

static int
check(int code, const char* fcn, int line)
{
    if(code == NC_NOERR) return code;
    fprintf(stderr,"***FAIL: (%d) %s @ %s:%d\n",code,nc_strerror(code),fcn,line);
    abort();
}

static void
cleanup(void)
{
    if(s3client)
        NC_s3sdkclose(s3client, &s3info, 0/*deleteit*/, NULL);
    s3client = NULL;
    NC_s3clear(&s3info);
}

int
main(int argc, char** argv)
{
    int c = 0,stat = NC_NOERR;

    /* Load RC and .aws/config */
    CHECK(nc_initialize()); /* Will invoke NC_s3sdkinitialize()); */
    NCglobalstate* gs = NC_getglobalstate();
    //Not checking, aborts if ~/.aws/config doesn't exist
    CHECK(NC_aws_load_credentials(gs));
    
    // Lets ensure the active profile is loaded
    // from the configurtion files instead of an URL
    const char* activeprofile = NULL;
    CHECK(NC_getactives3profile(NULL, &activeprofile));

    fprintf(stderr, "Active profile:%s\n", STR(activeprofile));
    
    // ARGV contains should contain "key[=value]" to verify
    // if key was parsed when loading the aws config and if it's
    // value is updated in case it's redefined on the .aws/credentials
    for(int i = 1; i < argc; i++) {
        const char *argkey = strtok(argv[i],"=");
        const char *argvalue = strtok(NULL,"=");
        const char* value = NULL;

        NC_s3profilelookup(activeprofile,argkey,&value);
        fprintf(stderr, "%s\t%s -> %s\n",value?"":"*** FAIL:", argv[i],value?value:"NOT DEFINED!");
        if ( value == NULL 
            || (argvalue != NULL 
                && strncmp(value, argvalue, strlen(value)))
        ){
                c++;
                stat |= NC_ERCFILE;
        }
    }

done:
    cleanup();
    if(stat)
        printf("*** FAIL: a total of %d keys were not found on the profile %s\n", c, STR(activeprofile));
    else
        printf("***PASS\n");
    (void)NC_s3sdkfinalize();
    (void)nc_finalize();
    exit(stat?:0);
}