@@ -147,27 +147,35 @@ func makeCredentials(authorization string) (ycsdk.Credentials, error) {
147147 const (
148148 instanceSaAuth = "instance-service-account"
149149 tokenAuth = "iam-token"
150+ tokenFileAuth = "iam-token-file:"
150151 iamKeyAuthPrefix = "iam-key-file:"
151152 )
152- switch auth := strings .TrimSpace (authorization ); auth {
153- case instanceSaAuth :
153+ auth := strings .TrimSpace (authorization )
154+ switch {
155+ case auth == instanceSaAuth :
154156 return ycsdk .InstanceServiceAccount (), nil
155- case tokenAuth :
157+ case auth == tokenAuth :
156158 token , ok := os .LookupEnv ("YC_TOKEN" )
157159 if ! ok {
158160 return nil , errors .New (`environment variable "YC_TOKEN" not set, required for authorization=iam-token` )
159161 }
160162 return ycsdk .NewIAMTokenCredentials (token ), nil
161- default :
162- if ! strings .HasPrefix (auth , iamKeyAuthPrefix ) {
163- return nil , fmt .Errorf ("unsupported authorization parameter %s" , auth )
163+ case strings .HasPrefix (auth , tokenFileAuth ):
164+ fileName := strings .TrimSpace (auth [len (tokenFileAuth ):])
165+ token , err := os .ReadFile (fileName )
166+ if err != nil {
167+ return nil , fmt .Errorf ("failed to read service account token file %s" , fileName )
164168 }
169+ return ycsdk .NewIAMTokenCredentials (string (token )), nil
170+ case strings .HasPrefix (auth , iamKeyAuthPrefix ):
165171 fileName := strings .TrimSpace (auth [len (iamKeyAuthPrefix ):])
166172 key , err := iamkey .ReadFromJSONFile (fileName )
167173 if err != nil {
168174 return nil , fmt .Errorf ("failed to read service account key file %s" , fileName )
169175 }
170176 return ycsdk .ServiceAccountKey (key )
177+ default :
178+ return nil , fmt .Errorf ("unsupported authorization parameter %s" , auth )
171179 }
172180}
173181
0 commit comments