Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wiki documentation for user data customization incorrect #668

Open
mathianasjs opened this issue Apr 1, 2015 · 3 comments
Open

Wiki documentation for user data customization incorrect #668

mathianasjs opened this issue Apr 1, 2015 · 3 comments

Comments

@mathianasjs
Copy link

The wiki at
https://github.com/Netflix/asgard/wiki/Customizing-User-Data

contains a non working example on how to extend the user data to provide custom environment variables.

This line creates a new instance of DefaultUserDataProvider which is outside the scope of Spring autowire control, so when the defaultProvider.buildUserDataForVariables method is invoked it causes a method inside with an autowired object method to be called result in a null pointer exception.
DefaultUserDataProvider defaultProvider = new DefaultUserDataProvider()

The proposed change to the example would be, this would then provide access to the defaultProvider with all autowired dependencies calls made inside the provider.

import com.netflix.asgard.userdata.DefaultUserDataProvider
import com.netflix.asgard.UserContext
import com.netflix.asgard.plugin.AdvancedUserDataProvider
import com.netflix.asgard.model.LaunchContext
import javax.xml.bind.DatatypeConverter
import com.amazonaws.services.ec2.model.Image
import org.springframework.beans.factory.annotation.Autowired

/**

  • Builds user data Initech style.
    */
    class InitechAdvancedUserDataProvider implements AdvancedUserDataProvider {
    @Autowired
    DefaultUserDataProvider defaultProvider

    String buildUserData(LaunchContext launchContext) {
    // Start with Asgard's default user data
    UserContext userContext = launchContext.userContext
    String appName = launchContext.application?.name ?: ''
    String asgName = launchContext.autoScalingGroup?.autoScalingGroupName ?: ''
    String lcName = launchContext.launchConfiguration?.launchConfigurationName ?: ''
    String encoded = defaultProvider.buildUserDataForVariables(userContext, appName, asgName, lcName)
    String defaultUserData = new String(DatatypeConverter.parseBase64Binary(encoded))

    // Add company specific stuff
    String initechMantra = "export IS_THIS_BEST_FOR_THE_COMPANY=true\n"
    Image image = launchContext.image
    String imgDesc = "export IMAGE_DESC=${image.description ?: ''}\n"
    String concatenated = defaultUserData + initechMantra + imgDesc
    DatatypeConverter.printBase64Binary(concatenated.bytes)
    

    }
    }

@mathianasjs
Copy link
Author

Does anyone have input on how the wiki documentation can be updated to address this issue?

@jvasallo
Copy link

+1 Please...spent a good 2 hours trying to implement this until I found this.

@Jared-Prime
Copy link

+1 the wiki is still incorrect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants