utils.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include "curl.h"
  5. #define MAX_BUF_SZ 2048
  6. enum environment_variable_key {
  7. OS_AUTH_TYPE,
  8. OS_AUTH_URL,
  9. OS_IDENTITY_API_VERSION,
  10. OS_INTERFACE,
  11. OS_PASSWORD,
  12. OS_PROJECT_DOMAIN_NAME,
  13. OS_PROJECT_ID,
  14. OS_PROJECT_NAME,
  15. OS_REGION_NAME,
  16. OS_USER_DOMAIN_NAME,
  17. OS_USERNAME,
  18. n_vars
  19. };
  20. struct environment_variable {
  21. char *name;
  22. char *val;
  23. bool req;
  24. };
  25. extern struct environment_variable env[n_vars];
  26. struct command {
  27. char *name;
  28. int (*fn)(int argc, char **argv);
  29. };
  30. // https://stackoverflow.com/a/40706869/10210798
  31. #define CMD_DEF(f) { #f, f }
  32. // Keep track of where we are in the subcommand stack, eg for adding to help/usage messages.
  33. extern int subcommand_depth;
  34. extern char *subcommand_breadcrumbs;
  35. void usage();
  36. #define WHEREAMI() { printf("In %s:%d, function '%s'\n", __FILE__, __LINE__, __func__); }
  37. void get_environment_variables();
  38. void print_credentials();
  39. void api_url_build(char *url, const char *endpoint, const char *path);
  40. void get_interface_endpoint(char *url, const char *endpoint);
  41. void print_response(const struct string *s, const char *item);
  42. void common_main(int argc, char **argv, struct command *subcommands);