This repository was archived by the owner on Dec 1, 2023. It is now read-only.
  
  
  - 
                Notifications
    
You must be signed in to change notification settings  - Fork 7
 
Create RubrikServiceAccount.sh #4
          
     Open
      
      
            BhardwajParag09
  wants to merge
  1
  commit into
  rubrikinc:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
BhardwajParag09:patch-1
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #!/bin/bash | ||
| 
     | 
||
| ######################################################################################################## | ||
| # Title: Bash-ServiceAccount.sh | ||
| # Summary: Authenticate BASH using Rubrik service account user. | ||
| # Author: Parag Bhardwaj | ||
| # | ||
| # REQUIREMENTS: | ||
| # jq is required to parse curl response. You can usually get the jq utility in the add on | ||
| # repository of most linux distros. | ||
| # | ||
| # USAGE: ./Bash-ServiceAccount.sh -c 192.X.X.X -serviceAccountId myServiceAccountID -secret SecretKeyOfTheServiceAccountUser | ||
| ######################################################################################################## | ||
| 
     | 
||
| #Modify the following parameters | ||
| c="X.X.X.X" | ||
| serviceAccountId="User:::5741XXXXXXad6" | ||
| secret="0reaJXXXXXXXX+yWApJF" | ||
| 
     | 
||
| # check jq is installed | ||
| if ! JQ_LOC="$(type -p jq)" || [ -z "$JQ_LOC" ]; then | ||
| printf '%s\n' "The jq utility is not installed." | ||
| printf '%s\n' "Install contructions can be found at https://stedolan.github.io/jq/download/" | ||
| exit 1 | ||
| fi | ||
| 
     | 
||
| #Create a session passing the Service account ID and Secret | ||
| session=$(curl -X POST "https://$c/api/v1/service_account/session" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"serviceAccountId\": \"$serviceAccountId\", \"secret\": \"$secret\"}" --insecure) | ||
| 
     | 
||
| #Get the token ID (will be used to pass the token in the authentication parameters) | ||
| AUTH_TOKEN=$(echo "$session" | jq -r .token) | ||
| 
     | 
||
| #Get the session ID (will be used to terminate the session in the end) | ||
| sessionId=$(echo "$session" | jq -r .sessionId) | ||
| 
     | 
||
| #OPTIONAL IF YOU WANT TO PRINT THE TOKEN AND SESSION ID | ||
| #printf '%s\n' "Token is: $AUTH_TOKEN" | ||
| #printf '%s\n' "Session ID is: $sessionId" | ||
| 
     | 
||
| #Testing to fetch the cluster details using the API key of the service account. | ||
| 
     | 
||
| test=$(curl -X GET "https://$c/api/v1/cluster/me" -H "accept: application/json" -H "Authorization: Bearer $AUTH_TOKEN" --insecure) | ||
| printf '%s\n' "$test" | ||
| 
     | 
||
| #Make sure to end the session because only 10 active sessions are allowed per service account. | ||
| end_session=$(curl -X DELETE "https://$c/api/v1/session/$sessionId" -H "accept: application/json" -H "Authorization: Bearer $AUTH_TOKEN" --insecure) | ||
| printf '%s\n' "session ended successfully" | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.