STATUS initKinesisVideoStructs()

in gst/gst-kvs-plugin/src/GstPlugin.c [113:177]


STATUS initKinesisVideoStructs(PGstKvsPlugin pGstPlugin)
{
    STATUS retStatus = STATUS_SUCCESS;
    PCHAR pAccessKey = NULL, pSecretKey = NULL, pSessionToken = NULL;
    IotInfo iotInfo;

    CHK(pGstPlugin != NULL, STATUS_NULL_ARG);

    CHK_STATUS(initKvsWebRtc());

    // Zero out the kvs sub-structures for proper cleanup later
    MEMSET(&pGstPlugin->kvsContext, 0x00, SIZEOF(KvsContext));

    // Load the CA cert path
    lookForSslCert(pGstPlugin);

    pSessionToken = GETENV(SESSION_TOKEN_ENV_VAR);
    if (0 == STRCMP(pGstPlugin->gstParams.accessKey, DEFAULT_ACCESS_KEY)) { // if no static credential is available in plugin property.
        if (NULL == (pAccessKey = GETENV(ACCESS_KEY_ENV_VAR)) ||
            NULL == (pSecretKey = GETENV(SECRET_KEY_ENV_VAR))) { // if no static credential is available in env var.
        }
    } else {
        pAccessKey = pGstPlugin->gstParams.accessKey;
        pSecretKey = pGstPlugin->gstParams.secretKey;
    }

    if (NULL == (pGstPlugin->pRegion = GETENV(DEFAULT_REGION_ENV_VAR))) {
        pGstPlugin->pRegion = pGstPlugin->gstParams.awsRegion;
    }

    if (NULL == pGstPlugin->pRegion) {
        // Use the default
        pGstPlugin->pRegion = DEFAULT_AWS_REGION;
    }

    if (0 != STRCMP(pGstPlugin->gstParams.fileLogPath, DEFAULT_FILE_LOG_PATH)) {
        CHK_STATUS(
            createFileLogger(FILE_LOGGING_BUFFER_SIZE, MAX_NUMBER_OF_LOG_FILES, (PCHAR) FILE_LOGGER_LOG_FILE_DIRECTORY_PATH, TRUE, TRUE, NULL));
    }

    // Create the Credential Provider which will be used by both the producer and the signaling client
    // Check if we have access key then use static credential provider.
    // If we have IoT struct then use IoT credential provider.
    // If we have File then we use file credential provider.
    // We also need to set the appropriate free function pointer.
    if (pAccessKey != NULL) {
        CHK_STATUS(
            createStaticCredentialProvider(pAccessKey, 0, pSecretKey, 0, pSessionToken, 0, MAX_UINT64, &pGstPlugin->kvsContext.pCredentialProvider));
        pGstPlugin->kvsContext.freeCredentialProviderFn = freeStaticCredentialProvider;
    } else if (pGstPlugin->gstParams.iotCertificate != NULL) {
        CHK_STATUS(gstStructToIotInfo(pGstPlugin->gstParams.iotCertificate, &iotInfo));
        CHK_STATUS(createCurlIotCredentialProvider(iotInfo.endPoint, iotInfo.certPath, iotInfo.privateKeyPath, iotInfo.caCertPath, iotInfo.roleAlias,
                                                   pGstPlugin->gstParams.streamName, &pGstPlugin->kvsContext.pCredentialProvider));
        pGstPlugin->kvsContext.freeCredentialProviderFn = freeIotCredentialProvider;
    } else if (pGstPlugin->gstParams.credentialFilePath != NULL) {
        CHK_STATUS(createFileCredentialProvider(pGstPlugin->gstParams.credentialFilePath, &pGstPlugin->kvsContext.pCredentialProvider));
        pGstPlugin->kvsContext.freeCredentialProviderFn = freeFileCredentialProvider;
    }

CleanUp:

    CHK_LOG_ERR(retStatus);

    return retStatus;
}